This commit was manufactured by cvs2svn to create tag
[linux-2.6.git] / net / 8021q / vlan.c
1 /*
2  * INET         802.1Q VLAN
3  *              Ethernet-type device handling.
4  *
5  * Authors:     Ben Greear <greearb@candelatech.com>
6  *              Please send support related email to: vlan@scry.wanfear.com
7  *              VLAN Home Page: http://www.candelatech.com/~greear/vlan.html
8  * 
9  * Fixes:
10  *              Fix for packet capture - Nick Eggleston <nick@dccinc.com>;
11  *              Add HW acceleration hooks - David S. Miller <davem@redhat.com>;
12  *              Correct all the locking - David S. Miller <davem@redhat.com>;
13  *              Use hash table for VLAN groups - David S. Miller <davem@redhat.com>
14  *
15  *              This program is free software; you can redistribute it and/or
16  *              modify it under the terms of the GNU General Public License
17  *              as published by the Free Software Foundation; either version
18  *              2 of the License, or (at your option) any later version.
19  */
20
21 #include <asm/uaccess.h> /* for copy_from_user */
22 #include <linux/module.h>
23 #include <linux/netdevice.h>
24 #include <linux/skbuff.h>
25 #include <net/datalink.h>
26 #include <linux/mm.h>
27 #include <linux/in.h>
28 #include <linux/init.h>
29 #include <net/p8022.h>
30 #include <net/arp.h>
31 #include <linux/rtnetlink.h>
32 #include <linux/notifier.h>
33
34 #include <linux/if_vlan.h>
35 #include "vlan.h"
36 #include "vlanproc.h"
37
38 #define DRV_VERSION "1.8"
39
40 /* Global VLAN variables */
41
42 /* Our listing of VLAN group(s) */
43 struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE];
44 #define vlan_grp_hashfn(IDX)    ((((IDX) >> VLAN_GRP_HASH_SHIFT) ^ (IDX)) & VLAN_GRP_HASH_MASK)
45
46 static char vlan_fullname[] = "802.1Q VLAN Support";
47 static char vlan_version[] = DRV_VERSION;
48 static char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>";
49 static char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
50
51 static int vlan_device_event(struct notifier_block *, unsigned long, void *);
52 static int vlan_ioctl_handler(void __user *);
53 static int unregister_vlan_dev(struct net_device *, unsigned short );
54
55 struct notifier_block vlan_notifier_block = {
56         .notifier_call = vlan_device_event,
57 };
58
59 /* These may be changed at run-time through IOCTLs */
60
61 /* Determines interface naming scheme. */
62 unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
63
64 /* DO reorder the header by default */
65 unsigned short vlan_default_dev_flags = 1;
66
67 static struct packet_type vlan_packet_type = {
68         .type = __constant_htons(ETH_P_8021Q),
69         .func = vlan_skb_recv, /* VLAN receive method */
70 };
71
72 /* Bits of netdev state that are propogated from real device to virtual */
73 #define VLAN_LINK_STATE_MASK \
74         ((1<<__LINK_STATE_PRESENT)|(1<<__LINK_STATE_NOCARRIER))
75
76 /* End of global variables definitions. */
77
78 /*
79  * Function vlan_proto_init (pro)
80  *
81  *    Initialize VLAN protocol layer, 
82  *
83  */
84 static int __init vlan_proto_init(void)
85 {
86         int err;
87
88         printk(VLAN_INF "%s v%s %s\n",
89                vlan_fullname, vlan_version, vlan_copyright);
90         printk(VLAN_INF "All bugs added by %s\n",
91                vlan_buggyright);
92
93         /* proc file system initialization */
94         err = vlan_proc_init();
95         if (err < 0) {
96                 printk(KERN_ERR 
97                        "%s %s: can't create entry in proc filesystem!\n",
98                        __FUNCTION__, VLAN_NAME);
99                 return 1;
100         }
101
102         dev_add_pack(&vlan_packet_type);
103
104         /* Register us to receive netdevice events */
105         register_netdevice_notifier(&vlan_notifier_block);
106
107         vlan_ioctl_set(vlan_ioctl_handler);
108
109         return 0;
110 }
111
112 /* Cleanup all vlan devices 
113  * Note: devices that have been registered that but not
114  * brought up will exist but have no module ref count.
115  */
116 static void __exit vlan_cleanup_devices(void)
117 {
118         struct net_device *dev, *nxt;
119
120         rtnl_lock();
121         for (dev = dev_base; dev; dev = nxt) {
122                 nxt = dev->next;
123                 if (dev->priv_flags & IFF_802_1Q_VLAN) {
124                         unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
125                                             VLAN_DEV_INFO(dev)->vlan_id);
126
127                         unregister_netdevice(dev);
128                 }
129         }
130         rtnl_unlock();
131 }
132
133 /*
134  *     Module 'remove' entry point.
135  *     o delete /proc/net/router directory and static entries.
136  */ 
137 static void __exit vlan_cleanup_module(void)
138 {
139         int i;
140
141         vlan_ioctl_set(NULL);
142
143         /* Un-register us from receiving netdevice events */
144         unregister_netdevice_notifier(&vlan_notifier_block);
145
146         dev_remove_pack(&vlan_packet_type);
147         vlan_cleanup_devices();
148
149         /* This table must be empty if there are no module
150          * references left.
151          */
152         for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) {
153                 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
154         }
155         vlan_proc_cleanup();
156
157         synchronize_net();
158 }
159
160 module_init(vlan_proto_init);
161 module_exit(vlan_cleanup_module);
162
163 /* Must be invoked with RCU read lock (no preempt) */
164 static struct vlan_group *__vlan_find_group(int real_dev_ifindex)
165 {
166         struct vlan_group *grp;
167         struct hlist_node *n;
168         int hash = vlan_grp_hashfn(real_dev_ifindex);
169
170         hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) {
171                 if (grp->real_dev_ifindex == real_dev_ifindex)
172                         return grp;
173         }
174
175         return NULL;
176 }
177
178 /*  Find the protocol handler.  Assumes VID < VLAN_VID_MASK.
179  *
180  * Must be invoked with RCU read lock (no preempt)
181  */
182 struct net_device *__find_vlan_dev(struct net_device *real_dev,
183                                    unsigned short VID)
184 {
185         struct vlan_group *grp = __vlan_find_group(real_dev->ifindex);
186
187         if (grp)
188                 return grp->vlan_devices[VID];
189
190         return NULL;
191 }
192
193 static void vlan_rcu_free(struct rcu_head *rcu)
194 {
195         kfree(container_of(rcu, struct vlan_group, rcu));
196 }
197
198
199 /* This returns 0 if everything went fine.
200  * It will return 1 if the group was killed as a result.
201  * A negative return indicates failure.
202  *
203  * The RTNL lock must be held.
204  */
205 static int unregister_vlan_dev(struct net_device *real_dev,
206                                unsigned short vlan_id)
207 {
208         struct net_device *dev = NULL;
209         int real_dev_ifindex = real_dev->ifindex;
210         struct vlan_group *grp;
211         int i, ret;
212
213 #ifdef VLAN_DEBUG
214         printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id);
215 #endif
216
217         /* sanity check */
218         if (vlan_id >= VLAN_VID_MASK)
219                 return -EINVAL;
220
221         ASSERT_RTNL();
222         grp = __vlan_find_group(real_dev_ifindex);
223
224         ret = 0;
225
226         if (grp) {
227                 dev = grp->vlan_devices[vlan_id];
228                 if (dev) {
229                         /* Remove proc entry */
230                         vlan_proc_rem_dev(dev);
231
232                         /* Take it out of our own structures, but be sure to
233                          * interlock with HW accelerating devices or SW vlan
234                          * input packet processing.
235                          */
236                         if (real_dev->features &
237                             (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER)) {
238                                 real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
239                         }
240
241                         grp->vlan_devices[vlan_id] = NULL;
242                         synchronize_net();
243
244
245                         /* Caller unregisters (and if necessary, puts)
246                          * VLAN device, but we get rid of the reference to
247                          * real_dev here.
248                          */
249                         dev_put(real_dev);
250
251                         /* If the group is now empty, kill off the
252                          * group.
253                          */
254                         for (i = 0; i < VLAN_VID_MASK; i++)
255                                 if (grp->vlan_devices[i])
256                                         break;
257
258                         if (i == VLAN_VID_MASK) {
259                                 if (real_dev->features & NETIF_F_HW_VLAN_RX)
260                                         real_dev->vlan_rx_register(real_dev, NULL);
261
262                                 hlist_del_rcu(&grp->hlist);
263
264                                 /* Free the group, after all cpu's are done. */
265                                 call_rcu(&grp->rcu, vlan_rcu_free);
266
267                                 grp = NULL;
268                                 ret = 1;
269                         }
270                 }
271         }
272
273         return ret;
274 }
275
276 static int unregister_vlan_device(const char *vlan_IF_name)
277 {
278         struct net_device *dev = NULL;
279         int ret;
280
281
282         dev = dev_get_by_name(vlan_IF_name);
283         ret = -EINVAL;
284         if (dev) {
285                 if (dev->priv_flags & IFF_802_1Q_VLAN) {
286                         rtnl_lock();
287
288                         ret = unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
289                                                   VLAN_DEV_INFO(dev)->vlan_id);
290
291                         dev_put(dev);
292                         unregister_netdevice(dev);
293
294                         rtnl_unlock();
295
296                         if (ret == 1)
297                                 ret = 0;
298                 } else {
299                         printk(VLAN_ERR 
300                                "%s: ERROR:      Tried to remove a non-vlan device "
301                                "with VLAN code, name: %s  priv_flags: %hX\n",
302                                __FUNCTION__, dev->name, dev->priv_flags);
303                         dev_put(dev);
304                         ret = -EPERM;
305                 }
306         } else {
307 #ifdef VLAN_DEBUG
308                 printk(VLAN_DBG "%s: WARNING: Could not find dev.\n", __FUNCTION__);
309 #endif
310                 ret = -EINVAL;
311         }
312
313         return ret;
314 }
315
316 static void vlan_setup(struct net_device *new_dev)
317 {
318         SET_MODULE_OWNER(new_dev);
319             
320         /* new_dev->ifindex = 0;  it will be set when added to
321          * the global list.
322          * iflink is set as well.
323          */
324         new_dev->get_stats = vlan_dev_get_stats;
325
326         /* Make this thing known as a VLAN device */
327         new_dev->priv_flags |= IFF_802_1Q_VLAN;
328                                 
329         /* Set us up to have no queue, as the underlying Hardware device
330          * can do all the queueing we could want.
331          */
332         new_dev->tx_queue_len = 0;
333
334         /* set up method calls */
335         new_dev->change_mtu = vlan_dev_change_mtu;
336         new_dev->open = vlan_dev_open;
337         new_dev->stop = vlan_dev_stop;
338         new_dev->set_mac_address = vlan_dev_set_mac_address;
339         new_dev->set_multicast_list = vlan_dev_set_multicast_list;
340         new_dev->destructor = free_netdev;
341         new_dev->do_ioctl = vlan_dev_ioctl;
342 }
343
344 /*  Attach a VLAN device to a mac address (ie Ethernet Card).
345  *  Returns the device that was created, or NULL if there was
346  *  an error of some kind.
347  */
348 static struct net_device *register_vlan_device(const char *eth_IF_name,
349                                                unsigned short VLAN_ID)
350 {
351         struct vlan_group *grp;
352         struct net_device *new_dev;
353         struct net_device *real_dev; /* the ethernet device */
354         char name[IFNAMSIZ];
355
356 #ifdef VLAN_DEBUG
357         printk(VLAN_DBG "%s: if_name -:%s:-     vid: %i\n",
358                 __FUNCTION__, eth_IF_name, VLAN_ID);
359 #endif
360
361         if (VLAN_ID >= VLAN_VID_MASK)
362                 goto out_ret_null;
363
364         /* find the device relating to eth_IF_name. */
365         real_dev = dev_get_by_name(eth_IF_name);
366         if (!real_dev)
367                 goto out_ret_null;
368
369         if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
370                 printk(VLAN_DBG "%s: VLANs not supported on %s.\n",
371                         __FUNCTION__, real_dev->name);
372                 goto out_put_dev;
373         }
374
375         if ((real_dev->features & NETIF_F_HW_VLAN_RX) &&
376             (real_dev->vlan_rx_register == NULL ||
377              real_dev->vlan_rx_kill_vid == NULL)) {
378                 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
379                         __FUNCTION__, real_dev->name);
380                 goto out_put_dev;
381         }
382
383         if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
384             (real_dev->vlan_rx_add_vid == NULL ||
385              real_dev->vlan_rx_kill_vid == NULL)) {
386                 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
387                         __FUNCTION__, real_dev->name);
388                 goto out_put_dev;
389         }
390
391         /* From this point on, all the data structures must remain
392          * consistent.
393          */
394         rtnl_lock();
395
396         /* The real device must be up and operating in order to
397          * assosciate a VLAN device with it.
398          */
399         if (!(real_dev->flags & IFF_UP))
400                 goto out_unlock;
401
402         if (__find_vlan_dev(real_dev, VLAN_ID) != NULL) {
403                 /* was already registered. */
404                 printk(VLAN_DBG "%s: ALREADY had VLAN registered\n", __FUNCTION__);
405                 goto out_unlock;
406         }
407
408         /* Gotta set up the fields for the device. */
409 #ifdef VLAN_DEBUG
410         printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n",
411                vlan_name_type);
412 #endif
413         switch (vlan_name_type) {
414         case VLAN_NAME_TYPE_RAW_PLUS_VID:
415                 /* name will look like:  eth1.0005 */
416                 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID);
417                 break;
418         case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
419                 /* Put our vlan.VID in the name.
420                  * Name will look like:  vlan5
421                  */
422                 snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID);
423                 break;
424         case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
425                 /* Put our vlan.VID in the name.
426                  * Name will look like:  eth0.5
427                  */
428                 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID);
429                 break;
430         case VLAN_NAME_TYPE_PLUS_VID:
431                 /* Put our vlan.VID in the name.
432                  * Name will look like:  vlan0005
433                  */
434         default:
435                 snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID);
436         };
437                     
438         new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name,
439                                vlan_setup);
440         if (new_dev == NULL)
441                 goto out_unlock;
442
443 #ifdef VLAN_DEBUG
444         printk(VLAN_DBG "Allocated new name -:%s:-\n", new_dev->name);
445 #endif
446         /* IFF_BROADCAST|IFF_MULTICAST; ??? */
447         new_dev->flags = real_dev->flags;
448         new_dev->flags &= ~IFF_UP;
449
450         new_dev->state = real_dev->state & VLAN_LINK_STATE_MASK;
451
452         /* need 4 bytes for extra VLAN header info,
453          * hope the underlying device can handle it.
454          */
455         new_dev->mtu = real_dev->mtu;
456
457         /* TODO: maybe just assign it to be ETHERNET? */
458         new_dev->type = real_dev->type;
459
460         new_dev->hard_header_len = real_dev->hard_header_len;
461         if (!(real_dev->features & NETIF_F_HW_VLAN_TX)) {
462                 /* Regular ethernet + 4 bytes (18 total). */
463                 new_dev->hard_header_len += VLAN_HLEN;
464         }
465
466         VLAN_MEM_DBG("new_dev->priv malloc, addr: %p  size: %i\n",
467                      new_dev->priv,
468                      sizeof(struct vlan_dev_info));
469             
470         memcpy(new_dev->broadcast, real_dev->broadcast, real_dev->addr_len);
471         memcpy(new_dev->dev_addr, real_dev->dev_addr, real_dev->addr_len);
472         new_dev->addr_len = real_dev->addr_len;
473
474         if (real_dev->features & NETIF_F_HW_VLAN_TX) {
475                 new_dev->hard_header = real_dev->hard_header;
476                 new_dev->hard_start_xmit = vlan_dev_hwaccel_hard_start_xmit;
477                 new_dev->rebuild_header = real_dev->rebuild_header;
478         } else {
479                 new_dev->hard_header = vlan_dev_hard_header;
480                 new_dev->hard_start_xmit = vlan_dev_hard_start_xmit;
481                 new_dev->rebuild_header = vlan_dev_rebuild_header;
482         }
483         new_dev->hard_header_parse = real_dev->hard_header_parse;
484
485         VLAN_DEV_INFO(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */
486         VLAN_DEV_INFO(new_dev)->real_dev = real_dev;
487         VLAN_DEV_INFO(new_dev)->dent = NULL;
488         VLAN_DEV_INFO(new_dev)->flags = vlan_default_dev_flags;
489
490 #ifdef VLAN_DEBUG
491         printk(VLAN_DBG "About to go find the group for idx: %i\n",
492                real_dev->ifindex);
493 #endif
494             
495         if (register_netdevice(new_dev))
496                 goto out_free_newdev;
497
498         /* So, got the sucker initialized, now lets place
499          * it into our local structure.
500          */
501         grp = __vlan_find_group(real_dev->ifindex);
502
503         /* Note, we are running under the RTNL semaphore
504          * so it cannot "appear" on us.
505          */
506         if (!grp) { /* need to add a new group */
507                 grp = kmalloc(sizeof(struct vlan_group), GFP_KERNEL);
508                 if (!grp)
509                         goto out_free_unregister;
510                                         
511                 /* printk(KERN_ALERT "VLAN REGISTER:  Allocated new group.\n"); */
512                 memset(grp, 0, sizeof(struct vlan_group));
513                 grp->real_dev_ifindex = real_dev->ifindex;
514
515                 hlist_add_head_rcu(&grp->hlist, 
516                                    &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]);
517
518                 if (real_dev->features & NETIF_F_HW_VLAN_RX)
519                         real_dev->vlan_rx_register(real_dev, grp);
520         }
521             
522         grp->vlan_devices[VLAN_ID] = new_dev;
523
524         if (vlan_proc_add_dev(new_dev)<0)/* create it's proc entry */
525                 printk(KERN_WARNING "VLAN: failed to add proc entry for %s\n",
526                                                          new_dev->name);
527
528         if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
529                 real_dev->vlan_rx_add_vid(real_dev, VLAN_ID);
530
531         rtnl_unlock();
532
533
534 #ifdef VLAN_DEBUG
535         printk(VLAN_DBG "Allocated new device successfully, returning.\n");
536 #endif
537         return new_dev;
538
539 out_free_unregister:
540         unregister_netdev(new_dev);
541         goto out_unlock;
542
543 out_free_newdev:
544         free_netdev(new_dev);
545
546 out_unlock:
547         rtnl_unlock();
548
549 out_put_dev:
550         dev_put(real_dev);
551
552 out_ret_null:
553         return NULL;
554 }
555
556 static int vlan_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
557 {
558         struct net_device *dev = ptr;
559         struct vlan_group *grp = __vlan_find_group(dev->ifindex);
560         int i, flgs;
561         struct net_device *vlandev;
562
563         if (!grp)
564                 goto out;
565
566         /* It is OK that we do not hold the group lock right now,
567          * as we run under the RTNL lock.
568          */
569
570         switch (event) {
571         case NETDEV_CHANGE:
572                 /* Propogate real device state to vlan devices */
573                 flgs = dev->state & VLAN_LINK_STATE_MASK;
574                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
575                         vlandev = grp->vlan_devices[i];
576                         if (!vlandev)
577                                 continue;
578
579                         if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
580                                 vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK) 
581                                         | flgs;
582                                 netdev_state_change(vlandev);
583                         }
584                 }
585                 break;
586
587         case NETDEV_DOWN:
588                 /* Put all VLANs for this dev in the down state too.  */
589                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
590                         vlandev = grp->vlan_devices[i];
591                         if (!vlandev)
592                                 continue;
593
594                         flgs = vlandev->flags;
595                         if (!(flgs & IFF_UP))
596                                 continue;
597
598                         dev_change_flags(vlandev, flgs & ~IFF_UP);
599                 }
600                 break;
601
602         case NETDEV_UP:
603                 /* Put all VLANs for this dev in the up state too.  */
604                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
605                         vlandev = grp->vlan_devices[i];
606                         if (!vlandev)
607                                 continue;
608                                 
609                         flgs = vlandev->flags;
610                         if (flgs & IFF_UP)
611                                 continue;
612
613                         dev_change_flags(vlandev, flgs | IFF_UP);
614                 }
615                 break;
616                 
617         case NETDEV_UNREGISTER:
618                 /* Delete all VLANs for this dev. */
619                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
620                         int ret;
621
622                         vlandev = grp->vlan_devices[i];
623                         if (!vlandev)
624                                 continue;
625
626                         ret = unregister_vlan_dev(dev,
627                                                   VLAN_DEV_INFO(vlandev)->vlan_id);
628
629                         unregister_netdevice(vlandev);
630
631                         /* Group was destroyed? */
632                         if (ret == 1)
633                                 break;
634                 }
635                 break;
636         };
637
638 out:
639         return NOTIFY_DONE;
640 }
641
642 /*
643  *      VLAN IOCTL handler.
644  *      o execute requested action or pass command to the device driver
645  *   arg is really a struct vlan_ioctl_args __user *.
646  */
647 static int vlan_ioctl_handler(void __user *arg)
648 {
649         int err = 0;
650         struct vlan_ioctl_args args;
651
652         /* everything here needs root permissions, except aguably the
653          * hack ioctls for sending packets.  However, I know _I_ don't
654          * want users running that on my network! --BLG
655          */
656         if (!capable(CAP_NET_ADMIN))
657                 return -EPERM;
658
659         if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
660                 return -EFAULT;
661
662         /* Null terminate this sucker, just in case. */
663         args.device1[23] = 0;
664         args.u.device2[23] = 0;
665
666 #ifdef VLAN_DEBUG
667         printk(VLAN_DBG "%s: args.cmd: %x\n", __FUNCTION__, args.cmd);
668 #endif
669
670         switch (args.cmd) {
671         case SET_VLAN_INGRESS_PRIORITY_CMD:
672                 err = vlan_dev_set_ingress_priority(args.device1,
673                                                     args.u.skb_priority,
674                                                     args.vlan_qos);
675                 break;
676
677         case SET_VLAN_EGRESS_PRIORITY_CMD:
678                 err = vlan_dev_set_egress_priority(args.device1,
679                                                    args.u.skb_priority,
680                                                    args.vlan_qos);
681                 break;
682
683         case SET_VLAN_FLAG_CMD:
684                 err = vlan_dev_set_vlan_flag(args.device1,
685                                              args.u.flag,
686                                              args.vlan_qos);
687                 break;
688
689         case SET_VLAN_NAME_TYPE_CMD:
690                 if ((args.u.name_type >= 0) &&
691                     (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
692                         vlan_name_type = args.u.name_type;
693                         err = 0;
694                 } else {
695                         err = -EINVAL;
696                 }
697                 break;
698
699                 /* TODO:  Figure out how to pass info back...
700                    case GET_VLAN_INGRESS_PRIORITY_IOCTL:
701                    err = vlan_dev_get_ingress_priority(args);
702                    break;
703
704                    case GET_VLAN_EGRESS_PRIORITY_IOCTL:
705                    err = vlan_dev_get_egress_priority(args);
706                    break;
707                 */
708
709         case ADD_VLAN_CMD:
710                 /* we have been given the name of the Ethernet Device we want to
711                  * talk to:  args.dev1   We also have the
712                  * VLAN ID:  args.u.VID
713                  */
714                 if (register_vlan_device(args.device1, args.u.VID)) {
715                         err = 0;
716                 } else {
717                         err = -EINVAL;
718                 }
719                 break;
720
721         case DEL_VLAN_CMD:
722                 /* Here, the args.dev1 is the actual VLAN we want
723                  * to get rid of.
724                  */
725                 err = unregister_vlan_device(args.device1);
726                 break;
727
728         default:
729                 /* pass on to underlying device instead?? */
730                 printk(VLAN_DBG "%s: Unknown VLAN CMD: %x \n",
731                         __FUNCTION__, args.cmd);
732                 return -EINVAL;
733         };
734
735         return err;
736 }
737
738 MODULE_LICENSE("GPL");
739 MODULE_VERSION(DRV_VERSION);