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
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
37#include <linux/if_vlan.h>
38#include "vlan.h"
39#include "vlanproc.h"
40#ifdef HNDCTF
41#include <ctf/hndctf.h>
42#endif /* HNDCTF */
43
44#define DRV_VERSION "1.8"
45
46/* Global VLAN variables */
47
48int vlan_net_id __read_mostly;
49
50/* Our listing of VLAN group(s) */
51static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE];
52
53const char vlan_fullname[] = "802.1Q VLAN Support";
54const char vlan_version[] = DRV_VERSION;
55static const char vlan_copyright[] = "Ben Greear <greearb@candelatech.com>";
56static const char vlan_buggyright[] = "David S. Miller <davem@redhat.com>";
57
58static struct packet_type vlan_packet_type __read_mostly = {
59	.type = cpu_to_be16(ETH_P_8021Q),
60	.func = vlan_skb_recv, /* VLAN receive method */
61};
62
63/* End of global variables definitions. */
64
65static inline unsigned int vlan_grp_hashfn(unsigned int idx)
66{
67	return ((idx >> VLAN_GRP_HASH_SHIFT) ^ idx) & VLAN_GRP_HASH_MASK;
68}
69
70/* Must be invoked with RCU read lock (no preempt) */
71static struct vlan_group *__vlan_find_group(struct net_device *real_dev)
72{
73	struct vlan_group *grp;
74	struct hlist_node *n;
75	int hash = vlan_grp_hashfn(real_dev->ifindex);
76
77	hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) {
78		if (grp->real_dev == real_dev)
79			return grp;
80	}
81
82	return NULL;
83}
84
85/*  Find the protocol handler.  Assumes VID < VLAN_VID_MASK.
86 *
87 * Must be invoked with RCU read lock (no preempt)
88 */
89struct net_device *__find_vlan_dev(struct net_device *real_dev, u16 vlan_id)
90{
91	struct vlan_group *grp = __vlan_find_group(real_dev);
92
93	if (grp)
94		return vlan_group_get_device(grp, vlan_id);
95
96	return NULL;
97}
98
99static void vlan_group_free(struct vlan_group *grp)
100{
101	int i;
102
103	for (i = 0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++)
104		kfree(grp->vlan_devices_arrays[i]);
105	kfree(grp);
106}
107
108static struct vlan_group *vlan_group_alloc(struct net_device *real_dev)
109{
110	struct vlan_group *grp;
111
112	grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL);
113	if (!grp)
114		return NULL;
115
116	grp->real_dev = real_dev;
117	hlist_add_head_rcu(&grp->hlist,
118			&vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]);
119	return grp;
120}
121
122static int vlan_group_prealloc_vid(struct vlan_group *vg, u16 vlan_id)
123{
124	struct net_device **array;
125	unsigned int size;
126
127	ASSERT_RTNL();
128
129	array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
130	if (array != NULL)
131		return 0;
132
133	size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN;
134	array = kzalloc(size, GFP_KERNEL);
135	if (array == NULL)
136		return -ENOBUFS;
137
138	vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN] = array;
139	return 0;
140}
141
142static void vlan_rcu_free(struct rcu_head *rcu)
143{
144	vlan_group_free(container_of(rcu, struct vlan_group, rcu));
145}
146
147void unregister_vlan_dev(struct net_device *dev, struct list_head *head)
148{
149	struct vlan_dev_info *vlan = vlan_dev_info(dev);
150	struct net_device *real_dev = vlan->real_dev;
151	const struct net_device_ops *ops = real_dev->netdev_ops;
152	struct vlan_group *grp;
153	u16 vlan_id = vlan->vlan_id;
154
155	ASSERT_RTNL();
156
157	grp = __vlan_find_group(real_dev);
158	BUG_ON(!grp);
159
160	/* Take it out of our own structures, but be sure to interlock with
161	 * HW accelerating devices or SW vlan input packet processing if
162	 * VLAN is not 0 (leave it there for 802.1p).
163	 */
164	if (vlan_id && (real_dev->features & NETIF_F_HW_VLAN_FILTER))
165		ops->ndo_vlan_rx_kill_vid(real_dev, vlan_id);
166
167	grp->nr_vlans--;
168
169	vlan_group_set_device(grp, vlan_id, NULL);
170	if (!grp->killall)
171		synchronize_net();
172
173#ifdef HNDCTF
174	(void)ctf_dev_vlan_delete(kcih, real_dev, vlan_id);
175#endif /* HNDCTF */
176
177	unregister_netdevice_queue(dev, head);
178
179	/* If the group is now empty, kill off the group. */
180	if (grp->nr_vlans == 0) {
181		vlan_gvrp_uninit_applicant(real_dev);
182
183		if (real_dev->features & NETIF_F_HW_VLAN_RX)
184			ops->ndo_vlan_rx_register(real_dev, NULL);
185
186		hlist_del_rcu(&grp->hlist);
187
188		/* Free the group, after all cpu's are done. */
189		call_rcu(&grp->rcu, vlan_rcu_free);
190	}
191
192	/* Get rid of the vlan's reference to real_dev */
193	dev_put(real_dev);
194}
195
196int vlan_check_real_dev(struct net_device *real_dev, u16 vlan_id)
197{
198	const char *name = real_dev->name;
199	const struct net_device_ops *ops = real_dev->netdev_ops;
200
201	if (real_dev->features & NETIF_F_VLAN_CHALLENGED) {
202		pr_info("8021q: VLANs not supported on %s\n", name);
203		return -EOPNOTSUPP;
204	}
205
206	if ((real_dev->features & NETIF_F_HW_VLAN_RX) && !ops->ndo_vlan_rx_register) {
207		pr_info("8021q: device %s has buggy VLAN hw accel\n", name);
208		return -EOPNOTSUPP;
209	}
210
211	if ((real_dev->features & NETIF_F_HW_VLAN_FILTER) &&
212	    (!ops->ndo_vlan_rx_add_vid || !ops->ndo_vlan_rx_kill_vid)) {
213		pr_info("8021q: Device %s has buggy VLAN hw accel\n", name);
214		return -EOPNOTSUPP;
215	}
216
217	if (__find_vlan_dev(real_dev, vlan_id) != NULL)
218		return -EEXIST;
219
220	return 0;
221}
222
223int register_vlan_dev(struct net_device *dev)
224{
225	struct vlan_dev_info *vlan = vlan_dev_info(dev);
226	struct net_device *real_dev = vlan->real_dev;
227	const struct net_device_ops *ops = real_dev->netdev_ops;
228	u16 vlan_id = vlan->vlan_id;
229	struct vlan_group *grp, *ngrp = NULL;
230	int err;
231
232	grp = __vlan_find_group(real_dev);
233	if (!grp) {
234		ngrp = grp = vlan_group_alloc(real_dev);
235		if (!grp)
236			return -ENOBUFS;
237		err = vlan_gvrp_init_applicant(real_dev);
238		if (err < 0)
239			goto out_free_group;
240	}
241
242	err = vlan_group_prealloc_vid(grp, vlan_id);
243	if (err < 0)
244		goto out_uninit_applicant;
245
246	err = register_netdevice(dev);
247	if (err < 0)
248		goto out_uninit_applicant;
249
250	/* Account for reference in struct vlan_dev_info */
251	dev_hold(real_dev);
252
253	netif_stacked_transfer_operstate(real_dev, dev);
254	linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
255
256	/* So, got the sucker initialized, now lets place
257	 * it into our local structure.
258	 */
259	vlan_group_set_device(grp, vlan_id, dev);
260	grp->nr_vlans++;
261
262	dev->features |= (real_dev->features & (NETIF_F_SG | NETIF_F_FRAGLIST | NETIF_F_ALL_CSUM));
263
264	if (ngrp && real_dev->features & NETIF_F_HW_VLAN_RX)
265		ops->ndo_vlan_rx_register(real_dev, ngrp);
266	if (real_dev->features & NETIF_F_HW_VLAN_FILTER)
267		ops->ndo_vlan_rx_add_vid(real_dev, vlan_id);
268
269	return 0;
270
271out_uninit_applicant:
272	if (ngrp)
273		vlan_gvrp_uninit_applicant(real_dev);
274out_free_group:
275	if (ngrp) {
276		hlist_del_rcu(&ngrp->hlist);
277		/* Free the group, after all cpu's are done. */
278		call_rcu(&ngrp->rcu, vlan_rcu_free);
279	}
280	return err;
281}
282
283/*  Attach a VLAN device to a mac address (ie Ethernet Card).
284 *  Returns 0 if the device was created or a negative error code otherwise.
285 */
286static int register_vlan_device(struct net_device *real_dev, u16 vlan_id)
287{
288	struct net_device *new_dev;
289	struct net *net = dev_net(real_dev);
290	struct vlan_net *vn = net_generic(net, vlan_net_id);
291	char name[IFNAMSIZ];
292	int err;
293
294	if (vlan_id >= VLAN_VID_MASK)
295		return -ERANGE;
296
297	err = vlan_check_real_dev(real_dev, vlan_id);
298	if (err < 0)
299		return err;
300
301	/* Gotta set up the fields for the device. */
302	switch (vn->name_type) {
303	case VLAN_NAME_TYPE_RAW_PLUS_VID:
304		/* name will look like:	 eth1.0005 */
305		snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, vlan_id);
306		break;
307	case VLAN_NAME_TYPE_PLUS_VID_NO_PAD:
308		/* Put our vlan.VID in the name.
309		 * Name will look like:	 vlan5
310		 */
311		snprintf(name, IFNAMSIZ, "vlan%i", vlan_id);
312		break;
313	case VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD:
314		/* Put our vlan.VID in the name.
315		 * Name will look like:	 eth0.5
316		 */
317		snprintf(name, IFNAMSIZ, "%s.%i", real_dev->name, vlan_id);
318		break;
319	case VLAN_NAME_TYPE_PLUS_VID:
320		/* Put our vlan.VID in the name.
321		 * Name will look like:	 vlan0005
322		 */
323	default:
324		snprintf(name, IFNAMSIZ, "vlan%.4i", vlan_id);
325	}
326
327	new_dev = alloc_netdev_mq(sizeof(struct vlan_dev_info), name,
328				  vlan_setup, real_dev->num_tx_queues);
329
330	if (new_dev == NULL)
331		return -ENOBUFS;
332
333	new_dev->real_num_tx_queues = real_dev->real_num_tx_queues;
334	dev_net_set(new_dev, net);
335	/* need 4 bytes for extra VLAN header info,
336	 * hope the underlying device can handle it.
337	 */
338	new_dev->mtu = real_dev->mtu;
339
340	vlan_dev_info(new_dev)->vlan_id = vlan_id;
341	vlan_dev_info(new_dev)->real_dev = real_dev;
342	vlan_dev_info(new_dev)->dent = NULL;
343	vlan_dev_info(new_dev)->flags = VLAN_FLAG_REORDER_HDR;
344
345	new_dev->rtnl_link_ops = &vlan_link_ops;
346	err = register_vlan_dev(new_dev);
347	if (err < 0)
348		goto out_free_newdev;
349
350#ifdef HNDCTF
351	(void)ctf_dev_vlan_add(kcih, real_dev, vlan_id, new_dev);
352#endif /* HNDCTF */
353
354	return 0;
355
356out_free_newdev:
357	free_netdev(new_dev);
358	return err;
359}
360
361static void vlan_sync_address(struct net_device *dev,
362			      struct net_device *vlandev)
363{
364	struct vlan_dev_info *vlan = vlan_dev_info(vlandev);
365
366	/* May be called without an actual change */
367	if (!compare_ether_addr(vlan->real_dev_addr, dev->dev_addr))
368		return;
369
370	/* vlan address was different from the old address and is equal to
371	 * the new address */
372	if (compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) &&
373	    !compare_ether_addr(vlandev->dev_addr, dev->dev_addr))
374		dev_uc_del(dev, vlandev->dev_addr);
375
376	/* vlan address was equal to the old address and is different from
377	 * the new address */
378	if (!compare_ether_addr(vlandev->dev_addr, vlan->real_dev_addr) &&
379	    compare_ether_addr(vlandev->dev_addr, dev->dev_addr))
380		dev_uc_add(dev, vlandev->dev_addr);
381
382	memcpy(vlan->real_dev_addr, dev->dev_addr, ETH_ALEN);
383}
384
385static void vlan_transfer_features(struct net_device *dev,
386				   struct net_device *vlandev)
387{
388	unsigned long old_features = vlandev->features;
389
390	vlandev->features &= ~dev->vlan_features;
391	vlandev->features |= dev->features & dev->vlan_features;
392	vlandev->gso_max_size = dev->gso_max_size;
393#if defined(CONFIG_FCOE) || defined(CONFIG_FCOE_MODULE)
394	vlandev->fcoe_ddp_xid = dev->fcoe_ddp_xid;
395#endif
396	vlandev->real_num_tx_queues = dev->real_num_tx_queues;
397	BUG_ON(vlandev->real_num_tx_queues > vlandev->num_tx_queues);
398
399	if (old_features != vlandev->features)
400		netdev_features_change(vlandev);
401}
402
403static void __vlan_device_event(struct net_device *dev, unsigned long event)
404{
405	switch (event) {
406	case NETDEV_CHANGENAME:
407		vlan_proc_rem_dev(dev);
408		if (vlan_proc_add_dev(dev) < 0)
409			pr_warning("8021q: failed to change proc name for %s\n",
410					dev->name);
411		break;
412	case NETDEV_REGISTER:
413		if (vlan_proc_add_dev(dev) < 0)
414			pr_warning("8021q: failed to add proc entry for %s\n",
415					dev->name);
416		break;
417	case NETDEV_UNREGISTER:
418		vlan_proc_rem_dev(dev);
419		break;
420	}
421}
422
423static int vlan_device_event(struct notifier_block *unused, unsigned long event,
424			     void *ptr)
425{
426	struct net_device *dev = ptr;
427	struct vlan_group *grp;
428	int i, flgs;
429	struct net_device *vlandev;
430	struct vlan_dev_info *vlan;
431	LIST_HEAD(list);
432
433	if (is_vlan_dev(dev))
434		__vlan_device_event(dev, event);
435
436	if ((event == NETDEV_UP) &&
437	    (dev->features & NETIF_F_HW_VLAN_FILTER) &&
438	    dev->netdev_ops->ndo_vlan_rx_add_vid) {
439		pr_info("8021q: adding VLAN 0 to HW filter on device %s\n",
440			dev->name);
441		dev->netdev_ops->ndo_vlan_rx_add_vid(dev, 0);
442	}
443
444	grp = __vlan_find_group(dev);
445	if (!grp)
446		goto out;
447
448	/* It is OK that we do not hold the group lock right now,
449	 * as we run under the RTNL lock.
450	 */
451
452	switch (event) {
453	case NETDEV_CHANGE:
454		/* Propagate real device state to vlan devices */
455		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
456			vlandev = vlan_group_get_device(grp, i);
457			if (!vlandev)
458				continue;
459
460			netif_stacked_transfer_operstate(dev, vlandev);
461		}
462		break;
463
464	case NETDEV_CHANGEADDR:
465		/* Adjust unicast filters on underlying device */
466		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
467			vlandev = vlan_group_get_device(grp, i);
468			if (!vlandev)
469				continue;
470
471			flgs = vlandev->flags;
472			if (!(flgs & IFF_UP))
473				continue;
474
475			vlan_sync_address(dev, vlandev);
476		}
477		break;
478
479	case NETDEV_CHANGEMTU:
480		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
481			vlandev = vlan_group_get_device(grp, i);
482			if (!vlandev)
483				continue;
484
485			if (vlandev->mtu <= dev->mtu)
486				continue;
487
488			dev_set_mtu(vlandev, dev->mtu);
489		}
490		break;
491
492	case NETDEV_FEAT_CHANGE:
493		/* Propagate device features to underlying device */
494		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
495			vlandev = vlan_group_get_device(grp, i);
496			if (!vlandev)
497				continue;
498
499			vlan_transfer_features(dev, vlandev);
500		}
501
502		break;
503
504	case NETDEV_DOWN:
505		/* Put all VLANs for this dev in the down state too.  */
506		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
507			vlandev = vlan_group_get_device(grp, i);
508			if (!vlandev)
509				continue;
510
511			flgs = vlandev->flags;
512			if (!(flgs & IFF_UP))
513				continue;
514
515			vlan = vlan_dev_info(vlandev);
516			if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
517				dev_change_flags(vlandev, flgs & ~IFF_UP);
518			netif_stacked_transfer_operstate(dev, vlandev);
519		}
520		break;
521
522	case NETDEV_UP:
523		/* Put all VLANs for this dev in the up state too.  */
524		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
525			vlandev = vlan_group_get_device(grp, i);
526			if (!vlandev)
527				continue;
528
529			flgs = vlandev->flags;
530			if (flgs & IFF_UP)
531				continue;
532
533			vlan = vlan_dev_info(vlandev);
534			if (!(vlan->flags & VLAN_FLAG_LOOSE_BINDING))
535				dev_change_flags(vlandev, flgs | IFF_UP);
536			netif_stacked_transfer_operstate(dev, vlandev);
537		}
538		break;
539
540	case NETDEV_UNREGISTER:
541		/* Delete all VLANs for this dev. */
542		grp->killall = 1;
543
544		for (i = 0; i < VLAN_GROUP_ARRAY_LEN; i++) {
545			vlandev = vlan_group_get_device(grp, i);
546			if (!vlandev)
547				continue;
548
549			/* unregistration of last vlan destroys group, abort
550			 * afterwards */
551			if (grp->nr_vlans == 1)
552				i = VLAN_GROUP_ARRAY_LEN;
553
554			unregister_vlan_dev(vlandev, &list);
555		}
556		unregister_netdevice_many(&list);
557		break;
558
559	case NETDEV_PRE_TYPE_CHANGE:
560		/* Forbid underlaying device to change its type. */
561		return NOTIFY_BAD;
562	}
563
564out:
565	return NOTIFY_DONE;
566}
567
568static struct notifier_block vlan_notifier_block __read_mostly = {
569	.notifier_call = vlan_device_event,
570};
571
572/*
573 *	VLAN IOCTL handler.
574 *	o execute requested action or pass command to the device driver
575 *   arg is really a struct vlan_ioctl_args __user *.
576 */
577static int vlan_ioctl_handler(struct net *net, void __user *arg)
578{
579	int err;
580	struct vlan_ioctl_args args;
581	struct net_device *dev = NULL;
582
583	if (copy_from_user(&args, arg, sizeof(struct vlan_ioctl_args)))
584		return -EFAULT;
585
586	/* Null terminate this sucker, just in case. */
587	args.device1[23] = 0;
588	args.u.device2[23] = 0;
589
590	rtnl_lock();
591
592	switch (args.cmd) {
593	case SET_VLAN_INGRESS_PRIORITY_CMD:
594	case SET_VLAN_EGRESS_PRIORITY_CMD:
595	case SET_VLAN_FLAG_CMD:
596	case ADD_VLAN_CMD:
597	case DEL_VLAN_CMD:
598	case GET_VLAN_REALDEV_NAME_CMD:
599	case GET_VLAN_VID_CMD:
600		err = -ENODEV;
601		dev = __dev_get_by_name(net, args.device1);
602		if (!dev)
603			goto out;
604
605		err = -EINVAL;
606		if (args.cmd != ADD_VLAN_CMD && !is_vlan_dev(dev))
607			goto out;
608	}
609
610	switch (args.cmd) {
611	case SET_VLAN_INGRESS_PRIORITY_CMD:
612		err = -EPERM;
613		if (!capable(CAP_NET_ADMIN))
614			break;
615		vlan_dev_set_ingress_priority(dev,
616					      args.u.skb_priority,
617					      args.vlan_qos);
618		err = 0;
619		break;
620
621	case SET_VLAN_EGRESS_PRIORITY_CMD:
622		err = -EPERM;
623		if (!capable(CAP_NET_ADMIN))
624			break;
625		err = vlan_dev_set_egress_priority(dev,
626						   args.u.skb_priority,
627						   args.vlan_qos);
628		break;
629
630	case SET_VLAN_FLAG_CMD:
631		err = -EPERM;
632		if (!capable(CAP_NET_ADMIN))
633			break;
634		err = vlan_dev_change_flags(dev,
635					    args.vlan_qos ? args.u.flag : 0,
636					    args.u.flag);
637		break;
638
639	case SET_VLAN_NAME_TYPE_CMD:
640		err = -EPERM;
641		if (!capable(CAP_NET_ADMIN))
642			break;
643		if ((args.u.name_type >= 0) &&
644		    (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
645			struct vlan_net *vn;
646
647			vn = net_generic(net, vlan_net_id);
648			vn->name_type = args.u.name_type;
649			err = 0;
650		} else {
651			err = -EINVAL;
652		}
653		break;
654
655	case ADD_VLAN_CMD:
656		err = -EPERM;
657		if (!capable(CAP_NET_ADMIN))
658			break;
659		err = register_vlan_device(dev, args.u.VID);
660		break;
661
662	case DEL_VLAN_CMD:
663		err = -EPERM;
664		if (!capable(CAP_NET_ADMIN))
665			break;
666		unregister_vlan_dev(dev, NULL);
667		err = 0;
668		break;
669
670	case GET_VLAN_REALDEV_NAME_CMD:
671		err = 0;
672		vlan_dev_get_realdev_name(dev, args.u.device2);
673		if (copy_to_user(arg, &args,
674				 sizeof(struct vlan_ioctl_args)))
675			err = -EFAULT;
676		break;
677
678	case GET_VLAN_VID_CMD:
679		err = 0;
680		args.u.VID = vlan_dev_vlan_id(dev);
681		if (copy_to_user(arg, &args,
682				 sizeof(struct vlan_ioctl_args)))
683		      err = -EFAULT;
684		break;
685
686	default:
687		err = -EOPNOTSUPP;
688		break;
689	}
690out:
691	rtnl_unlock();
692	return err;
693}
694
695static int __net_init vlan_init_net(struct net *net)
696{
697	struct vlan_net *vn = net_generic(net, vlan_net_id);
698	int err;
699
700	vn->name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD;
701
702	err = vlan_proc_init(net);
703
704	return err;
705}
706
707static void __net_exit vlan_exit_net(struct net *net)
708{
709	vlan_proc_cleanup(net);
710}
711
712static struct pernet_operations vlan_net_ops = {
713	.init = vlan_init_net,
714	.exit = vlan_exit_net,
715	.id   = &vlan_net_id,
716	.size = sizeof(struct vlan_net),
717};
718
719static int __init vlan_proto_init(void)
720{
721	int err;
722
723	pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright);
724	pr_info("All bugs added by %s\n", vlan_buggyright);
725
726	err = register_pernet_subsys(&vlan_net_ops);
727	if (err < 0)
728		goto err0;
729
730	err = register_netdevice_notifier(&vlan_notifier_block);
731	if (err < 0)
732		goto err2;
733
734	err = vlan_gvrp_init();
735	if (err < 0)
736		goto err3;
737
738	err = vlan_netlink_init();
739	if (err < 0)
740		goto err4;
741
742	dev_add_pack(&vlan_packet_type);
743	vlan_ioctl_set(vlan_ioctl_handler);
744	return 0;
745
746err4:
747	vlan_gvrp_uninit();
748err3:
749	unregister_netdevice_notifier(&vlan_notifier_block);
750err2:
751	unregister_pernet_subsys(&vlan_net_ops);
752err0:
753	return err;
754}
755
756static void __exit vlan_cleanup_module(void)
757{
758	unsigned int i;
759
760	vlan_ioctl_set(NULL);
761	vlan_netlink_fini();
762
763	unregister_netdevice_notifier(&vlan_notifier_block);
764
765	dev_remove_pack(&vlan_packet_type);
766
767	/* This table must be empty if there are no module references left. */
768	for (i = 0; i < VLAN_GRP_HASH_SIZE; i++)
769		BUG_ON(!hlist_empty(&vlan_group_hash[i]));
770
771	unregister_pernet_subsys(&vlan_net_ops);
772	rcu_barrier(); /* Wait for completion of call_rcu()'s */
773
774	vlan_gvrp_uninit();
775}
776
777module_init(vlan_proto_init);
778module_exit(vlan_cleanup_module);
779
780MODULE_LICENSE("GPL");
781MODULE_VERSION(DRV_VERSION);
782