phylib: add the ICPlus IP175C PHY driver
[linux-2.6.git] / net / 8021q / vlan.c
blobde78c9dd713bbfb0bb0942bea0f98bd5ffb6179a
1 /*
2 * INET 802.1Q VLAN
3 * Ethernet-type device handling.
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
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>
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.
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>
35 #include <linux/if_vlan.h>
36 #include "vlan.h"
37 #include "vlanproc.h"
39 #define DRV_VERSION "1.8"
41 /* Global VLAN variables */
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)
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>";
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 );
56 static struct notifier_block vlan_notifier_block = {
57 .notifier_call = vlan_device_event,
60 /* These may be changed at run-time through IOCTLs */
62 /* Determines interface naming scheme. */
63 unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
65 static struct packet_type vlan_packet_type = {
66 .type = __constant_htons(ETH_P_8021Q),
67 .func = vlan_skb_recv, /* VLAN receive method */
70 /* End of global variables definitions. */
73 * Function vlan_proto_init (pro)
75 * Initialize VLAN protocol layer,
78 static int __init vlan_proto_init(void)
80 int err;
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);
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;
96 dev_add_pack(&vlan_packet_type);
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;
106 vlan_ioctl_set(vlan_ioctl_handler);
108 return 0;
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.
115 static void __exit vlan_cleanup_devices(void)
117 struct net_device *dev, *nxt;
119 rtnl_lock();
120 for_each_netdev_safe(dev, nxt) {
121 if (dev->priv_flags & IFF_802_1Q_VLAN) {
122 unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
123 VLAN_DEV_INFO(dev)->vlan_id);
125 unregister_netdevice(dev);
128 rtnl_unlock();
132 * Module 'remove' entry point.
133 * o delete /proc/net/router directory and static entries.
135 static void __exit vlan_cleanup_module(void)
137 int i;
139 vlan_ioctl_set(NULL);
141 /* Un-register us from receiving netdevice events */
142 unregister_netdevice_notifier(&vlan_notifier_block);
144 dev_remove_pack(&vlan_packet_type);
145 vlan_cleanup_devices();
147 /* This table must be empty if there are no module
148 * references left.
150 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) {
151 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
153 vlan_proc_cleanup();
155 synchronize_net();
158 module_init(vlan_proto_init);
159 module_exit(vlan_cleanup_module);
161 /* Must be invoked with RCU read lock (no preempt) */
162 static struct vlan_group *__vlan_find_group(int real_dev_ifindex)
164 struct vlan_group *grp;
165 struct hlist_node *n;
166 int hash = vlan_grp_hashfn(real_dev_ifindex);
168 hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) {
169 if (grp->real_dev_ifindex == real_dev_ifindex)
170 return grp;
173 return NULL;
176 /* Find the protocol handler. Assumes VID < VLAN_VID_MASK.
178 * Must be invoked with RCU read lock (no preempt)
180 struct net_device *__find_vlan_dev(struct net_device *real_dev,
181 unsigned short VID)
183 struct vlan_group *grp = __vlan_find_group(real_dev->ifindex);
185 if (grp)
186 return vlan_group_get_device(grp, VID);
188 return NULL;
191 static void vlan_group_free(struct vlan_group *grp)
193 int i;
195 for (i=0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++)
196 kfree(grp->vlan_devices_arrays[i]);
197 kfree(grp);
200 static void vlan_rcu_free(struct rcu_head *rcu)
202 vlan_group_free(container_of(rcu, struct vlan_group, rcu));
206 /* This returns 0 if everything went fine.
207 * It will return 1 if the group was killed as a result.
208 * A negative return indicates failure.
210 * The RTNL lock must be held.
212 static int unregister_vlan_dev(struct net_device *real_dev,
213 unsigned short vlan_id)
215 struct net_device *dev = NULL;
216 int real_dev_ifindex = real_dev->ifindex;
217 struct vlan_group *grp;
218 int i, ret;
220 #ifdef VLAN_DEBUG
221 printk(VLAN_DBG "%s: VID: %i\n", __FUNCTION__, vlan_id);
222 #endif
224 /* sanity check */
225 if (vlan_id >= VLAN_VID_MASK)
226 return -EINVAL;
228 ASSERT_RTNL();
229 grp = __vlan_find_group(real_dev_ifindex);
231 ret = 0;
233 if (grp) {
234 dev = vlan_group_get_device(grp, vlan_id);
235 if (dev) {
236 /* Remove proc entry */
237 vlan_proc_rem_dev(dev);
239 /* Take it out of our own structures, but be sure to
240 * interlock with HW accelerating devices or SW vlan
241 * input packet processing.
243 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
244 real_dev->vlan_rx_kill_vid(real_dev, vlan_id);
246 vlan_group_set_device(grp, vlan_id, NULL);
247 synchronize_net();
250 /* Caller unregisters (and if necessary, puts)
251 * VLAN device, but we get rid of the reference to
252 * real_dev here.
254 dev_put(real_dev);
256 /* If the group is now empty, kill off the
257 * group.
259 for (i = 0; i < VLAN_VID_MASK; i++)
260 if (vlan_group_get_device(grp, i))
261 break;
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);
267 hlist_del_rcu(&grp->hlist);
269 /* Free the group, after all cpu's are done. */
270 call_rcu(&grp->rcu, vlan_rcu_free);
272 grp = NULL;
273 ret = 1;
278 return ret;
281 static int unregister_vlan_device(const char *vlan_IF_name)
283 struct net_device *dev = NULL;
284 int ret;
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();
293 ret = unregister_vlan_dev(VLAN_DEV_INFO(dev)->real_dev,
294 VLAN_DEV_INFO(dev)->vlan_id);
296 dev_put(dev);
297 unregister_netdevice(dev);
299 rtnl_unlock();
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;
311 } else {
312 #ifdef VLAN_DEBUG
313 printk(VLAN_DBG "%s: WARNING: Could not find dev.\n", __FUNCTION__);
314 #endif
315 ret = -EINVAL;
318 return ret;
321 static void vlan_setup(struct net_device *new_dev)
323 SET_MODULE_OWNER(new_dev);
325 /* new_dev->ifindex = 0; it will be set when added to
326 * the global list.
327 * iflink is set as well.
329 new_dev->get_stats = vlan_dev_get_stats;
331 /* Make this thing known as a VLAN device */
332 new_dev->priv_flags |= IFF_802_1Q_VLAN;
334 /* Set us up to have no queue, as the underlying Hardware device
335 * can do all the queueing we could want.
337 new_dev->tx_queue_len = 0;
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;
349 static void vlan_transfer_operstate(const struct net_device *dev, struct net_device *vlandev)
351 /* Have to respect userspace enforced dormant state
352 * of real device, also must allow supplicant running
353 * on VLAN device
355 if (dev->operstate == IF_OPER_DORMANT)
356 netif_dormant_on(vlandev);
357 else
358 netif_dormant_off(vlandev);
360 if (netif_carrier_ok(dev)) {
361 if (!netif_carrier_ok(vlandev))
362 netif_carrier_on(vlandev);
363 } else {
364 if (netif_carrier_ok(vlandev))
365 netif_carrier_off(vlandev);
370 * vlan network devices have devices nesting below it, and are a special
371 * "super class" of normal network devices; split their locks off into a
372 * separate class since they always nest.
374 static struct lock_class_key vlan_netdev_xmit_lock_key;
377 /* Attach a VLAN device to a mac address (ie Ethernet Card).
378 * Returns the device that was created, or NULL if there was
379 * an error of some kind.
381 static struct net_device *register_vlan_device(const char *eth_IF_name,
382 unsigned short VLAN_ID)
384 struct vlan_group *grp;
385 struct net_device *new_dev;
386 struct net_device *real_dev; /* the ethernet device */
387 char name[IFNAMSIZ];
388 int i;
390 #ifdef VLAN_DEBUG
391 printk(VLAN_DBG "%s: if_name -:%s:- vid: %i\n",
392 __FUNCTION__, eth_IF_name, VLAN_ID);
393 #endif
395 if (VLAN_ID >= VLAN_VID_MASK)
396 goto out_ret_null;
398 /* find the device relating to eth_IF_name. */
399 real_dev = dev_get_by_name(eth_IF_name);
400 if (!real_dev)
401 goto out_ret_null;
403 if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
404 printk(VLAN_DBG "%s: VLANs not supported on %s.\n",
405 __FUNCTION__, real_dev->name);
406 goto out_put_dev;
409 if ((real_dev->features & NETIF_F_HW_VLAN_RX) &&
410 !real_dev->vlan_rx_register) {
411 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
412 __FUNCTION__, real_dev->name);
413 goto out_put_dev;
416 if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
417 (!real_dev->vlan_rx_add_vid || !real_dev->vlan_rx_kill_vid)) {
418 printk(VLAN_DBG "%s: Device %s has buggy VLAN hw accel.\n",
419 __FUNCTION__, real_dev->name);
420 goto out_put_dev;
423 /* From this point on, all the data structures must remain
424 * consistent.
426 rtnl_lock();
428 /* The real device must be up and operating in order to
429 * assosciate a VLAN device with it.
431 if (!(real_dev->flags & IFF_UP))
432 goto out_unlock;
434 if (__find_vlan_dev(real_dev, VLAN_ID) != NULL) {
435 /* was already registered. */
436 printk(VLAN_DBG "%s: ALREADY had VLAN registered\n", __FUNCTION__);
437 goto out_unlock;
440 /* Gotta set up the fields for the device. */
441 #ifdef VLAN_DEBUG
442 printk(VLAN_DBG "About to allocate name, vlan_name_type: %i\n",
443 vlan_name_type);
444 #endif
445 switch (vlan_name_type) {
446 case VLAN_NAME_TYPE_RAW_PLUS_VID:
447 /* name will look like: eth1.0005 */
448 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID);
449 break;
450 case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
451 /* Put our vlan.VID in the name.
452 * Name will look like: vlan5
454 snprintf(name, IFNAMSIZ, "vlan%i", VLAN_ID);
455 break;
456 case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
457 /* Put our vlan.VID in the name.
458 * Name will look like: eth0.5
460 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, VLAN_ID);
461 break;
462 case VLAN_NAME_TYPE_PLUS_VID:
463 /* Put our vlan.VID in the name.
464 * Name will look like: vlan0005
466 default:
467 snprintf(name, IFNAMSIZ, "vlan%.4i", VLAN_ID);
470 new_dev = alloc_netdev(sizeof(struct vlan_dev_info), name,
471 vlan_setup);
473 if (new_dev == NULL)
474 goto out_unlock;
476 #ifdef VLAN_DEBUG
477 printk(VLAN_DBG "Allocated new name -:%s:-\n", new_dev->name);
478 #endif
479 /* IFF_BROADCAST|IFF_MULTICAST; ??? */
480 new_dev->flags = real_dev->flags;
481 new_dev->flags &= ~IFF_UP;
483 new_dev->state = (real_dev->state & ((1<<__LINK_STATE_NOCARRIER) |
484 (1<<__LINK_STATE_DORMANT))) |
485 (1<<__LINK_STATE_PRESENT);
487 /* need 4 bytes for extra VLAN header info,
488 * hope the underlying device can handle it.
490 new_dev->mtu = real_dev->mtu;
492 /* TODO: maybe just assign it to be ETHERNET? */
493 new_dev->type = real_dev->type;
495 new_dev->hard_header_len = real_dev->hard_header_len;
496 if (!(real_dev->features & NETIF_F_HW_VLAN_TX)) {
497 /* Regular ethernet + 4 bytes (18 total). */
498 new_dev->hard_header_len += VLAN_HLEN;
501 VLAN_MEM_DBG("new_dev->priv malloc, addr: %p size: %i\n",
502 new_dev->priv,
503 sizeof(struct vlan_dev_info));
505 memcpy(new_dev->broadcast, real_dev->broadcast, real_dev->addr_len);
506 memcpy(new_dev->dev_addr, real_dev->dev_addr, real_dev->addr_len);
507 new_dev->addr_len = real_dev->addr_len;
509 if (real_dev->features & NETIF_F_HW_VLAN_TX) {
510 new_dev->hard_header = real_dev->hard_header;
511 new_dev->hard_start_xmit = vlan_dev_hwaccel_hard_start_xmit;
512 new_dev->rebuild_header = real_dev->rebuild_header;
513 } else {
514 new_dev->hard_header = vlan_dev_hard_header;
515 new_dev->hard_start_xmit = vlan_dev_hard_start_xmit;
516 new_dev->rebuild_header = vlan_dev_rebuild_header;
518 new_dev->hard_header_parse = real_dev->hard_header_parse;
520 VLAN_DEV_INFO(new_dev)->vlan_id = VLAN_ID; /* 1 through VLAN_VID_MASK */
521 VLAN_DEV_INFO(new_dev)->real_dev = real_dev;
522 VLAN_DEV_INFO(new_dev)->dent = NULL;
523 VLAN_DEV_INFO(new_dev)->flags = 1;
525 #ifdef VLAN_DEBUG
526 printk(VLAN_DBG "About to go find the group for idx: %i\n",
527 real_dev->ifindex);
528 #endif
530 if (register_netdevice(new_dev))
531 goto out_free_newdev;
533 lockdep_set_class(&new_dev->_xmit_lock, &vlan_netdev_xmit_lock_key);
535 new_dev->iflink = real_dev->ifindex;
536 vlan_transfer_operstate(real_dev, new_dev);
537 linkwatch_fire_event(new_dev); /* _MUST_ call rfc2863_policy() */
539 /* So, got the sucker initialized, now lets place
540 * it into our local structure.
542 grp = __vlan_find_group(real_dev->ifindex);
544 /* Note, we are running under the RTNL semaphore
545 * so it cannot "appear" on us.
547 if (!grp) { /* need to add a new group */
548 grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL);
549 if (!grp)
550 goto out_free_unregister;
552 for (i=0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) {
553 grp->vlan_devices_arrays[i] = kzalloc(
554 sizeof(struct net_device *)*VLAN_GROUP_ARRAY_PART_LEN,
555 GFP_KERNEL);
557 if (!grp->vlan_devices_arrays[i])
558 goto out_free_arrays;
561 /* printk(KERN_ALERT "VLAN REGISTER: Allocated new group.\n"); */
562 grp->real_dev_ifindex = real_dev->ifindex;
564 hlist_add_head_rcu(&grp->hlist,
565 &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]);
567 if (real_dev->features & NETIF_F_HW_VLAN_RX)
568 real_dev->vlan_rx_register(real_dev, grp);
571 vlan_group_set_device(grp, VLAN_ID, new_dev);
573 if (vlan_proc_add_dev(new_dev)<0)/* create it's proc entry */
574 printk(KERN_WARNING "VLAN: failed to add proc entry for %s\n",
575 new_dev->name);
577 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
578 real_dev->vlan_rx_add_vid(real_dev, VLAN_ID);
580 rtnl_unlock();
583 #ifdef VLAN_DEBUG
584 printk(VLAN_DBG "Allocated new device successfully, returning.\n");
585 #endif
586 return new_dev;
588 out_free_arrays:
589 vlan_group_free(grp);
591 out_free_unregister:
592 unregister_netdev(new_dev);
593 goto out_unlock;
595 out_free_newdev:
596 free_netdev(new_dev);
598 out_unlock:
599 rtnl_unlock();
601 out_put_dev:
602 dev_put(real_dev);
604 out_ret_null:
605 return NULL;
608 static int vlan_device_event(struct notifier_block *unused, unsigned long event, void *ptr)
610 struct net_device *dev = ptr;
611 struct vlan_group *grp = __vlan_find_group(dev->ifindex);
612 int i, flgs;
613 struct net_device *vlandev;
615 if (!grp)
616 goto out;
618 /* It is OK that we do not hold the group lock right now,
619 * as we run under the RTNL lock.
622 switch (event) {
623 case NETDEV_CHANGE:
624 /* Propagate real device state to vlan devices */
625 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
626 vlandev = vlan_group_get_device(grp, i);
627 if (!vlandev)
628 continue;
630 vlan_transfer_operstate(dev, vlandev);
632 break;
634 case NETDEV_DOWN:
635 /* Put all VLANs for this dev in the down state too. */
636 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
637 vlandev = vlan_group_get_device(grp, i);
638 if (!vlandev)
639 continue;
641 flgs = vlandev->flags;
642 if (!(flgs & IFF_UP))
643 continue;
645 dev_change_flags(vlandev, flgs & ~IFF_UP);
647 break;
649 case NETDEV_UP:
650 /* Put all VLANs for this dev in the up state too. */
651 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
652 vlandev = vlan_group_get_device(grp, i);
653 if (!vlandev)
654 continue;
656 flgs = vlandev->flags;
657 if (flgs & IFF_UP)
658 continue;
660 dev_change_flags(vlandev, flgs | IFF_UP);
662 break;
664 case NETDEV_UNREGISTER:
665 /* Delete all VLANs for this dev. */
666 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
667 int ret;
669 vlandev = vlan_group_get_device(grp, i);
670 if (!vlandev)
671 continue;
673 ret = unregister_vlan_dev(dev,
674 VLAN_DEV_INFO(vlandev)->vlan_id);
676 unregister_netdevice(vlandev);
678 /* Group was destroyed? */
679 if (ret == 1)
680 break;
682 break;
685 out:
686 return NOTIFY_DONE;
690 * VLAN IOCTL handler.
691 * o execute requested action or pass command to the device driver
692 * arg is really a struct vlan_ioctl_args __user *.
694 static int vlan_ioctl_handler(void __user *arg)
696 int err = 0;
697 unsigned short vid = 0;
698 struct vlan_ioctl_args args;
700 if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
701 return -EFAULT;
703 /* Null terminate this sucker, just in case. */
704 args.device1[23] = 0;
705 args.u.device2[23] = 0;
707 #ifdef VLAN_DEBUG
708 printk(VLAN_DBG "%s: args.cmd: %x\n", __FUNCTION__, args.cmd);
709 #endif
711 switch (args.cmd) {
712 case SET_VLAN_INGRESS_PRIORITY_CMD:
713 if (!capable(CAP_NET_ADMIN))
714 return -EPERM;
715 err = vlan_dev_set_ingress_priority(args.device1,
716 args.u.skb_priority,
717 args.vlan_qos);
718 break;
720 case SET_VLAN_EGRESS_PRIORITY_CMD:
721 if (!capable(CAP_NET_ADMIN))
722 return -EPERM;
723 err = vlan_dev_set_egress_priority(args.device1,
724 args.u.skb_priority,
725 args.vlan_qos);
726 break;
728 case SET_VLAN_FLAG_CMD:
729 if (!capable(CAP_NET_ADMIN))
730 return -EPERM;
731 err = vlan_dev_set_vlan_flag(args.device1,
732 args.u.flag,
733 args.vlan_qos);
734 break;
736 case SET_VLAN_NAME_TYPE_CMD:
737 if (!capable(CAP_NET_ADMIN))
738 return -EPERM;
739 if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
740 vlan_name_type = args.u.name_type;
741 err = 0;
742 } else {
743 err = -EINVAL;
745 break;
747 case ADD_VLAN_CMD:
748 if (!capable(CAP_NET_ADMIN))
749 return -EPERM;
750 /* we have been given the name of the Ethernet Device we want to
751 * talk to: args.dev1 We also have the
752 * VLAN ID: args.u.VID
754 if (register_vlan_device(args.device1, args.u.VID)) {
755 err = 0;
756 } else {
757 err = -EINVAL;
759 break;
761 case DEL_VLAN_CMD:
762 if (!capable(CAP_NET_ADMIN))
763 return -EPERM;
764 /* Here, the args.dev1 is the actual VLAN we want
765 * to get rid of.
767 err = unregister_vlan_device(args.device1);
768 break;
770 case GET_VLAN_INGRESS_PRIORITY_CMD:
771 /* TODO: Implement
772 err = vlan_dev_get_ingress_priority(args);
773 if (copy_to_user((void*)arg, &args,
774 sizeof(struct vlan_ioctl_args))) {
775 err = -EFAULT;
778 err = -EINVAL;
779 break;
780 case GET_VLAN_EGRESS_PRIORITY_CMD:
781 /* TODO: Implement
782 err = vlan_dev_get_egress_priority(args.device1, &(args.args);
783 if (copy_to_user((void*)arg, &args,
784 sizeof(struct vlan_ioctl_args))) {
785 err = -EFAULT;
788 err = -EINVAL;
789 break;
790 case GET_VLAN_REALDEV_NAME_CMD:
791 err = vlan_dev_get_realdev_name(args.device1, args.u.device2);
792 if (err)
793 goto out;
794 if (copy_to_user(arg, &args,
795 sizeof(struct vlan_ioctl_args))) {
796 err = -EFAULT;
798 break;
800 case GET_VLAN_VID_CMD:
801 err = vlan_dev_get_vid(args.device1, &vid);
802 if (err)
803 goto out;
804 args.u.VID = vid;
805 if (copy_to_user(arg, &args,
806 sizeof(struct vlan_ioctl_args))) {
807 err = -EFAULT;
809 break;
811 default:
812 /* pass on to underlying device instead?? */
813 printk(VLAN_DBG "%s: Unknown VLAN CMD: %x \n",
814 __FUNCTION__, args.cmd);
815 return -EINVAL;
817 out:
818 return err;
821 MODULE_LICENSE("GPL");
822 MODULE_VERSION(DRV_VERSION);