vlan.c 17 KB

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