* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
static ssize_t switch_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
static ssize_t switch_proc_read(struct file *file, char *buf, size_t count, loff_t *ppos)
{
if (dent->data != NULL) {
switch_proc_handler *handler = (switch_proc_handler *) dent->data;
if (handler->handler.read != NULL)
if (dent->data != NULL) {
switch_proc_handler *handler = (switch_proc_handler *) dent->data;
if (handler->handler.read != NULL)
static ssize_t switch_proc_write(struct file *file, const char *buf, size_t count, void *data)
{
static ssize_t switch_proc_write(struct file *file, const char *buf, size_t count, void *data)
{
if (dent->data != NULL) {
switch_proc_handler *handler = (switch_proc_handler *) dent->data;
if (handler->handler.write != NULL) {
if (dent->data != NULL) {
switch_proc_handler *handler = (switch_proc_handler *) dent->data;
if (handler->handler.write != NULL) {
switch_proc_handler *tmp;
tmp = (switch_proc_handler *) kmalloc(sizeof(switch_proc_handler), GFP_KERNEL);
switch_proc_handler *tmp;
tmp = (switch_proc_handler *) kmalloc(sizeof(switch_proc_handler), GFP_KERNEL);
INIT_LIST_HEAD(&tmp->list);
tmp->parent = parent;
tmp->nr = nr;
tmp->driver = driver;
memcpy(&tmp->handler, handler, sizeof(switch_config));
list_add(&tmp->list, &priv->data.list);
INIT_LIST_HEAD(&tmp->list);
tmp->parent = parent;
tmp->nr = nr;
tmp->driver = driver;
memcpy(&tmp->handler, handler, sizeof(switch_config));
list_add(&tmp->list, &priv->data.list);
if ((p = create_proc_entry(handler->name, mode, parent)) != NULL) {
p->data = (void *) tmp;
p->proc_fops = &switch_proc_fops;
if ((p = create_proc_entry(handler->name, mode, parent)) != NULL) {
p->data = (void *) tmp;
p->proc_fops = &switch_proc_fops;
static inline void add_handlers(switch_driver *driver, const switch_config *handlers, struct proc_dir_entry *parent, int nr)
{
int i;
static inline void add_handlers(switch_driver *driver, const switch_config *handlers, struct proc_dir_entry *parent, int nr)
{
int i;
for (i = 0; handlers[i].name != NULL; i++) {
add_handler(driver, &(handlers[i]), parent, nr);
}
for (i = 0; handlers[i].name != NULL; i++) {
add_handler(driver, &(handlers[i]), parent, nr);
}
for(i = 0; priv->ports[i] != NULL; i++) {
sprintf(buf, "%d", i);
remove_proc_entry(buf, priv->port_dir);
for(i = 0; priv->ports[i] != NULL; i++) {
sprintf(buf, "%d", i);
remove_proc_entry(buf, priv->port_dir);
remove_proc_entry("vlan", priv->driver_dir);
remove_proc_entry(driver->interface, switch_root);
remove_proc_entry("vlan", priv->driver_dir);
remove_proc_entry(driver->interface, switch_root);
priv->nr = drv_num++;
priv->driver_dir = proc_mkdir(driver->interface, switch_root);
if (driver->driver_handlers != NULL) {
add_handlers(driver, driver->driver_handlers, priv->driver_dir, 0);
add_handlers(driver, global_driver_handlers, priv->driver_dir, 0);
}
priv->nr = drv_num++;
priv->driver_dir = proc_mkdir(driver->interface, switch_root);
if (driver->driver_handlers != NULL) {
add_handlers(driver, driver->driver_handlers, priv->driver_dir, 0);
add_handlers(driver, global_driver_handlers, priv->driver_dir, 0);
}
for (i = 0; i < driver->ports; i++) {
sprintf(buf, "%d", i);
priv->ports[i] = proc_mkdir(buf, priv->port_dir);
for (i = 0; i < driver->ports; i++) {
sprintf(buf, "%d", i);
priv->ports[i] = proc_mkdir(buf, priv->port_dir);
add_handlers(driver, driver->port_handlers, priv->ports[i], i);
}
priv->ports[i] = NULL;
add_handlers(driver, driver->port_handlers, priv->ports[i], i);
}
priv->ports[i] = NULL;
for (i = 0; i < driver->vlans; i++) {
sprintf(buf, "%d", i);
priv->vlans[i] = proc_mkdir(buf, priv->vlan_dir);
for (i = 0; i < driver->vlans; i++) {
sprintf(buf, "%d", i);
priv->vlans[i] = proc_mkdir(buf, priv->vlan_dir);
add_handlers(driver, driver->vlan_handlers, priv->vlans[i], i);
}
priv->vlans[i] = NULL;
add_handlers(driver, driver->vlan_handlers, priv->vlans[i], i);
}
priv->vlans[i] = NULL;
#define toupper(c) (islower(c) ? ((c) ^ 0x20) : (c))
#define islower(c) (((unsigned char)((c) - 'a')) < 26)
#define toupper(c) (islower(c) ? ((c) ^ 0x20) : (c))
#define islower(c) (((unsigned char)((c) - 'a')) < 26)
-
- c = kmalloc(sizeof(switch_vlan_config), GFP_KERNEL);
- memset(c, 0, sizeof(switch_vlan_config));
+
+ c = kzalloc(sizeof(switch_vlan_config), GFP_KERNEL);
+ if (!c)
+ return NULL;
c->port &= (1 << driver->ports) - 1;
c->untag &= (1 << driver->ports) - 1;
c->pvid &= (1 << driver->ports) - 1;
c->port &= (1 << driver->ports) - 1;
c->untag &= (1 << driver->ports) - 1;
c->pvid &= (1 << driver->ports) - 1;
+int switch_device_registered (char* device) {
+ struct list_head *pos;
+
+ list_for_each(pos, &drivers.list) {
+ if (strcmp(list_entry(pos, switch_driver, list)->interface, device) == 0) {
+ printk("There is already a switch registered on the device '%s'\n", device);
+ return -EINVAL;
+ }
+ }
+
+ return 0;
+}
+
+
list_for_each(pos, &drivers.list) {
if (strcmp(list_entry(pos, switch_driver, list)->name, driver->name) == 0) {
printk("Switch driver '%s' already exists in the kernel\n", driver->name);
list_for_each(pos, &drivers.list) {
if (strcmp(list_entry(pos, switch_driver, list)->name, driver->name) == 0) {
printk("Switch driver '%s' already exists in the kernel\n", driver->name);
memcpy(new, driver, sizeof(switch_driver));
new->name = strdup(driver->name);
new->interface = strdup(driver->interface);
memcpy(new, driver, sizeof(switch_driver));
new->name = strdup(driver->name);
new->interface = strdup(driver->interface);
EXPORT_SYMBOL(switch_register_driver);
EXPORT_SYMBOL(switch_unregister_driver);
EXPORT_SYMBOL(switch_parse_vlan);
EXPORT_SYMBOL(switch_register_driver);
EXPORT_SYMBOL(switch_unregister_driver);
EXPORT_SYMBOL(switch_parse_vlan);