upgrade to linux 2.6.10-1.12_FC2
[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 propagated 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 err;
100         }
101
102         dev_add_pack(&vlan_packet_type);
103
104         /* Register us to receive netdevice events */
105         err = register_netdevice_notifier(&vlan_notifier_block);
106         if (err < 0) {
107                 dev_remove_pack(&vlan_packet_type);
108                 vlan_proc_cleanup();
109                 return err;
110         }
111
112         vlan_ioctl_set(vlan_ioctl_handler);
113
114         return 0;
115 }
116
117 /* Cleanup all vlan devices 
118  * Note: devices that have been registered that but not
119  * brought up will exist but have no module ref count.
120  */
121 static void __exit vlan_cleanup_devices(void)
122 {
123         struct net_device *dev, *nxt;
124
125         rtnl_lock();
126         for (dev = dev_base; dev; dev = nxt) {
127                 nxt = dev->next;
128                 if (dev->priv_flags & IFF_802_1Q_VLAN) {
129                         unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
130                                             VLAN_DEV_INFO(dev)->vlan_id);
131
132                         unregister_netdevice(dev);
133                 }
134         }
135         rtnl_unlock();
136 }
137
138 /*
139  *     Module 'remove' entry point.
140  *     o delete /proc/net/router directory and static entries.
141  */ 
142 static void __exit vlan_cleanup_module(void)
143 {
144         int i;
145
146         vlan_ioctl_set(NULL);
147
148         /* Un-register us from receiving netdevice events */
149         unregister_netdevice_notifier(&vlan_notifier_block);
150
151         dev_remove_pack(&vlan_packet_type);
152         vlan_cleanup_devices();
153
154         /* This table must be empty if there are no module
155          * references left.
156          */
157         for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) {
158                 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
159         }
160         vlan_proc_cleanup();
161
162         synchronize_net();
163 }
164
165 module_init(vlan_proto_init);
166 module_exit(vlan_cleanup_module);
167
168 /* Must be invoked with RCU read lock (no preempt) */
169 static struct vlan_group *__vlan_find_group(int real_dev_ifindex)
170 {
171         struct vlan_group *grp;
172         struct hlist_node *n;
173         int hash = vlan_grp_hashfn(real_dev_ifindex);
174
175         hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) {
176                 if (grp->real_dev_ifindex == real_dev_ifindex)
177                         return grp;
178         }
179
180         return NULL;
181 }
182
183 /*  Find the protocol handler.  Assumes VID < VLAN_VID_MASK.
184  *
185  * Must be invoked with RCU read lock (no preempt)
186  */
187 struct net_device *__find_vlan_dev(struct net_device *real_dev,
188                                    unsigned short VID)
189 {
190         struct vlan_group *grp = __vlan_find_group(real_dev->ifindex);
191
192         if (grp)
193                 return grp->vlan_devices[VID];
194
195         return NULL;
196 }
197
198 static void vlan_rcu_free(struct rcu_head *rcu)
199 {
200         kfree(container_of(rcu, struct vlan_group, rcu));
201 }
202
203
204 /* This returns 0 if everything went fine.
205  * It will return 1 if the group was killed as a result.
206  * A negative return indicates failure.
207  *
208  * The RTNL lock must be held.
209  */
210 static int unregister_vlan_dev(struct net_device *real_dev,
211                                unsigned short vlan_id)
212 {
213         struct net_device *dev = NULL;
214         int real_dev_ifindex = real_dev->ifindex;
215         struct vlan_group *grp;
216         int i, ret;
217
218 #ifdef VLAN_DEBUG
219         printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id);
220 #endif
221
222         /* sanity check */
223         if (vlan_id >= VLAN_VID_MASK)
224                 return -EINVAL;
225
226         ASSERT_RTNL();
227         grp = __vlan_find_group(real_dev_ifindex);
228
229         ret = 0;
230
231         if (grp) {
232                 dev = grp->vlan_devices[vlan_id];
233                 if (dev) {
234                         /* Remove proc entry */
235                         vlan_proc_rem_dev(dev);
236
237                         /* Take it out of our own structures, but be sure to
238                          * interlock with HW accelerating devices or SW vlan
239                          * input packet processing.
240                          */
241                         if (real_dev->features &
242                             (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_FILTER)) {
243                                 real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
244                         }
245
246                         grp->vlan_devices[vlan_id] = NULL;
247                         synchronize_net();
248
249
250                         /* Caller unregisters (and if necessary, puts)
251                          * VLAN device, but we get rid of the reference to
252                          * real_dev here.
253                          */
254                         dev_put(real_dev);
255
256                         /* If the group is now empty, kill off the
257                          * group.
258                          */
259                         for (i = 0; i < VLAN_VID_MASK; i++)
260                                 if (grp->vlan_devices[i])
261                                         break;
262
263                         if (i == VLAN_VID_MASK) {
264                                 if (real_dev->features & NETIF_F_HW_VLAN_RX)
265                                         real_dev->vlan_rx_register(real_dev, NULL);
266
267                                 hlist_del_rcu(&grp->hlist);
268
269                                 /* Free the group, after all cpu's are done. */
270                                 call_rcu(&grp->rcu, vlan_rcu_free);
271
272                                 grp = NULL;
273                                 ret = 1;
274                         }
275                 }
276         }
277
278         return ret;
279 }
280
281 static int unregister_vlan_device(const char *vlan_IF_name)
282 {
283         struct net_device *dev = NULL;
284         int ret;
285
286
287         dev = dev_get_by_name(vlan_IF_name);
288         ret = -EINVAL;
289         if (dev) {
290                 if (dev->priv_flags & IFF_802_1Q_VLAN) {
291                         rtnl_lock();
292
293                         ret = unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
294                                                   VLAN_DEV_INFO(dev)->vlan_id);
295
296                         dev_put(dev);
297                         unregister_netdevice(dev);
298
299                         rtnl_unlock();
300
301                         if (ret == 1)
302                                 ret = 0;
303                 } else {
304                         printk(VLAN_ERR 
305                                "%s: ERROR:      Tried to remove a non-vlan device "
306                                "with VLAN code, name: %s  priv_flags: %hX\n",
307                                __FUNCTION__, dev->name, dev->priv_flags);
308                         dev_put(dev);
309                         ret = -EPERM;
310                 }
311         } else {
312 #ifdef VLAN_DEBUG
313                 printk(VLAN_DBG "%s: WARNING: Could not find dev.\n", __FUNCTION__);
314 #endif
315                 ret = -EINVAL;
316         }
317
318         return ret;
319 }
320
321 static void vlan_setup(struct net_device *new_dev)
322 {
323         SET_MODULE_OWNER(new_dev);
324             
325         /* new_dev->ifindex = 0;  it will be set when added to
326          * the global list.
327          * iflink is set as well.
328          */
329         new_dev->get_stats = vlan_dev_get_stats;
330
331         /* Make this thing known as a VLAN device */
332         new_dev->priv_flags |= IFF_802_1Q_VLAN;
333                                 
334         /* Set us up to have no queue, as the underlying Hardware device
335          * can do all the queueing we could want.
336          */
337         new_dev->tx_queue_len = 0;
338
339         /* set up method calls */
340         new_dev->change_mtu = vlan_dev_change_mtu;
341         new_dev->open = vlan_dev_open;
342         new_dev->stop = vlan_dev_stop;
343         new_dev->set_mac_address = vlan_dev_set_mac_address;
344         new_dev->set_multicast_list = vlan_dev_set_multicast_list;
345         new_dev->destructor = free_netdev;
346         new_dev->do_ioctl = vlan_dev_ioctl;
347 }
348
349 /*  Attach a VLAN device to a mac address (ie Ethernet Card).
350  *  Returns the device that was created, or NULL if there was
351  *  an error of some kind.
352  */
353 static struct net_device *register_vlan_device(const char *eth_IF_name,
354                                                unsigned short VLAN_ID)
355 {
356         struct vlan_group *grp;
357         struct net_device *new_dev;
358         struct net_device *real_dev; /* the ethernet device */
359         char name[IFNAMSIZ];
360
361 #ifdef VLAN_DEBUG
362         printk(VLAN_DBG "%s: if_name -:%s:-     vid: %i\n",
363                 __FUNCTION__, eth_IF_name, VLAN_ID);
364 #endif
365
366         if (VLAN_ID >= VLAN_VID_MASK)
367                 goto out_ret_null;
368
369         /* find the device relating to eth_IF_name. */
370         real_dev = dev_get_by_name(eth_IF_name);
371         if (!real_dev)
372                 goto out_ret_null;
373
374         if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
375                 printk(VLAN_DBG "%s: VLANs not supported on %s.\n",
376                         __FUNCTION__, real_dev->name);
377                 goto out_put_dev;
378         }
379
380         if ((real_dev->features & NETIF_F_HW_VLAN_RX) &&
381             (real_dev->vlan_rx_register == NULL ||
382              real_dev->vlan_rx_kill_vid == NULL)) {
383                 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
384                         __FUNCTION__, real_dev->name);
385                 goto out_put_dev;
386         }
387
388         if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
389             (real_dev->vlan_rx_add_vid == NULL ||
390              real_dev->vlan_rx_kill_vid == NULL)) {
391                 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
392                         __FUNCTION__, real_dev->name);
393                 goto out_put_dev;
394         }
395
396         /* From this point on, all the data structures must remain
397          * consistent.
398          */
399         rtnl_lock();
400
401         /* The real device must be up and operating in order to
402          * assosciate a VLAN device with it.
403          */
404         if (!(real_dev->flags & IFF_UP))
405                 goto out_unlock;
406
407         if (__find_vlan_dev(real_dev, VLAN_ID) != NULL) {
408                 /* was already registered. */
409                 printk(VLAN_DBG "%s: ALREADY had VLAN registered\n", __FUNCTION__);
410                 goto out_unlock;
411         }
412
413         /* Gotta set up the fields for the device. */
414 #ifdef VLAN_DEBUG
415         printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n",
416                vlan_name_type);
417 #endif
418         switch (vlan_name_type) {
419         case VLAN_NAME_TYPE_RAW_PLUS_VID:
420                 /* name will look like:  eth1.0005 */
421                 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID);
422                 break;
423         case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
424                 /* Put our vlan.VID in the name.
425                  * Name will look like:  vlan5
426                  */
427                 snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID);
428                 break;
429         case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
430                 /* Put our vlan.VID in the name.
431                  * Name will look like:  eth0.5
432                  */
433                 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID);
434                 break;
435         case VLAN_NAME_TYPE_PLUS_VID:
436                 /* Put our vlan.VID in the name.
437                  * Name will look like:  vlan0005
438                  */
439         default:
440                 snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID);
441         };
442                     
443         new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name,
444                                vlan_setup);
445         if (new_dev == NULL)
446                 goto out_unlock;
447
448 #ifdef VLAN_DEBUG
449         printk(VLAN_DBG "Allocated new name -:%s:-\n", new_dev->name);
450 #endif
451         /* IFF_BROADCAST|IFF_MULTICAST; ??? */
452         new_dev->flags = real_dev->flags;
453         new_dev->flags &= ~IFF_UP;
454
455         new_dev->state = real_dev->state & VLAN_LINK_STATE_MASK;
456
457         /* need 4 bytes for extra VLAN header info,
458          * hope the underlying device can handle it.
459          */
460         new_dev->mtu = real_dev->mtu;
461
462         /* TODO: maybe just assign it to be ETHERNET? */
463         new_dev->type = real_dev->type;
464
465         new_dev->hard_header_len = real_dev->hard_header_len;
466         if (!(real_dev->features & NETIF_F_HW_VLAN_TX)) {
467                 /* Regular ethernet + 4 bytes (18 total). */
468                 new_dev->hard_header_len += VLAN_HLEN;
469         }
470
471         VLAN_MEM_DBG("new_dev->priv malloc, addr: %p  size: %i\n",
472                      new_dev->priv,
473                      sizeof(struct vlan_dev_info));
474             
475         memcpy(new_dev->broadcast, real_dev->broadcast, real_dev->addr_len);
476         memcpy(new_dev->dev_addr, real_dev->dev_addr, real_dev->addr_len);
477         new_dev->addr_len = real_dev->addr_len;
478
479         if (real_dev->features & NETIF_F_HW_VLAN_TX) {
480                 new_dev->hard_header = real_dev->hard_header;
481                 new_dev->hard_start_xmit = vlan_dev_hwaccel_hard_start_xmit;
482                 new_dev->rebuild_header = real_dev->rebuild_header;
483         } else {
484                 new_dev->hard_header = vlan_dev_hard_header;
485                 new_dev->hard_start_xmit = vlan_dev_hard_start_xmit;
486                 new_dev->rebuild_header = vlan_dev_rebuild_header;
487         }
488         new_dev->hard_header_parse = real_dev->hard_header_parse;
489
490         VLAN_DEV_INFO(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */
491         VLAN_DEV_INFO(new_dev)->real_dev = real_dev;
492         VLAN_DEV_INFO(new_dev)->dent = NULL;
493         VLAN_DEV_INFO(new_dev)->flags = vlan_default_dev_flags;
494
495 #ifdef VLAN_DEBUG
496         printk(VLAN_DBG "About to go find the group for idx: %i\n",
497                real_dev->ifindex);
498 #endif
499             
500         if (register_netdevice(new_dev))
501                 goto out_free_newdev;
502
503         /* So, got the sucker initialized, now lets place
504          * it into our local structure.
505          */
506         grp = __vlan_find_group(real_dev->ifindex);
507
508         /* Note, we are running under the RTNL semaphore
509          * so it cannot "appear" on us.
510          */
511         if (!grp) { /* need to add a new group */
512                 grp = kmalloc(sizeof(struct vlan_group), GFP_KERNEL);
513                 if (!grp)
514                         goto out_free_unregister;
515                                         
516                 /* printk(KERN_ALERT "VLAN REGISTER:  Allocated new group.\n"); */
517                 memset(grp, 0, sizeof(struct vlan_group));
518                 grp->real_dev_ifindex = real_dev->ifindex;
519
520                 hlist_add_head_rcu(&grp->hlist, 
521                                    &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]);
522
523                 if (real_dev->features & NETIF_F_HW_VLAN_RX)
524                         real_dev->vlan_rx_register(real_dev, grp);
525         }
526             
527         grp->vlan_devices[VLAN_ID] = new_dev;
528
529         if (vlan_proc_add_dev(new_dev)<0)/* create it's proc entry */
530                 printk(KERN_WARNING "VLAN: failed to add proc entry for %s\n",
531                                                          new_dev->name);
532
533         if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
534                 real_dev->vlan_rx_add_vid(real_dev, VLAN_ID);
535
536         rtnl_unlock();
537
538
539 #ifdef VLAN_DEBUG
540         printk(VLAN_DBG "Allocated new device successfully, returning.\n");
541 #endif
542         return new_dev;
543
544 out_free_unregister:
545         unregister_netdev(new_dev);
546         goto out_unlock;
547
548 out_free_newdev:
549         free_netdev(new_dev);
550
551 out_unlock:
552         rtnl_unlock();
553
554 out_put_dev:
555         dev_put(real_dev);
556
557 out_ret_null:
558         return NULL;
559 }
560
561 static int vlan_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
562 {
563         struct net_device *dev = ptr;
564         struct vlan_group *grp = __vlan_find_group(dev->ifindex);
565         int i, flgs;
566         struct net_device *vlandev;
567
568         if (!grp)
569                 goto out;
570
571         /* It is OK that we do not hold the group lock right now,
572          * as we run under the RTNL lock.
573          */
574
575         switch (event) {
576         case NETDEV_CHANGE:
577                 /* Propagate real device state to vlan devices */
578                 flgs = dev->state & VLAN_LINK_STATE_MASK;
579                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
580                         vlandev = grp->vlan_devices[i];
581                         if (!vlandev)
582                                 continue;
583
584                         if ((vlandev->state & VLAN_LINK_STATE_MASK) != flgs) {
585                                 vlandev->state = (vlandev->state &~ VLAN_LINK_STATE_MASK) 
586                                         | flgs;
587                                 netdev_state_change(vlandev);
588                         }
589                 }
590                 break;
591
592         case NETDEV_DOWN:
593                 /* Put all VLANs for this dev in the down state too.  */
594                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
595                         vlandev = grp->vlan_devices[i];
596                         if (!vlandev)
597                                 continue;
598
599                         flgs = vlandev->flags;
600                         if (!(flgs & IFF_UP))
601                                 continue;
602
603                         dev_change_flags(vlandev, flgs & ~IFF_UP);
604                 }
605                 break;
606
607         case NETDEV_UP:
608                 /* Put all VLANs for this dev in the up state too.  */
609                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
610                         vlandev = grp->vlan_devices[i];
611                         if (!vlandev)
612                                 continue;
613                                 
614                         flgs = vlandev->flags;
615                         if (flgs & IFF_UP)
616                                 continue;
617
618                         dev_change_flags(vlandev, flgs | IFF_UP);
619                 }
620                 break;
621                 
622         case NETDEV_UNREGISTER:
623                 /* Delete all VLANs for this dev. */
624                 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
625                         int ret;
626
627                         vlandev = grp->vlan_devices[i];
628                         if (!vlandev)
629                                 continue;
630
631                         ret = unregister_vlan_dev(dev,
632                                                   VLAN_DEV_INFO(vlandev)->vlan_id);
633
634                         unregister_netdevice(vlandev);
635
636                         /* Group was destroyed? */
637                         if (ret == 1)
638                                 break;
639                 }
640                 break;
641         };
642
643 out:
644         return NOTIFY_DONE;
645 }
646
647 /*
648  *      VLAN IOCTL handler.
649  *      o execute requested action or pass command to the device driver
650  *   arg is really a struct vlan_ioctl_args __user *.
651  */
652 static int vlan_ioctl_handler(void __user *arg)
653 {
654         int err = 0;
655         unsigned short vid = 0;
656         struct vlan_ioctl_args args;
657
658         if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
659                 return -EFAULT;
660
661         /* Null terminate this sucker, just in case. */
662         args.device1[23] = 0;
663         args.u.device2[23] = 0;
664
665 #ifdef VLAN_DEBUG
666         printk(VLAN_DBG "%s: args.cmd: %x\n", __FUNCTION__, args.cmd);
667 #endif
668
669         switch (args.cmd) {
670         case SET_VLAN_INGRESS_PRIORITY_CMD:
671                 if (!capable(CAP_NET_ADMIN))
672                         return -EPERM;
673                 err = vlan_dev_set_ingress_priority(args.device1,
674                                                     args.u.skb_priority,
675                                                     args.vlan_qos);
676                 break;
677
678         case SET_VLAN_EGRESS_PRIORITY_CMD:
679                 if (!capable(CAP_NET_ADMIN))
680                         return -EPERM;
681                 err = vlan_dev_set_egress_priority(args.device1,
682                                                    args.u.skb_priority,
683                                                    args.vlan_qos);
684                 break;
685
686         case SET_VLAN_FLAG_CMD:
687                 if (!capable(CAP_NET_ADMIN))
688                         return -EPERM;
689                 err = vlan_dev_set_vlan_flag(args.device1,
690                                              args.u.flag,
691                                              args.vlan_qos);
692                 break;
693
694         case SET_VLAN_NAME_TYPE_CMD:
695                 if (!capable(CAP_NET_ADMIN))
696                         return -EPERM;
697                 if ((args.u.name_type >= 0) &&
698                     (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
699                         vlan_name_type = args.u.name_type;
700                         err = 0;
701                 } else {
702                         err = -EINVAL;
703                 }
704                 break;
705
706         case ADD_VLAN_CMD:
707                 if (!capable(CAP_NET_ADMIN))
708                         return -EPERM;
709                 /* we have been given the name of the Ethernet Device we want to
710                  * talk to:  args.dev1   We also have the
711                  * VLAN ID:  args.u.VID
712                  */
713                 if (register_vlan_device(args.device1, args.u.VID)) {
714                         err = 0;
715                 } else {
716                         err = -EINVAL;
717                 }
718                 break;
719
720         case DEL_VLAN_CMD:
721                 if (!capable(CAP_NET_ADMIN))
722                         return -EPERM;
723                 /* Here, the args.dev1 is the actual VLAN we want
724                  * to get rid of.
725                  */
726                 err = unregister_vlan_device(args.device1);
727                 break;
728
729         case GET_VLAN_INGRESS_PRIORITY_CMD:
730                 /* TODO:  Implement
731                    err = vlan_dev_get_ingress_priority(args);
732                    if (copy_to_user((void*)arg, &args,
733                         sizeof(struct vlan_ioctl_args))) {
734                         err = -EFAULT;
735                    }
736                 */
737                 err = -EINVAL;
738                 break;
739         case GET_VLAN_EGRESS_PRIORITY_CMD:
740                 /* TODO:  Implement
741                    err = vlan_dev_get_egress_priority(args.device1, &(args.args);
742                    if (copy_to_user((void*)arg, &args,
743                         sizeof(struct vlan_ioctl_args))) {
744                         err = -EFAULT;
745                    }
746                 */
747                 err = -EINVAL;
748                 break;
749         case GET_VLAN_REALDEV_NAME_CMD:
750                 err = vlan_dev_get_realdev_name(args.device1, args.u.device2);
751                 if (copy_to_user(arg, &args,
752                                  sizeof(struct vlan_ioctl_args))) {
753                         err = -EFAULT;
754                 }
755                 break;
756
757         case GET_VLAN_VID_CMD:
758                 err = vlan_dev_get_vid(args.device1, &vid);
759                 args.u.VID = vid;
760                 if (copy_to_user(arg, &args,
761                                  sizeof(struct vlan_ioctl_args))) {
762                       err = -EFAULT;
763                 }
764                 break;
765
766         default:
767                 /* pass on to underlying device instead?? */
768                 printk(VLAN_DBG "%s: Unknown VLAN CMD: %x \n",
769                         __FUNCTION__, args.cmd);
770                 return -EINVAL;
771         };
772
773         return err;
774 }
775
776 MODULE_LICENSE("GPL");
777 MODULE_VERSION(DRV_VERSION);