GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / net / 8021q / vlan.c
blob95f3278d4063cfd2983c053e7598fdcac86df8f9
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: netdev@vger.kernel.org
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 <linux/capability.h>
22 #include <linux/module.h>
23 #include <linux/netdevice.h>
24 #include <linux/skbuff.h>
25 #include <linux/slab.h>
26 #include <linux/init.h>
27 #include <linux/rculist.h>
28 #include <net/p8022.h>
29 #include <net/arp.h>
30 #include <linux/rtnetlink.h>
31 #include <linux/notifier.h>
32 #include <net/rtnetlink.h>
33 #include <net/net_namespace.h>
34 #include <net/netns/generic.h>
35 #include <asm/uaccess.h>
37 #include <linux/if_vlan.h>
38 #include "vlan.h"
39 #include "vlanproc.h"
40 #ifdef HNDCTF
41 #include <ctf/hndctf.h>
42 #endif /* HNDCTF */
44 #define DRV_VERSION "1.8"
46 /* Global VLAN variables */
48 int vlan_net_id __read_mostly;
50 /* Our listing of VLAN group(s) */
51 static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE];
53 const char vlan_fullname[] = "802.1Q VLAN Support";
54 const char vlan_version[] = DRV_VERSION;
55 static const char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>";
56 static const char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
58 static struct packet_type vlan_packet_type __read_mostly = {
59 .type = cpu_to_be16(ETH_P_8021Q),
60 .func = vlan_skb_recv, /* VLAN receive method */
63 /* End of global variables definitions. */
65 static inline unsigned int vlan_grp_hashfn(unsigned int idx)
67 return ((idx >> VLAN_GRP_HASH_SHIFT) ^ idx) & VLAN_GRP_HASH_MASK;
70 /* Must be invoked with RCU read lock (no preempt) */
71 static struct vlan_group *__vlan_find_group(struct net_device *real_dev)
73 struct vlan_group *grp;
74 struct hlist_node *n;
75 int hash = vlan_grp_hashfn(real_dev->ifindex);
77 hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) {
78 if (grp->real_dev == real_dev)
79 return grp;
82 return NULL;
85 /* Find the protocol handler. Assumes VID < VLAN_VID_MASK.
87 * Must be invoked with RCU read lock (no preempt)
89 struct net_device *__find_vlan_dev(struct net_device *real_dev, u16 vlan_id)
91 struct vlan_group *grp = __vlan_find_group(real_dev);
93 if (grp)
94 return vlan_group_get_device(grp, vlan_id);
96 return NULL;
99 static void vlan_group_free(struct vlan_group *grp)
101 int i;
103 for (i = 0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++)
104 kfree(grp->vlan_devices_arrays[i]);
105 kfree(grp);
108 static struct vlan_group *vlan_group_alloc(struct net_device *real_dev)
110 struct vlan_group *grp;
112 grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL);
113 if (!grp)
114 return NULL;
116 grp->real_dev = real_dev;
117 hlist_add_head_rcu(&grp->hlist,
118 &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]);
119 return grp;
122 static int vlan_group_prealloc_vid(struct vlan_group *vg, u16 vlan_id)
124 struct net_device **array;
125 unsigned int size;
127 ASSERT_RTNL();
129 array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
130 if (array != NULL)
131 return 0;
133 size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
134 array = kzalloc(size, GFP_KERNEL);
135 if (array == NULL)
136 return -ENOBUFS;
138 vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN] = array;
139 return 0;
142 static void vlan_rcu_free(struct rcu_head *rcu)
144 vlan_group_free(container_of(rcu, struct vlan_group, rcu));
147 void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
149 struct vlan_dev_info *vlan = vlan_dev_info(dev);
150 struct net_device *real_dev = vlan->real_dev;
151 const struct net_device_ops *ops = real_dev->netdev_ops;
152 struct vlan_group *grp;
153 u16 vlan_id = vlan->vlan_id;
155 ASSERT_RTNL();
157 grp = __vlan_find_group(real_dev);
158 BUG_ON(!grp);
160 /* Take it out of our own structures, but be sure to interlock with
161 * HW accelerating devices or SW vlan input packet processing if
162 * VLAN is not 0 (leave it there for 802.1p).
164 if (vlan_id && (real_dev->features & NETIF_F_HW_VLAN_FILTER))
165 ops->ndo_vlan_rx_kill_vid(real_dev, vlan_id);
167 grp->nr_vlans--;
169 vlan_group_set_device(grp, vlan_id, NULL);
170 if (!grp->killall)
171 synchronize_net();
173 #ifdef HNDCTF
174 (void)ctf_dev_vlan_delete(kcih, real_dev, vlan_id);
175 #endif /* HNDCTF */
177 unregister_netdevice_queue(dev, head);
179 /* If the group is now empty, kill off the group. */
180 if (grp->nr_vlans == 0) {
181 vlan_gvrp_uninit_applicant(real_dev);
183 if (real_dev->features & NETIF_F_HW_VLAN_RX)
184 ops->ndo_vlan_rx_register(real_dev, NULL);
186 hlist_del_rcu(&grp->hlist);
188 /* Free the group, after all cpu's are done. */
189 call_rcu(&grp->rcu, vlan_rcu_free);
192 /* Get rid of the vlan's reference to real_dev */
193 dev_put(real_dev);
196 int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
198 const char *name = real_dev->name;
199 const struct net_device_ops *ops = real_dev->netdev_ops;
201 if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
202 pr_info("8021q: VLANs not supported on %s\n", name);
203 return -EOPNOTSUPP;
206 if ((real_dev->features & NETIF_F_HW_VLAN_RX) && !ops->ndo_vlan_rx_register) {
207 pr_info("8021q: device %s has buggy VLAN hw accel\n", name);
208 return -EOPNOTSUPP;
211 if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
212 (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
213 pr_info("8021q: Device %s has buggy VLAN hw accel\n", name);
214 return -EOPNOTSUPP;
217 if (__find_vlan_dev(real_dev, vlan_id) != NULL)
218 return -EEXIST;
220 return 0;
223 int register_vlan_dev(struct net_device *dev)
225 struct vlan_dev_info *vlan = vlan_dev_info(dev);
226 struct net_device *real_dev = vlan->real_dev;
227 const struct net_device_ops *ops = real_dev->netdev_ops;
228 u16 vlan_id = vlan->vlan_id;
229 struct vlan_group *grp, *ngrp = NULL;
230 int err;
232 grp = __vlan_find_group(real_dev);
233 if (!grp) {
234 ngrp = grp = vlan_group_alloc(real_dev);
235 if (!grp)
236 return -ENOBUFS;
237 err = vlan_gvrp_init_applicant(real_dev);
238 if (err < 0)
239 goto out_free_group;
242 err = vlan_group_prealloc_vid(grp, vlan_id);
243 if (err < 0)
244 goto out_uninit_applicant;
246 err = register_netdevice(dev);
247 if (err < 0)
248 goto out_uninit_applicant;
250 /* Account for reference in struct vlan_dev_info */
251 dev_hold(real_dev);
253 netif_stacked_transfer_operstate(real_dev, dev);
254 linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
256 /* So, got the sucker initialized, now lets place
257 * it into our local structure.
259 vlan_group_set_device(grp, vlan_id, dev);
260 grp->nr_vlans++;
262 dev->features |= (real_dev->features & (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_ALL_CSUM));
264 if (ngrp && real_dev->features & NETIF_F_HW_VLAN_RX)
265 ops->ndo_vlan_rx_register(real_dev, ngrp);
266 if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
267 ops->ndo_vlan_rx_add_vid(real_dev, vlan_id);
269 return 0;
271 out_uninit_applicant:
272 if (ngrp)
273 vlan_gvrp_uninit_applicant(real_dev);
274 out_free_group:
275 if (ngrp) {
276 hlist_del_rcu(&ngrp->hlist);
277 /* Free the group, after all cpu's are done. */
278 call_rcu(&ngrp->rcu, vlan_rcu_free);
280 return err;
283 /* Attach a VLAN device to a mac address (ie Ethernet Card).
284 * Returns 0 if the device was created or a negative error code otherwise.
286 static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
288 struct net_device *new_dev;
289 struct net *net = dev_net(real_dev);
290 struct vlan_net *vn = net_generic(net, vlan_net_id);
291 char name[IFNAMSIZ];
292 int err;
294 if (vlan_id >= VLAN_VID_MASK)
295 return -ERANGE;
297 err = vlan_check_real_dev(real_dev, vlan_id);
298 if (err < 0)
299 return err;
301 /* Gotta set up the fields for the device. */
302 switch (vn->name_type) {
303 case VLAN_NAME_TYPE_RAW_PLUS_VID:
304 /* name will look like: eth1.0005 */
305 snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
306 break;
307 case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
308 /* Put our vlan.VID in the name.
309 * Name will look like: vlan5
311 snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
312 break;
313 case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
314 /* Put our vlan.VID in the name.
315 * Name will look like: eth0.5
317 snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
318 break;
319 case VLAN_NAME_TYPE_PLUS_VID:
320 /* Put our vlan.VID in the name.
321 * Name will look like: vlan0005
323 default:
324 snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
327 new_dev = alloc_netdev_mq(sizeof(struct vlan_dev_info), name,
328 vlan_setup, real_dev->num_tx_queues);
330 if (new_dev == NULL)
331 return -ENOBUFS;
333 new_dev->real_num_tx_queues = real_dev->real_num_tx_queues;
334 dev_net_set(new_dev, net);
335 /* need 4 bytes for extra VLAN header info,
336 * hope the underlying device can handle it.
338 new_dev->mtu = real_dev->mtu;
340 vlan_dev_info(new_dev)->vlan_id = vlan_id;
341 vlan_dev_info(new_dev)->real_dev = real_dev;
342 vlan_dev_info(new_dev)->dent = NULL;
343 vlan_dev_info(new_dev)->flags = VLAN_FLAG_REORDER_HDR;
345 new_dev->rtnl_link_ops = &vlan_link_ops;
346 err = register_vlan_dev(new_dev);
347 if (err < 0)
348 goto out_free_newdev;
350 #ifdef HNDCTF
351 (void)ctf_dev_vlan_add(kcih, real_dev, vlan_id, new_dev);
352 #endif /* HNDCTF */
354 return 0;
356 out_free_newdev:
357 free_netdev(new_dev);
358 return err;
361 static void vlan_sync_address(struct net_device *dev,
362 struct net_device *vlandev)
364 struct vlan_dev_info *vlan = vlan_dev_info(vlandev);
366 /* May be called without an actual change */
367 if (!compare_ether_addr(vlan->real_dev_addr, dev->dev_addr))
368 return;
370 /* vlan address was different from the old address and is equal to
371 * the new address */
372 if (compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) &&
373 !compare_ether_addr(vlandev->dev_addr, dev->dev_addr))
374 dev_uc_del(dev, vlandev->dev_addr);
376 /* vlan address was equal to the old address and is different from
377 * the new address */
378 if (!compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) &&
379 compare_ether_addr(vlandev->dev_addr, dev->dev_addr))
380 dev_uc_add(dev, vlandev->dev_addr);
382 memcpy(vlan->real_dev_addr, dev->dev_addr, ETH_ALEN);
385 static void vlan_transfer_features(struct net_device *dev,
386 struct net_device *vlandev)
388 unsigned long old_features = vlandev->features;
390 vlandev->features &= ~dev->vlan_features;
391 vlandev->features |= dev->features & dev->vlan_features;
392 vlandev->gso_max_size = dev->gso_max_size;
393 #if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
394 vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid;
395 #endif
396 vlandev->real_num_tx_queues = dev->real_num_tx_queues;
397 BUG_ON(vlandev->real_num_tx_queues > vlandev->num_tx_queues);
399 if (old_features != vlandev->features)
400 netdev_features_change(vlandev);
403 static void __vlan_device_event(struct net_device *dev, unsigned long event)
405 switch (event) {
406 case NETDEV_CHANGENAME:
407 vlan_proc_rem_dev(dev);
408 if (vlan_proc_add_dev(dev) < 0)
409 pr_warning("8021q: failed to change proc name for %s\n",
410 dev->name);
411 break;
412 case NETDEV_REGISTER:
413 if (vlan_proc_add_dev(dev) < 0)
414 pr_warning("8021q: failed to add proc entry for %s\n",
415 dev->name);
416 break;
417 case NETDEV_UNREGISTER:
418 vlan_proc_rem_dev(dev);
419 break;
423 static int vlan_device_event(struct notifier_block *unused, unsigned long event,
424 void *ptr)
426 struct net_device *dev = ptr;
427 struct vlan_group *grp;
428 int i, flgs;
429 struct net_device *vlandev;
430 struct vlan_dev_info *vlan;
431 LIST_HEAD(list);
433 if (is_vlan_dev(dev))
434 __vlan_device_event(dev, event);
436 if ((event == NETDEV_UP) &&
437 (dev->features & NETIF_F_HW_VLAN_FILTER) &&
438 dev->netdev_ops->ndo_vlan_rx_add_vid) {
439 pr_info("8021q: adding VLAN 0 to HW filter on device %s\n",
440 dev->name);
441 dev->netdev_ops->ndo_vlan_rx_add_vid(dev, 0);
444 grp = __vlan_find_group(dev);
445 if (!grp)
446 goto out;
448 /* It is OK that we do not hold the group lock right now,
449 * as we run under the RTNL lock.
452 switch (event) {
453 case NETDEV_CHANGE:
454 /* Propagate real device state to vlan devices */
455 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
456 vlandev = vlan_group_get_device(grp, i);
457 if (!vlandev)
458 continue;
460 netif_stacked_transfer_operstate(dev, vlandev);
462 break;
464 case NETDEV_CHANGEADDR:
465 /* Adjust unicast filters on underlying device */
466 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
467 vlandev = vlan_group_get_device(grp, i);
468 if (!vlandev)
469 continue;
471 flgs = vlandev->flags;
472 if (!(flgs & IFF_UP))
473 continue;
475 vlan_sync_address(dev, vlandev);
477 break;
479 case NETDEV_CHANGEMTU:
480 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
481 vlandev = vlan_group_get_device(grp, i);
482 if (!vlandev)
483 continue;
485 if (vlandev->mtu <= dev->mtu)
486 continue;
488 dev_set_mtu(vlandev, dev->mtu);
490 break;
492 case NETDEV_FEAT_CHANGE:
493 /* Propagate device features to underlying device */
494 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
495 vlandev = vlan_group_get_device(grp, i);
496 if (!vlandev)
497 continue;
499 vlan_transfer_features(dev, vlandev);
502 break;
504 case NETDEV_DOWN:
505 /* Put all VLANs for this dev in the down state too. */
506 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
507 vlandev = vlan_group_get_device(grp, i);
508 if (!vlandev)
509 continue;
511 flgs = vlandev->flags;
512 if (!(flgs & IFF_UP))
513 continue;
515 vlan = vlan_dev_info(vlandev);
516 if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
517 dev_change_flags(vlandev, flgs & ~IFF_UP);
518 netif_stacked_transfer_operstate(dev, vlandev);
520 break;
522 case NETDEV_UP:
523 /* Put all VLANs for this dev in the up state too. */
524 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
525 vlandev = vlan_group_get_device(grp, i);
526 if (!vlandev)
527 continue;
529 flgs = vlandev->flags;
530 if (flgs & IFF_UP)
531 continue;
533 vlan = vlan_dev_info(vlandev);
534 if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
535 dev_change_flags(vlandev, flgs | IFF_UP);
536 netif_stacked_transfer_operstate(dev, vlandev);
538 break;
540 case NETDEV_UNREGISTER:
541 /* Delete all VLANs for this dev. */
542 grp->killall = 1;
544 for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
545 vlandev = vlan_group_get_device(grp, i);
546 if (!vlandev)
547 continue;
549 /* unregistration of last vlan destroys group, abort
550 * afterwards */
551 if (grp->nr_vlans == 1)
552 i = VLAN_GROUP_ARRAY_LEN;
554 unregister_vlan_dev(vlandev, &list);
556 unregister_netdevice_many(&list);
557 break;
559 case NETDEV_PRE_TYPE_CHANGE:
560 /* Forbid underlaying device to change its type. */
561 return NOTIFY_BAD;
564 out:
565 return NOTIFY_DONE;
568 static struct notifier_block vlan_notifier_block __read_mostly = {
569 .notifier_call = vlan_device_event,
573 * VLAN IOCTL handler.
574 * o execute requested action or pass command to the device driver
575 * arg is really a struct vlan_ioctl_args __user *.
577 static int vlan_ioctl_handler(struct net *net, void __user *arg)
579 int err;
580 struct vlan_ioctl_args args;
581 struct net_device *dev = NULL;
583 if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
584 return -EFAULT;
586 /* Null terminate this sucker, just in case. */
587 args.device1[23] = 0;
588 args.u.device2[23] = 0;
590 rtnl_lock();
592 switch (args.cmd) {
593 case SET_VLAN_INGRESS_PRIORITY_CMD:
594 case SET_VLAN_EGRESS_PRIORITY_CMD:
595 case SET_VLAN_FLAG_CMD:
596 case ADD_VLAN_CMD:
597 case DEL_VLAN_CMD:
598 case GET_VLAN_REALDEV_NAME_CMD:
599 case GET_VLAN_VID_CMD:
600 err = -ENODEV;
601 dev = __dev_get_by_name(net, args.device1);
602 if (!dev)
603 goto out;
605 err = -EINVAL;
606 if (args.cmd != ADD_VLAN_CMD && !is_vlan_dev(dev))
607 goto out;
610 switch (args.cmd) {
611 case SET_VLAN_INGRESS_PRIORITY_CMD:
612 err = -EPERM;
613 if (!capable(CAP_NET_ADMIN))
614 break;
615 vlan_dev_set_ingress_priority(dev,
616 args.u.skb_priority,
617 args.vlan_qos);
618 err = 0;
619 break;
621 case SET_VLAN_EGRESS_PRIORITY_CMD:
622 err = -EPERM;
623 if (!capable(CAP_NET_ADMIN))
624 break;
625 err = vlan_dev_set_egress_priority(dev,
626 args.u.skb_priority,
627 args.vlan_qos);
628 break;
630 case SET_VLAN_FLAG_CMD:
631 err = -EPERM;
632 if (!capable(CAP_NET_ADMIN))
633 break;
634 err = vlan_dev_change_flags(dev,
635 args.vlan_qos ? args.u.flag : 0,
636 args.u.flag);
637 break;
639 case SET_VLAN_NAME_TYPE_CMD:
640 err = -EPERM;
641 if (!capable(CAP_NET_ADMIN))
642 break;
643 if ((args.u.name_type >= 0) &&
644 (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
645 struct vlan_net *vn;
647 vn = net_generic(net, vlan_net_id);
648 vn->name_type = args.u.name_type;
649 err = 0;
650 } else {
651 err = -EINVAL;
653 break;
655 case ADD_VLAN_CMD:
656 err = -EPERM;
657 if (!capable(CAP_NET_ADMIN))
658 break;
659 err = register_vlan_device(dev, args.u.VID);
660 break;
662 case DEL_VLAN_CMD:
663 err = -EPERM;
664 if (!capable(CAP_NET_ADMIN))
665 break;
666 unregister_vlan_dev(dev, NULL);
667 err = 0;
668 break;
670 case GET_VLAN_REALDEV_NAME_CMD:
671 err = 0;
672 vlan_dev_get_realdev_name(dev, args.u.device2);
673 if (copy_to_user(arg, &args,
674 sizeof(struct vlan_ioctl_args)))
675 err = -EFAULT;
676 break;
678 case GET_VLAN_VID_CMD:
679 err = 0;
680 args.u.VID = vlan_dev_vlan_id(dev);
681 if (copy_to_user(arg, &args,
682 sizeof(struct vlan_ioctl_args)))
683 err = -EFAULT;
684 break;
686 default:
687 err = -EOPNOTSUPP;
688 break;
690 out:
691 rtnl_unlock();
692 return err;
695 static int __net_init vlan_init_net(struct net *net)
697 struct vlan_net *vn = net_generic(net, vlan_net_id);
698 int err;
700 vn->name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
702 err = vlan_proc_init(net);
704 return err;
707 static void __net_exit vlan_exit_net(struct net *net)
709 vlan_proc_cleanup(net);
712 static struct pernet_operations vlan_net_ops = {
713 .init = vlan_init_net,
714 .exit = vlan_exit_net,
715 .id = &vlan_net_id,
716 .size = sizeof(struct vlan_net),
719 static int __init vlan_proto_init(void)
721 int err;
723 pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright);
724 pr_info("All bugs added by %s\n", vlan_buggyright);
726 err = register_pernet_subsys(&vlan_net_ops);
727 if (err < 0)
728 goto err0;
730 err = register_netdevice_notifier(&vlan_notifier_block);
731 if (err < 0)
732 goto err2;
734 err = vlan_gvrp_init();
735 if (err < 0)
736 goto err3;
738 err = vlan_netlink_init();
739 if (err < 0)
740 goto err4;
742 dev_add_pack(&vlan_packet_type);
743 vlan_ioctl_set(vlan_ioctl_handler);
744 return 0;
746 err4:
747 vlan_gvrp_uninit();
748 err3:
749 unregister_netdevice_notifier(&vlan_notifier_block);
750 err2:
751 unregister_pernet_subsys(&vlan_net_ops);
752 err0:
753 return err;
756 static void __exit vlan_cleanup_module(void)
758 unsigned int i;
760 vlan_ioctl_set(NULL);
761 vlan_netlink_fini();
763 unregister_netdevice_notifier(&vlan_notifier_block);
765 dev_remove_pack(&vlan_packet_type);
767 /* This table must be empty if there are no module references left. */
768 for (i = 0; i < VLAN_GRP_HASH_SIZE; i++)
769 BUG_ON(!hlist_empty(&vlan_group_hash[i]));
771 unregister_pernet_subsys(&vlan_net_ops);
772 rcu_barrier(); /* Wait for completion of call_rcu()'s */
774 vlan_gvrp_uninit();
777 module_init(vlan_proto_init);
778 module_exit(vlan_cleanup_module);
780 MODULE_LICENSE("GPL");
781 MODULE_VERSION(DRV_VERSION);