vlan.c 17 KB

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