From c346dca10840a874240c78efe3f39acf4312a1f2 Mon Sep 17 00:00:00 2001 From: YOSHIFUJI Hideaki Date: Tue, 25 Mar 2008 21:47:49 +0900 Subject: [NET] NETNS: Omit net_device->nd_net without CONFIG_NET_NS. Introduce per-net_device inlines: dev_net(), dev_net_set(). Without CONFIG_NET_NS, no namespace other than &init_net exists. Let's explicitly define them to help compiler optimizations. Signed-off-by: YOSHIFUJI Hideaki --- net/8021q/vlan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'net/8021q/vlan.c') diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index dbc81b96509..c35dc230365 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -382,7 +382,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event, int i, flgs; struct net_device *vlandev; - if (dev->nd_net != &init_net) + if (dev_net(dev) != &init_net) return NOTIFY_DONE; if (!grp) -- cgit v1.2.3-70-g09d2 From 67727184f28c38d06013c6659560bb046c1d9f9c Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 26 Mar 2008 16:27:22 -0700 Subject: [VLAN]: Reduce memory consumed by vlan_groups Currently each vlan_groupd contains 8 pointers on arrays with 512 pointers on struct net_device each :) Such a construction "in many cases ... wastes memory". My proposal is to allow for some of these arrays pointers be NULL, meaning that there are no devices in it. When a new device is added to the vlan_group, the appropriate array is allocated. The check in vlan_group_get_device's is safe, since the pointer vg->vlan_devices_arrays[x] can only switch from NULL to not-NULL. The vlan_group_prealloc_vid() is guarded with rtnl lock and is also safe. I've checked (I hope that) all the places, that use these arrays and found, that the register_vlan_dev is the only place, that can put a vlan device on an empty vlan_group. Rough calculations shows, that after the patch a setup with a single vlan dev (or up to 512 vlans with sequential vids) will occupy approximately 8 times less memory. The question I have is - does this patch makes sense, or a totally new structures are required to store the vlan_devs? Signed-off-by: Pavel Emelyanov Signed-off-by: Patrick McHardy --- include/linux/if_vlan.h | 2 +- net/8021q/vlan.c | 36 +++++++++++++++++++++++------------- 2 files changed, 24 insertions(+), 14 deletions(-) (limited to 'net/8021q/vlan.c') diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index 79504b22a93..edd55af7ebd 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -93,7 +93,7 @@ static inline struct net_device *vlan_group_get_device(struct vlan_group *vg, { struct net_device **array; array = vg->vlan_devices_arrays[vlan_id / VLAN_GROUP_ARRAY_PART_LEN]; - return array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN]; + return array ? array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] : NULL; } static inline void vlan_group_set_device(struct vlan_group *vg, diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index c35dc230365..694be86e449 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -106,29 +106,35 @@ static void vlan_group_free(struct vlan_group *grp) static struct vlan_group *vlan_group_alloc(int ifindex) { struct vlan_group *grp; - unsigned int size; - unsigned int i; grp = kzalloc(sizeof(struct vlan_group), GFP_KERNEL); if (!grp) return NULL; - size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN; - - for (i = 0; i < VLAN_GROUP_ARRAY_SPLIT_PARTS; i++) { - grp->vlan_devices_arrays[i] = kzalloc(size, GFP_KERNEL); - if (!grp->vlan_devices_arrays[i]) - goto err; - } - grp->real_dev_ifindex = ifindex; hlist_add_head_rcu(&grp->hlist, &vlan_group_hash[vlan_grp_hashfn(ifindex)]); return grp; +} -err: - vlan_group_free(grp); - return NULL; +static int vlan_group_prealloc_vid(struct vlan_group *vg, int vid) +{ + struct net_device **array; + unsigned int size; + + ASSERT_RTNL(); + + array = vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN]; + if (array != NULL) + return 0; + + size = sizeof(struct net_device *) * VLAN_GROUP_ARRAY_PART_LEN; + array = kzalloc(size, GFP_KERNEL); + if (array == NULL) + return -ENOBUFS; + + vg->vlan_devices_arrays[vid / VLAN_GROUP_ARRAY_PART_LEN] = array; + return 0; } static void vlan_rcu_free(struct rcu_head *rcu) @@ -247,6 +253,10 @@ int register_vlan_dev(struct net_device *dev) return -ENOBUFS; } + err = vlan_group_prealloc_vid(grp, vlan_id); + if (err < 0) + goto out_free_group; + err = register_netdevice(dev); if (err < 0) goto out_free_group; -- cgit v1.2.3-70-g09d2 From a9fde2607895667823e9d1172fc193087125ef68 Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Apr 2008 00:48:04 -0700 Subject: [VLAN]: Tag vlan_group_device with net device, not ifindex. Currently vlan group is searched using one key - the ifindex. We'll have to lookup the vlan_group by two keys - ifindex and net. Turning the vlan_group lookup key to struct net_device pointer will make this process easier. Besides, this will eliminate one more place in the networking, that assumes that indexes are unique in the kernel. Signed-off-by: Pavel Emelyanov Acked-by: Patrick McHardy Signed-off-by: David S. Miller --- include/linux/if_vlan.h | 4 +++- net/8021q/vlan.c | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 12 deletions(-) (limited to 'net/8021q/vlan.c') diff --git a/include/linux/if_vlan.h b/include/linux/if_vlan.h index edd55af7ebd..15ace02b7b2 100644 --- a/include/linux/if_vlan.h +++ b/include/linux/if_vlan.h @@ -81,7 +81,9 @@ extern void vlan_ioctl_set(int (*hook)(struct net *, void __user *)); #define VLAN_GROUP_ARRAY_PART_LEN (VLAN_GROUP_ARRAY_LEN/VLAN_GROUP_ARRAY_SPLIT_PARTS) struct vlan_group { - int real_dev_ifindex; /* The ifindex of the ethernet(like) device the vlan is attached to. */ + struct net_device *real_dev; /* The ethernet(like) device + * the vlan is attached to. + */ unsigned int nr_vlans; struct hlist_node hlist; /* linked list */ struct net_device **vlan_devices_arrays[VLAN_GROUP_ARRAY_SPLIT_PARTS]; diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 5975ec3be7f..cf8d810a130 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -65,14 +65,14 @@ static inline unsigned int vlan_grp_hashfn(unsigned int idx) } /* Must be invoked with RCU read lock (no preempt) */ -static struct vlan_group *__vlan_find_group(int real_dev_ifindex) +static struct vlan_group *__vlan_find_group(struct net_device *real_dev) { struct vlan_group *grp; struct hlist_node *n; - int hash = vlan_grp_hashfn(real_dev_ifindex); + int hash = vlan_grp_hashfn(real_dev->ifindex); hlist_for_each_entry_rcu(grp, n, &vlan_group_hash[hash], hlist) { - if (grp->real_dev_ifindex == real_dev_ifindex) + if (grp->real_dev == real_dev) return grp; } @@ -86,7 +86,7 @@ static struct vlan_group *__vlan_find_group(int real_dev_ifindex) struct net_device *__find_vlan_dev(struct net_device *real_dev, unsigned short VID) { - struct vlan_group *grp = __vlan_find_group(real_dev->ifindex); + struct vlan_group *grp = __vlan_find_group(real_dev); if (grp) return vlan_group_get_device(grp, VID); @@ -103,7 +103,7 @@ static void vlan_group_free(struct vlan_group *grp) kfree(grp); } -static struct vlan_group *vlan_group_alloc(int ifindex) +static struct vlan_group *vlan_group_alloc(struct net_device *real_dev) { struct vlan_group *grp; @@ -111,9 +111,9 @@ static struct vlan_group *vlan_group_alloc(int ifindex) if (!grp) return NULL; - grp->real_dev_ifindex = ifindex; + grp->real_dev = real_dev; hlist_add_head_rcu(&grp->hlist, - &vlan_group_hash[vlan_grp_hashfn(ifindex)]); + &vlan_group_hash[vlan_grp_hashfn(real_dev->ifindex)]); return grp; } @@ -151,7 +151,7 @@ void unregister_vlan_dev(struct net_device *dev) ASSERT_RTNL(); - grp = __vlan_find_group(real_dev->ifindex); + grp = __vlan_find_group(real_dev); BUG_ON(!grp); vlan_proc_rem_dev(dev); @@ -246,9 +246,9 @@ int register_vlan_dev(struct net_device *dev) struct vlan_group *grp, *ngrp = NULL; int err; - grp = __vlan_find_group(real_dev->ifindex); + grp = __vlan_find_group(real_dev); if (!grp) { - ngrp = grp = vlan_group_alloc(real_dev->ifindex); + ngrp = grp = vlan_group_alloc(real_dev); if (!grp) return -ENOBUFS; } @@ -412,7 +412,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event, goto out; } - grp = __vlan_find_group(dev->ifindex); + grp = __vlan_find_group(dev); if (!grp) goto out; -- cgit v1.2.3-70-g09d2 From d9ed0f0e2dba45eec79ffbdd841757f87712349b Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Apr 2008 00:49:09 -0700 Subject: [VLAN]: Introduce the vlan_net structure and init/exit net ops. Unlike TUN, it is empty from the very beginning, and will be eventually populated later. Signed-off-by: Pavel Emelyanov Acked-by: Patrick McHardy Signed-off-by: David S. Miller --- net/8021q/vlan.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++ net/8021q/vlan.h | 5 +++++ 2 files changed, 51 insertions(+) (limited to 'net/8021q/vlan.c') diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index cf8d810a130..92966016a22 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "vlan.h" @@ -41,6 +42,8 @@ /* Global VLAN variables */ +int vlan_net_id; + /* Our listing of VLAN group(s) */ static struct hlist_head vlan_group_hash[VLAN_GRP_HASH_SIZE]; @@ -625,6 +628,41 @@ out: return err; } +static int vlan_init_net(struct net *net) +{ + int err; + struct vlan_net *vn; + + err = -ENOMEM; + vn = kzalloc(sizeof(struct vlan_net), GFP_KERNEL); + if (vn == NULL) + goto err_alloc; + + err = net_assign_generic(net, vlan_net_id, vn); + if (err < 0) + goto err_assign; + + return 0; + +err_assign: + kfree(vn); +err_alloc: + return err; +} + +static void vlan_exit_net(struct net *net) +{ + struct vlan_net *vn; + + vn = net_generic(net, vlan_net_id); + kfree(vn); +} + +static struct pernet_operations vlan_net_ops = { + .init = vlan_init_net, + .exit = vlan_exit_net, +}; + static int __init vlan_proto_init(void) { int err; @@ -632,6 +670,10 @@ static int __init vlan_proto_init(void) pr_info("%s v%s %s\n", vlan_fullname, vlan_version, vlan_copyright); pr_info("All bugs added by %s\n", vlan_buggyright); + err = register_pernet_gen_device(&vlan_net_id, &vlan_net_ops); + if (err < 0) + goto err0; + err = vlan_proc_init(); if (err < 0) goto err1; @@ -653,6 +695,8 @@ err3: err2: vlan_proc_cleanup(); err1: + unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); +err0: return err; } @@ -673,6 +717,8 @@ static void __exit vlan_cleanup_module(void) vlan_proc_cleanup(); + unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); + synchronize_net(); } diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 51271aea402..f27d8d6f362 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -50,4 +50,9 @@ static inline int is_vlan_dev(struct net_device *dev) return dev->priv_flags & IFF_802_1Q_VLAN; } +extern int vlan_net_id; + +struct vlan_net { +}; + #endif /* !(__BEN_VLAN_802_1Q_INC__) */ -- cgit v1.2.3-70-g09d2 From cd1c701432fbf84ad5ea1d8012ddd398a560bccc Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Apr 2008 00:51:12 -0700 Subject: [VLAN]: Add a net argument to proc init and cleanup calls. All proc files will be created in each net, so prepare them for this change now, not to mess it with real creation patch. The net != &init_net checks in them are for git-bisect sanity, but I will drop them soon. Signed-off-by: Pavel Emelyanov Acked-by: Patrick McHardy Signed-off-by: David S. Miller --- net/8021q/vlan.c | 15 +++++++-------- net/8021q/vlanproc.c | 12 +++++++++--- net/8021q/vlanproc.h | 10 ++++++---- 3 files changed, 22 insertions(+), 15 deletions(-) (limited to 'net/8021q/vlan.c') diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 92966016a22..541542e2a2c 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -642,8 +642,14 @@ static int vlan_init_net(struct net *net) if (err < 0) goto err_assign; + err = vlan_proc_init(net); + if (err < 0) + goto err_proc; + return 0; +err_proc: + /* nothing */ err_assign: kfree(vn); err_alloc: @@ -655,6 +661,7 @@ static void vlan_exit_net(struct net *net) struct vlan_net *vn; vn = net_generic(net, vlan_net_id); + vlan_proc_cleanup(net); kfree(vn); } @@ -674,10 +681,6 @@ static int __init vlan_proto_init(void) if (err < 0) goto err0; - err = vlan_proc_init(); - if (err < 0) - goto err1; - err = register_netdevice_notifier(&vlan_notifier_block); if (err < 0) goto err2; @@ -693,8 +696,6 @@ static int __init vlan_proto_init(void) err3: unregister_netdevice_notifier(&vlan_notifier_block); err2: - vlan_proc_cleanup(); -err1: unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); err0: return err; @@ -715,8 +716,6 @@ static void __exit vlan_cleanup_module(void) for (i = 0; i < VLAN_GRP_HASH_SIZE; i++) BUG_ON(!hlist_empty(&vlan_group_hash[i])); - vlan_proc_cleanup(); - unregister_pernet_gen_device(vlan_net_id, &vlan_net_ops); synchronize_net(); diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c index 24cd96ee810..4d13aeb8858 100644 --- a/net/8021q/vlanproc.c +++ b/net/8021q/vlanproc.c @@ -138,8 +138,11 @@ static const char *vlan_name_type_str[VLAN_NAME_TYPE_HIGHEST] = { * Clean up /proc/net/vlan entries */ -void vlan_proc_cleanup(void) +void vlan_proc_cleanup(struct net *net) { + if (net != &init_net) + return; + if (proc_vlan_conf) remove_proc_entry(name_conf, proc_vlan_dir); @@ -155,8 +158,11 @@ void vlan_proc_cleanup(void) * Create /proc/net/vlan entries */ -int __init vlan_proc_init(void) +int vlan_proc_init(struct net *net) { + if (net != &init_net) + return 0; + proc_vlan_dir = proc_mkdir(name_root, init_net.proc_net); if (!proc_vlan_dir) goto err; @@ -169,7 +175,7 @@ int __init vlan_proc_init(void) err: pr_err("%s: can't create entry in proc filesystem!\n", __func__); - vlan_proc_cleanup(); + vlan_proc_cleanup(net); return -ENOBUFS; } diff --git a/net/8021q/vlanproc.h b/net/8021q/vlanproc.h index da542cacc5a..063f60a3d5c 100644 --- a/net/8021q/vlanproc.h +++ b/net/8021q/vlanproc.h @@ -2,15 +2,17 @@ #define __BEN_VLAN_PROC_INC__ #ifdef CONFIG_PROC_FS -int vlan_proc_init(void); +struct net; + +int vlan_proc_init(struct net *net); int vlan_proc_rem_dev(struct net_device *vlandev); int vlan_proc_add_dev(struct net_device *vlandev); -void vlan_proc_cleanup(void); +void vlan_proc_cleanup(struct net *net); #else /* No CONFIG_PROC_FS */ -#define vlan_proc_init() (0) -#define vlan_proc_cleanup() do {} while (0) +#define vlan_proc_init(net) (0) +#define vlan_proc_cleanup(net) do {} while (0) #define vlan_proc_add_dev(dev) ({(void)(dev), 0; }) #define vlan_proc_rem_dev(dev) ({(void)(dev), 0; }) #endif -- cgit v1.2.3-70-g09d2 From 7a17a2f79f54a988d08ffa33ec9e1038bffec42b Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Apr 2008 00:54:39 -0700 Subject: [VLAN]: Make the vlan_name_type per-net. This includes moving one on the struct vlan_net and s/vlan_name_type/vn->name_type/ over the code. Signed-off-by: Pavel Emelyanov Acked-by: Patrick McHardy Signed-off-by: David S. Miller --- net/8021q/vlan.c | 14 +++++++++----- net/8021q/vlan.h | 4 ++-- net/8021q/vlanproc.c | 7 +++++-- 3 files changed, 16 insertions(+), 9 deletions(-) (limited to 'net/8021q/vlan.c') diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 541542e2a2c..5cacad0671d 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -52,9 +52,6 @@ static char vlan_version[] = DRV_VERSION; static char vlan_copyright[] = "Ben Greear "; static char vlan_buggyright[] = "David S. Miller "; -/* Determines interface naming scheme. */ -unsigned short vlan_name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD; - static struct packet_type vlan_packet_type = { .type = __constant_htons(ETH_P_8021Q), .func = vlan_skb_recv, /* VLAN receive method */ @@ -299,6 +296,8 @@ static int register_vlan_device(struct net_device *real_dev, unsigned short VLAN_ID) { struct net_device *new_dev; + struct net *net = dev_net(real_dev); + struct vlan_net *vn = net_generic(net, vlan_net_id); char name[IFNAMSIZ]; int err; @@ -310,7 +309,7 @@ static int register_vlan_device(struct net_device *real_dev, return err; /* Gotta set up the fields for the device. */ - switch (vlan_name_type) { + switch (vn->name_type) { case VLAN_NAME_TYPE_RAW_PLUS_VID: /* name will look like: eth1.0005 */ snprintf(name, IFNAMSIZ, "%s.%.4i", real_dev->name, VLAN_ID); @@ -580,7 +579,10 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg) break; if ((args.u.name_type >= 0) && (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) { - vlan_name_type = args.u.name_type; + struct vlan_net *vn; + + vn = net_generic(net, vlan_net_id); + vn->name_type = args.u.name_type; err = 0; } else { err = -EINVAL; @@ -642,6 +644,8 @@ static int vlan_init_net(struct net *net) if (err < 0) goto err_assign; + vn->name_type = VLAN_NAME_TYPE_RAW_PLUS_VID_NO_PAD; + err = vlan_proc_init(net); if (err < 0) goto err_proc; diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h index 7258357db84..5229a72c7ea 100644 --- a/net/8021q/vlan.h +++ b/net/8021q/vlan.h @@ -3,8 +3,6 @@ #include -extern unsigned short vlan_name_type; - #define VLAN_GRP_HASH_SHIFT 5 #define VLAN_GRP_HASH_SIZE (1 << VLAN_GRP_HASH_SHIFT) #define VLAN_GRP_HASH_MASK (VLAN_GRP_HASH_SIZE - 1) @@ -59,6 +57,8 @@ struct vlan_net { struct proc_dir_entry *proc_vlan_dir; /* /proc/net/vlan/config */ struct proc_dir_entry *proc_vlan_conf; + /* Determines interface naming scheme. */ + unsigned short name_type; }; #endif /* !(__BEN_VLAN_802_1Q_INC__) */ diff --git a/net/8021q/vlanproc.c b/net/8021q/vlanproc.c index cc17b722078..daad0064e2c 100644 --- a/net/8021q/vlanproc.c +++ b/net/8021q/vlanproc.c @@ -260,13 +260,16 @@ static void vlan_seq_stop(struct seq_file *seq, void *v) static int vlan_seq_show(struct seq_file *seq, void *v) { + struct net *net = seq_file_net(seq); + struct vlan_net *vn = net_generic(net, vlan_net_id); + if (v == SEQ_START_TOKEN) { const char *nmtype = NULL; seq_puts(seq, "VLAN Dev name | VLAN ID\n"); - if (vlan_name_type < ARRAY_SIZE(vlan_name_type_str)) - nmtype = vlan_name_type_str[vlan_name_type]; + if (vn->name_type < ARRAY_SIZE(vlan_name_type_str)) + nmtype = vlan_name_type_str[vn->name_type]; seq_printf(seq, "Name-Type: %s\n", nmtype ? nmtype : "UNKNOWN"); -- cgit v1.2.3-70-g09d2 From 65d292a2ef2df66fd1ab83447afee71ef3720ded Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Apr 2008 00:55:06 -0700 Subject: [VLAN]: Allow vlan devices registration in net namespaces. This one is similar to what I've done for TUN - set the proper net after device allocation and clean VLANs on net exit (use the rtnl_kill_links helper finally). Plus, drop explicit init_net usage and net != &init_net checks. Signed-off-by: Pavel Emelyanov Acked-by: Patrick McHardy Signed-off-by: David S. Miller --- net/8021q/vlan.c | 7 +++---- net/8021q/vlan_dev.c | 3 --- net/8021q/vlan_netlink.c | 2 +- 3 files changed, 4 insertions(+), 8 deletions(-) (limited to 'net/8021q/vlan.c') diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 5cacad0671d..7e9d22ec7d4 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -340,6 +340,7 @@ static int register_vlan_device(struct net_device *real_dev, if (new_dev == NULL) return -ENOBUFS; + dev_net_set(new_dev, net); /* need 4 bytes for extra VLAN header info, * hope the underlying device can handle it. */ @@ -406,9 +407,6 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event, int i, flgs; struct net_device *vlandev; - if (dev_net(dev) != &init_net) - return NOTIFY_DONE; - if (is_vlan_dev(dev)) { __vlan_device_event(dev, event); goto out; @@ -534,7 +532,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg) case GET_VLAN_REALDEV_NAME_CMD: case GET_VLAN_VID_CMD: err = -ENODEV; - dev = __dev_get_by_name(&init_net, args.device1); + dev = __dev_get_by_name(net, args.device1); if (!dev) goto out; @@ -665,6 +663,7 @@ static void vlan_exit_net(struct net *net) struct vlan_net *vn; vn = net_generic(net, vlan_net_id); + rtnl_kill_links(net, &vlan_link_ops); vlan_proc_cleanup(net); kfree(vn); } diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c index 4ae0d7ef62c..c961f082600 100644 --- a/net/8021q/vlan_dev.c +++ b/net/8021q/vlan_dev.c @@ -153,9 +153,6 @@ int vlan_skb_recv(struct sk_buff *skb, struct net_device *dev, struct net_device_stats *stats; unsigned short vlan_TCI; - if (dev_net(dev) != &init_net) - goto err_free; - skb = skb_share_check(skb, GFP_ATOMIC); if (skb == NULL) goto err_free; diff --git a/net/8021q/vlan_netlink.c b/net/8021q/vlan_netlink.c index e32eeb37987..c93e69ec28e 100644 --- a/net/8021q/vlan_netlink.c +++ b/net/8021q/vlan_netlink.c @@ -113,7 +113,7 @@ static int vlan_newlink(struct net_device *dev, if (!tb[IFLA_LINK]) return -EINVAL; - real_dev = __dev_get_by_index(&init_net, nla_get_u32(tb[IFLA_LINK])); + real_dev = __dev_get_by_index(dev_net(dev), nla_get_u32(tb[IFLA_LINK])); if (!real_dev) return -ENODEV; -- cgit v1.2.3-70-g09d2 From 30688a9a3e06d83d187658bd1c15f0e306bed38b Mon Sep 17 00:00:00 2001 From: Pavel Emelyanov Date: Wed, 16 Apr 2008 00:57:01 -0700 Subject: [VLAN]: Handle vlan devices net namespace changing. When van device is moved to another namespace proc files, related to this device, should also change one. Use the netdev REGISTER and UNREGISTER event handlers for this. Signed-off-by: Pavel Emelyanov Acked-by: Patrick McHardy Signed-off-by: David S. Miller --- net/8021q/vlan.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'net/8021q/vlan.c') diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c index 7e9d22ec7d4..2a739adaa92 100644 --- a/net/8021q/vlan.c +++ b/net/8021q/vlan.c @@ -154,8 +154,6 @@ void unregister_vlan_dev(struct net_device *dev) grp = __vlan_find_group(real_dev); BUG_ON(!grp); - vlan_proc_rem_dev(dev); - /* Take it out of our own structures, but be sure to interlock with * HW accelerating devices or SW vlan input packet processing. */ @@ -278,9 +276,6 @@ int register_vlan_dev(struct net_device *dev) if (real_dev->features & NETIF_F_HW_VLAN_FILTER) real_dev->vlan_rx_add_vid(real_dev, vlan_id); - if (vlan_proc_add_dev(dev) < 0) - pr_warning("8021q: failed to add proc entry for %s\n", - dev->name); return 0; out_free_group: @@ -396,6 +391,14 @@ static void __vlan_device_event(struct net_device *dev, unsigned long event) pr_warning("8021q: failed to change proc name for %s\n", dev->name); break; + case NETDEV_REGISTER: + if (vlan_proc_add_dev(dev) < 0) + pr_warning("8021q: failed to add proc entry for %s\n", + dev->name); + break; + case NETDEV_UNREGISTER: + vlan_proc_rem_dev(dev); + break; } } -- cgit v1.2.3-70-g09d2