vlan.c 16 KB

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