vlan.c 16 KB

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