vlan.c 17 KB

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