vlan.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  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: netdev@vger.kernel.org
  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. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  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>
  36. #include <linux/if_vlan.h>
  37. #include "vlan.h"
  38. #include "vlanproc.h"
  39. #define DRV_VERSION "1.8"
  40. /* Global VLAN variables */
  41. int vlan_net_id __read_mostly;
  42. const char vlan_fullname[] = "802.1Q VLAN Support";
  43. const char vlan_version[] = DRV_VERSION;
  44. /* End of global variables definitions. */
  45. static int vlan_group_prealloc_vid(struct vlan_group *vg, u16 vlan_id)
  46. {
  47. struct net_device **array;
  48. unsigned int size;
  49. ASSERT_RTNL();
  50. array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
  51. if (array != NULL)
  52. return 0;
  53. size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
  54. array = kzalloc(size, GFP_KERNEL);
  55. if (array == NULL)
  56. return -ENOBUFS;
  57. vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN] = array;
  58. return 0;
  59. }
  60. void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
  61. {
  62. struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
  63. struct net_device *real_dev = vlan->real_dev;
  64. struct vlan_info *vlan_info;
  65. struct vlan_group *grp;
  66. u16 vlan_id = vlan->vlan_id;
  67. ASSERT_RTNL();
  68. vlan_info = rtnl_dereference(real_dev->vlan_info);
  69. BUG_ON(!vlan_info);
  70. grp = &vlan_info->grp;
  71. /* Take it out of our own structures, but be sure to interlock with
  72. * HW accelerating devices or SW vlan input packet processing if
  73. * VLAN is not 0 (leave it there for 802.1p).
  74. */
  75. if (vlan_id)
  76. vlan_vid_del(real_dev, vlan_id);
  77. grp->nr_vlan_devs--;
  78. if (vlan->flags & VLAN_FLAG_GVRP)
  79. vlan_gvrp_request_leave(dev);
  80. vlan_group_set_device(grp, vlan_id, NULL);
  81. /* Because unregister_netdevice_queue() makes sure at least one rcu
  82. * grace period is respected before device freeing,
  83. * we dont need to call synchronize_net() here.
  84. */
  85. unregister_netdevice_queue(dev, head);
  86. if (grp->nr_vlan_devs == 0)
  87. vlan_gvrp_uninit_applicant(real_dev);
  88. /* Get rid of the vlan's reference to real_dev */
  89. dev_put(real_dev);
  90. }
  91. int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
  92. {
  93. const char *name = real_dev->name;
  94. const struct net_device_ops *ops = real_dev->netdev_ops;
  95. if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
  96. pr_info("VLANs not supported on %s\n", name);
  97. return -EOPNOTSUPP;
  98. }
  99. if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
  100. (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
  101. pr_info("Device %s has buggy VLAN hw accel\n", name);
  102. return -EOPNOTSUPP;
  103. }
  104. if (vlan_find_dev(real_dev, vlan_id) != NULL)
  105. return -EEXIST;
  106. return 0;
  107. }
  108. int register_vlan_dev(struct net_device *dev)
  109. {
  110. struct vlan_dev_priv *vlan = vlan_dev_priv(dev);
  111. struct net_device *real_dev = vlan->real_dev;
  112. u16 vlan_id = vlan->vlan_id;
  113. struct vlan_info *vlan_info;
  114. struct vlan_group *grp;
  115. int err;
  116. err = vlan_vid_add(real_dev, vlan_id);
  117. if (err)
  118. return err;
  119. vlan_info = rtnl_dereference(real_dev->vlan_info);
  120. /* vlan_info should be there now. vlan_vid_add took care of it */
  121. BUG_ON(!vlan_info);
  122. grp = &vlan_info->grp;
  123. if (grp->nr_vlan_devs == 0) {
  124. err = vlan_gvrp_init_applicant(real_dev);
  125. if (err < 0)
  126. goto out_vid_del;
  127. }
  128. err = vlan_group_prealloc_vid(grp, vlan_id);
  129. if (err < 0)
  130. goto out_uninit_applicant;
  131. err = register_netdevice(dev);
  132. if (err < 0)
  133. goto out_uninit_applicant;
  134. /* Account for reference in struct vlan_dev_priv */
  135. dev_hold(real_dev);
  136. netif_stacked_transfer_operstate(real_dev, dev);
  137. linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
  138. /* So, got the sucker initialized, now lets place
  139. * it into our local structure.
  140. */
  141. vlan_group_set_device(grp, vlan_id, dev);
  142. grp->nr_vlan_devs++;
  143. return 0;
  144. out_uninit_applicant:
  145. if (grp->nr_vlan_devs == 0)
  146. vlan_gvrp_uninit_applicant(real_dev);
  147. out_vid_del:
  148. vlan_vid_del(real_dev, vlan_id);
  149. return err;
  150. }
  151. /* Attach a VLAN device to a mac address (ie Ethernet Card).
  152. * Returns 0 if the device was created or a negative error code otherwise.
  153. */
  154. static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
  155. {
  156. struct net_device *new_dev;
  157. struct net *net = dev_net(real_dev);
  158. struct vlan_net *vn = net_generic(net, vlan_net_id);
  159. char name[IFNAMSIZ];
  160. int err;
  161. if (vlan_id >= VLAN_VID_MASK)
  162. return -ERANGE;
  163. err = vlan_check_real_dev(real_dev, vlan_id);
  164. if (err < 0)
  165. return err;
  166. /* Gotta set up the fields for the device. */
  167. switch (vn->name_type) {
  168. case VLAN_NAME_TYPE_RAW_PLUS_VID:
  169. /* name will look like: eth1.0005 */
  170. snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
  171. break;
  172. case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
  173. /* Put our vlan.VID in the name.
  174. * Name will look like: vlan5
  175. */
  176. snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
  177. break;
  178. case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
  179. /* Put our vlan.VID in the name.
  180. * Name will look like: eth0.5
  181. */
  182. snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
  183. break;
  184. case VLAN_NAME_TYPE_PLUS_VID:
  185. /* Put our vlan.VID in the name.
  186. * Name will look like: vlan0005
  187. */
  188. default:
  189. snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
  190. }
  191. new_dev = alloc_netdev(sizeof(struct vlan_dev_priv), name, vlan_setup);
  192. if (new_dev == NULL)
  193. return -ENOBUFS;
  194. dev_net_set(new_dev, net);
  195. /* need 4 bytes for extra VLAN header info,
  196. * hope the underlying device can handle it.
  197. */
  198. new_dev->mtu = real_dev->mtu;
  199. new_dev->priv_flags |= (real_dev->priv_flags & IFF_UNICAST_FLT);
  200. vlan_dev_priv(new_dev)->vlan_id = vlan_id;
  201. vlan_dev_priv(new_dev)->real_dev = real_dev;
  202. vlan_dev_priv(new_dev)->dent = NULL;
  203. vlan_dev_priv(new_dev)->flags = VLAN_FLAG_REORDER_HDR;
  204. new_dev->rtnl_link_ops = &vlan_link_ops;
  205. err = register_vlan_dev(new_dev);
  206. if (err < 0)
  207. goto out_free_newdev;
  208. return 0;
  209. out_free_newdev:
  210. free_netdev(new_dev);
  211. return err;
  212. }
  213. static void vlan_sync_address(struct net_device *dev,
  214. struct net_device *vlandev)
  215. {
  216. struct vlan_dev_priv *vlan = vlan_dev_priv(vlandev);
  217. /* May be called without an actual change */
  218. if (ether_addr_equal(vlan->real_dev_addr, dev->dev_addr))
  219. return;
  220. /* vlan address was different from the old address and is equal to
  221. * the new address */
  222. if (!ether_addr_equal(vlandev->dev_addr, vlan->real_dev_addr) &&
  223. ether_addr_equal(vlandev->dev_addr, dev->dev_addr))
  224. dev_uc_del(dev, vlandev->dev_addr);
  225. /* vlan address was equal to the old address and is different from
  226. * the new address */
  227. if (ether_addr_equal(vlandev->dev_addr, vlan->real_dev_addr) &&
  228. !ether_addr_equal(vlandev->dev_addr, dev->dev_addr))
  229. dev_uc_add(dev, vlandev->dev_addr);
  230. memcpy(vlan->real_dev_addr, dev->dev_addr, ETH_ALEN);
  231. }
  232. static void vlan_transfer_features(struct net_device *dev,
  233. struct net_device *vlandev)
  234. {
  235. vlandev->gso_max_size = dev->gso_max_size;
  236. if (dev->features & NETIF_F_HW_VLAN_TX)
  237. vlandev->hard_header_len = dev->hard_header_len;
  238. else
  239. vlandev->hard_header_len = dev->hard_header_len + VLAN_HLEN;
  240. #if IS_ENABLED(CONFIG_FCOE)
  241. vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid;
  242. #endif
  243. netdev_update_features(vlandev);
  244. }
  245. static void __vlan_device_event(struct net_device *dev, unsigned long event)
  246. {
  247. switch (event) {
  248. case NETDEV_CHANGENAME:
  249. vlan_proc_rem_dev(dev);
  250. if (vlan_proc_add_dev(dev) < 0)
  251. pr_warn("failed to change proc name for %s\n",
  252. dev->name);
  253. break;
  254. case NETDEV_REGISTER:
  255. if (vlan_proc_add_dev(dev) < 0)
  256. pr_warn("failed to add proc entry for %s\n", dev->name);
  257. break;
  258. case NETDEV_UNREGISTER:
  259. vlan_proc_rem_dev(dev);
  260. break;
  261. }
  262. }
  263. static int vlan_device_event(struct notifier_block *unused, unsigned long event,
  264. void *ptr)
  265. {
  266. struct net_device *dev = ptr;
  267. struct vlan_group *grp;
  268. struct vlan_info *vlan_info;
  269. int i, flgs;
  270. struct net_device *vlandev;
  271. struct vlan_dev_priv *vlan;
  272. LIST_HEAD(list);
  273. if (is_vlan_dev(dev))
  274. __vlan_device_event(dev, event);
  275. if ((event == NETDEV_UP) &&
  276. (dev->features & NETIF_F_HW_VLAN_FILTER)) {
  277. pr_info("adding VLAN 0 to HW filter on device %s\n",
  278. dev->name);
  279. vlan_vid_add(dev, 0);
  280. }
  281. vlan_info = rtnl_dereference(dev->vlan_info);
  282. if (!vlan_info)
  283. goto out;
  284. grp = &vlan_info->grp;
  285. /* It is OK that we do not hold the group lock right now,
  286. * as we run under the RTNL lock.
  287. */
  288. switch (event) {
  289. case NETDEV_CHANGE:
  290. /* Propagate real device state to vlan devices */
  291. for (i = 0; i < VLAN_N_VID; i++) {
  292. vlandev = vlan_group_get_device(grp, i);
  293. if (!vlandev)
  294. continue;
  295. netif_stacked_transfer_operstate(dev, vlandev);
  296. }
  297. break;
  298. case NETDEV_CHANGEADDR:
  299. /* Adjust unicast filters on underlying device */
  300. for (i = 0; i < VLAN_N_VID; i++) {
  301. vlandev = vlan_group_get_device(grp, i);
  302. if (!vlandev)
  303. continue;
  304. flgs = vlandev->flags;
  305. if (!(flgs & IFF_UP))
  306. continue;
  307. vlan_sync_address(dev, vlandev);
  308. }
  309. break;
  310. case NETDEV_CHANGEMTU:
  311. for (i = 0; i < VLAN_N_VID; i++) {
  312. vlandev = vlan_group_get_device(grp, i);
  313. if (!vlandev)
  314. continue;
  315. if (vlandev->mtu <= dev->mtu)
  316. continue;
  317. dev_set_mtu(vlandev, dev->mtu);
  318. }
  319. break;
  320. case NETDEV_FEAT_CHANGE:
  321. /* Propagate device features to underlying device */
  322. for (i = 0; i < VLAN_N_VID; i++) {
  323. vlandev = vlan_group_get_device(grp, i);
  324. if (!vlandev)
  325. continue;
  326. vlan_transfer_features(dev, vlandev);
  327. }
  328. break;
  329. case NETDEV_DOWN:
  330. if (dev->features & NETIF_F_HW_VLAN_FILTER)
  331. vlan_vid_del(dev, 0);
  332. /* Put all VLANs for this dev in the down state too. */
  333. for (i = 0; i < VLAN_N_VID; i++) {
  334. vlandev = vlan_group_get_device(grp, i);
  335. if (!vlandev)
  336. continue;
  337. flgs = vlandev->flags;
  338. if (!(flgs & IFF_UP))
  339. continue;
  340. vlan = vlan_dev_priv(vlandev);
  341. if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
  342. dev_change_flags(vlandev, flgs & ~IFF_UP);
  343. netif_stacked_transfer_operstate(dev, vlandev);
  344. }
  345. break;
  346. case NETDEV_UP:
  347. /* Put all VLANs for this dev in the up state too. */
  348. for (i = 0; i < VLAN_N_VID; i++) {
  349. vlandev = vlan_group_get_device(grp, i);
  350. if (!vlandev)
  351. continue;
  352. flgs = vlandev->flags;
  353. if (flgs & IFF_UP)
  354. continue;
  355. vlan = vlan_dev_priv(vlandev);
  356. if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
  357. dev_change_flags(vlandev, flgs | IFF_UP);
  358. netif_stacked_transfer_operstate(dev, vlandev);
  359. }
  360. break;
  361. case NETDEV_UNREGISTER:
  362. /* twiddle thumbs on netns device moves */
  363. if (dev->reg_state != NETREG_UNREGISTERING)
  364. break;
  365. for (i = 0; i < VLAN_N_VID; i++) {
  366. vlandev = vlan_group_get_device(grp, i);
  367. if (!vlandev)
  368. continue;
  369. /* removal of last vid destroys vlan_info, abort
  370. * afterwards */
  371. if (vlan_info->nr_vids == 1)
  372. i = VLAN_N_VID;
  373. unregister_vlan_dev(vlandev, &list);
  374. }
  375. unregister_netdevice_many(&list);
  376. break;
  377. case NETDEV_PRE_TYPE_CHANGE:
  378. /* Forbid underlaying device to change its type. */
  379. if (vlan_uses_dev(dev))
  380. return NOTIFY_BAD;
  381. break;
  382. case NETDEV_NOTIFY_PEERS:
  383. case NETDEV_BONDING_FAILOVER:
  384. /* Propagate to vlan devices */
  385. for (i = 0; i < VLAN_N_VID; i++) {
  386. vlandev = vlan_group_get_device(grp, i);
  387. if (!vlandev)
  388. continue;
  389. call_netdevice_notifiers(event, vlandev);
  390. }
  391. break;
  392. }
  393. out:
  394. return NOTIFY_DONE;
  395. }
  396. static struct notifier_block vlan_notifier_block __read_mostly = {
  397. .notifier_call = vlan_device_event,
  398. };
  399. /*
  400. * VLAN IOCTL handler.
  401. * o execute requested action or pass command to the device driver
  402. * arg is really a struct vlan_ioctl_args __user *.
  403. */
  404. static int vlan_ioctl_handler(struct net *net, void __user *arg)
  405. {
  406. int err;
  407. struct vlan_ioctl_args args;
  408. struct net_device *dev = NULL;
  409. if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
  410. return -EFAULT;
  411. /* Null terminate this sucker, just in case. */
  412. args.device1[23] = 0;
  413. args.u.device2[23] = 0;
  414. rtnl_lock();
  415. switch (args.cmd) {
  416. case SET_VLAN_INGRESS_PRIORITY_CMD:
  417. case SET_VLAN_EGRESS_PRIORITY_CMD:
  418. case SET_VLAN_FLAG_CMD:
  419. case ADD_VLAN_CMD:
  420. case DEL_VLAN_CMD:
  421. case GET_VLAN_REALDEV_NAME_CMD:
  422. case GET_VLAN_VID_CMD:
  423. err = -ENODEV;
  424. dev = __dev_get_by_name(net, args.device1);
  425. if (!dev)
  426. goto out;
  427. err = -EINVAL;
  428. if (args.cmd != ADD_VLAN_CMD && !is_vlan_dev(dev))
  429. goto out;
  430. }
  431. switch (args.cmd) {
  432. case SET_VLAN_INGRESS_PRIORITY_CMD:
  433. err = -EPERM;
  434. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  435. break;
  436. vlan_dev_set_ingress_priority(dev,
  437. args.u.skb_priority,
  438. args.vlan_qos);
  439. err = 0;
  440. break;
  441. case SET_VLAN_EGRESS_PRIORITY_CMD:
  442. err = -EPERM;
  443. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  444. break;
  445. err = vlan_dev_set_egress_priority(dev,
  446. args.u.skb_priority,
  447. args.vlan_qos);
  448. break;
  449. case SET_VLAN_FLAG_CMD:
  450. err = -EPERM;
  451. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  452. break;
  453. err = vlan_dev_change_flags(dev,
  454. args.vlan_qos ? args.u.flag : 0,
  455. args.u.flag);
  456. break;
  457. case SET_VLAN_NAME_TYPE_CMD:
  458. err = -EPERM;
  459. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  460. break;
  461. if ((args.u.name_type >= 0) &&
  462. (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
  463. struct vlan_net *vn;
  464. vn = net_generic(net, vlan_net_id);
  465. vn->name_type = args.u.name_type;
  466. err = 0;
  467. } else {
  468. err = -EINVAL;
  469. }
  470. break;
  471. case ADD_VLAN_CMD:
  472. err = -EPERM;
  473. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  474. break;
  475. err = register_vlan_device(dev, args.u.VID);
  476. break;
  477. case DEL_VLAN_CMD:
  478. err = -EPERM;
  479. if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
  480. break;
  481. unregister_vlan_dev(dev, NULL);
  482. err = 0;
  483. break;
  484. case GET_VLAN_REALDEV_NAME_CMD:
  485. err = 0;
  486. vlan_dev_get_realdev_name(dev, args.u.device2);
  487. if (copy_to_user(arg, &args,
  488. sizeof(struct vlan_ioctl_args)))
  489. err = -EFAULT;
  490. break;
  491. case GET_VLAN_VID_CMD:
  492. err = 0;
  493. args.u.VID = vlan_dev_vlan_id(dev);
  494. if (copy_to_user(arg, &args,
  495. sizeof(struct vlan_ioctl_args)))
  496. err = -EFAULT;
  497. break;
  498. default:
  499. err = -EOPNOTSUPP;
  500. break;
  501. }
  502. out:
  503. rtnl_unlock();
  504. return err;
  505. }
  506. static int __net_init vlan_init_net(struct net *net)
  507. {
  508. struct vlan_net *vn = net_generic(net, vlan_net_id);
  509. int err;
  510. vn->name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
  511. err = vlan_proc_init(net);
  512. return err;
  513. }
  514. static void __net_exit vlan_exit_net(struct net *net)
  515. {
  516. vlan_proc_cleanup(net);
  517. }
  518. static struct pernet_operations vlan_net_ops = {
  519. .init = vlan_init_net,
  520. .exit = vlan_exit_net,
  521. .id = &vlan_net_id,
  522. .size = sizeof(struct vlan_net),
  523. };
  524. static int __init vlan_proto_init(void)
  525. {
  526. int err;
  527. pr_info("%s v%s\n", vlan_fullname, vlan_version);
  528. err = register_pernet_subsys(&vlan_net_ops);
  529. if (err < 0)
  530. goto err0;
  531. err = register_netdevice_notifier(&vlan_notifier_block);
  532. if (err < 0)
  533. goto err2;
  534. err = vlan_gvrp_init();
  535. if (err < 0)
  536. goto err3;
  537. err = vlan_netlink_init();
  538. if (err < 0)
  539. goto err4;
  540. vlan_ioctl_set(vlan_ioctl_handler);
  541. return 0;
  542. err4:
  543. vlan_gvrp_uninit();
  544. err3:
  545. unregister_netdevice_notifier(&vlan_notifier_block);
  546. err2:
  547. unregister_pernet_subsys(&vlan_net_ops);
  548. err0:
  549. return err;
  550. }
  551. static void __exit vlan_cleanup_module(void)
  552. {
  553. vlan_ioctl_set(NULL);
  554. vlan_netlink_fini();
  555. unregister_netdevice_notifier(&vlan_notifier_block);
  556. unregister_pernet_subsys(&vlan_net_ops);
  557. rcu_barrier(); /* Wait for completion of call_rcu()'s */
  558. vlan_gvrp_uninit();
  559. }
  560. module_init(vlan_proto_init);
  561. module_exit(vlan_cleanup_module);
  562. MODULE_LICENSE("GPL");
  563. MODULE_VERSION(DRV_VERSION);