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