vlan.c 16 KB

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