Skip to contentSkip to conversation

netns fixes

PATCH In review Daniel Lezcano 3 participants 7 messages Apr 30, 2008 – Jun 4, 2008

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover netns fixes

The two following patches fix bugs related to the network namespace. The first one fixes a sysfs issue (when using the sysfs per namespace), and the second one fixes the frag timer for ipv6 to use the right network namespace.

#1 lore raw

PATCH 1/2 fix device renaming for sysfs

When a netdev is moved across namespaces with the 'dev_change_net_namespace' function, the 'device_rename' function is used to fixup kobject and refresh the sysfs tree. The device_rename function will call kobject_rename and this one will check if there is an object with the same name and this is the case because we are renaming the object with the same name.

The use of 'device_rename' seems for me wrong because we usually don't rename it but just move it across namespaces. As we just want to do a mini "netdev_[un]register", IMO the functions 'netdev_[un]register_kobject' should be used instead, like an usual network device [un]registering.

This patch replace device_rename by netdev_unregister_kobject, followed by netdev_register_kobject.

The netdev_register_kobject will call device_initialize and will raise a warning indicating the device was already initialized. In order to fix that, I split the device initialization into a separate function and use it together with 'netdev_register_kobject' into register_netdevice. So we can safely call 'netdev_register_kobject' in 'dev_change_net_namespace'.

This fix will allow to properly use the sysfs per namespace which is coming from -mm tree.

---
 net/core/dev.c       |    4 +++-
 net/core/net-sysfs.c |    7 ++++++-
 net/core/net-sysfs.h |    2 +-
 3 files changed, 10 insertions(+), 3 deletions(-)
net/core/dev.c +3 -1
Index: net-2.6/net/core/dev.c
===================================================================
@@ -3776,6 +3776,7 @@ int register_netdevice(struct net_device
 		}
 	}
 
+	netdev_initialize_kobject(dev);
 	ret = netdev_register_kobject(dev);
 	if (ret)
 		goto err_uninit;
@@ -4208,7 +4209,8 @@ int dev_change_net_namespace(struct net_
 	}
 
 	/* Fixup kobjects */
-	err = device_rename(&dev->dev, dev->name);
+	netdev_unregister_kobject(dev);
+	err = netdev_register_kobject(dev);
 	WARN_ON(err);
 
 	/* Add the device back in the hashes */
net/core/net-sysfs.c +6 -1
Index: net-2.6/net/core/net-sysfs.c
===================================================================
@@ -449,7 +449,6 @@ int netdev_register_kobject(struct net_d
 	struct device *dev = &(net->dev);
 	struct attribute_group **groups = net->sysfs_groups;
 
-	device_initialize(dev);
 	dev->class = &net_class;
 	dev->platform_data = net;
 	dev->groups = groups;
@@ -470,6 +469,12 @@ int netdev_register_kobject(struct net_d
 	return device_add(dev);
 }
 
+void netdev_initialize_kobject(struct net_device *net)
+{
+	struct device *device = &(net->dev);
+	device_initialize(device);
+}
+
 int netdev_kobject_init(void)
 {
 	return class_register(&net_class);
net/core/net-sysfs.h +1 -1
Index: net-2.6/net/core/net-sysfs.h
===================================================================
@@ -4,5 +4,5 @@
 int netdev_kobject_init(void);
 int netdev_register_kobject(struct net_device *);
 void netdev_unregister_kobject(struct net_device *);
-
+void netdev_initialize_kobject(struct net_device *);
 #endif
maintainer
#2 lore raw

Re: [net-2.6 patch 1/2][NETNS] fix device renaming for sysfs

From: Daniel Lezcano <[email protected]>
Date: Wed, 30 Apr 2008 23:31:14 +0200

Quoted 20 lines

When a netdev is moved across namespaces with the 'dev_change_net_namespace' function, the 'device_rename' function is used to fixup kobject and refresh the sysfs tree. The device_rename function will call kobject_rename and this one will check if there is an object with the same name and this is the case because we are renaming the object with the same name.

The use of 'device_rename' seems for me wrong because we usually don't rename it but just move it across namespaces. As we just want to do a mini "netdev_[un]register", IMO the functions 'netdev_[un]register_kobject' should be used instead, like an usual network device [un]registering.

This patch replace device_rename by netdev_unregister_kobject, followed by netdev_register_kobject.

The netdev_register_kobject will call device_initialize and will raise a warning indicating the device was already initialized. In order to fix that, I split the device initialization into a separate function and use it together with 'netdev_register_kobject' into register_netdevice. So we can safely call 'netdev_register_kobject' in 'dev_change_net_namespace'.

Quoted 5 lines

This fix will allow to properly use the sysfs per namespace which is coming from -mm tree.

Looks good, applied.

#3 lore raw

Re: [net-2.6 patch 1/2][NETNS] fix device renaming for sysfs

In reply to Daniel Lezcano
Quoted 10 lines · Daniel Lezcano

When a netdev is moved across namespaces with the 'dev_change_net_namespace' function, the 'device_rename' function is used to fixup kobject and refresh the sysfs tree. The device_rename function will call kobject_rename and this one will check if there is an object with the same name and this is the case because we are renaming the object with the same name.

The use of 'device_rename' seems for me wrong because we usually don't rename it but just move it across namespaces. As we just want to do a mini "netdev_[un]register", IMO the functions 'netdev_[un]register_kobject' should be used instead, like an usual network device [un]registering.

device_rename is correct. Because doing device_del; device_add removes any driver specific sysfs attributes.

Causing your patch to introduce subtle driver breakage only when we move a network device between namespaces. Ouch!

To support this operation we need something like device_rename that can preserve driver specific attributes, and generally handle movement between namespaces. Since device_rename already does 99% of what we need it to do I found it easier to extend device_rename to handle this case then to introduce yet another function into the kobject layer.

Quoted 2 lines

This patch replace device_rename by netdev_unregister_kobject, followed by netdev_register_kobject.

And sysfs comes a' tumblin' down.

My apologies for not replying sooner I just spotted this.

Eric

#4 lore raw

Re: [net-2.6 patch 1/2][NETNS] fix device renaming for sysfs

Quoted 22 lines · Eric W. Biederman
Quoted 6 lines · Daniel Lezcano

When a netdev is moved across namespaces with the 'dev_change_net_namespace' function, the 'device_rename' function is used to fixup kobject and refresh the sysfs tree. The device_rename function will call kobject_rename and this one will check if there is an object with the same name and this is the case
because we are renaming the object with the same name.

The use of 'device_rename' seems for me wrong because we usually don't
rename it but just move it across namespaces. As we just want to do a mini "netdev_[un]register", IMO the functions 'netdev_[un]register_kobject' should be used instead, like an usual network device [un]registering.

device_rename is correct. Because doing device_del; device_add removes any driver specific sysfs attributes.

Causing your patch to introduce subtle driver breakage only when we move a network device between namespaces. Ouch!

To support this operation we need something like device_rename that can preserve driver specific attributes, and generally handle movement between namespaces. Since device_rename already does 99% of what we need it to do I found it easier to extend device_rename to handle this case then to introduce yet another function into the kobject layer.

Quoted 5 lines
Quoted 2 lines

This patch replace device_rename by netdev_unregister_kobject, followed by netdev_register_kobject.

And sysfs comes a' tumblin' down.
My apologies for not replying sooner I just spotted this.

My fault, I should have Cc'ed you when sending the email :( Thanks for looking at this patch.

-- Daniel

#5 lore raw

PATCH 2/2 Fix reassembly timer to use the right namespace

In reply to Daniel Lezcano

This trivial fix retrieves the network namespace from frag queue and use it to get the network device in the right namespace.

---
 net/ipv6/reassembly.c |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
net/ipv6/reassembly.c +3 -1
Index: net-2.6/net/ipv6/reassembly.c
===================================================================
@@ -197,6 +197,7 @@ static void ip6_frag_expire(unsigned lon
 {
 	struct frag_queue *fq;
 	struct net_device *dev = NULL;
+	struct net *net;
 
 	fq = container_of((struct inet_frag_queue *)data, struct frag_queue, q);
 
@@ -207,7 +208,8 @@ static void ip6_frag_expire(unsigned lon
 
 	fq_kill(fq);
 
-	dev = dev_get_by_index(&init_net, fq->iif);
+	net = container_of(fq->q.net, struct net, ipv6.frags);
+	dev = dev_get_by_index(net, fq->iif);
 	if (!dev)
 		goto out;
 
maintainer
#6 lore raw

Re: [net-2.6 patch 2/2][NETNS] Fix reassembly timer to use the right namespace

From: Daniel Lezcano <[email protected]>
Date: Wed, 30 Apr 2008 23:31:15 +0200

Quoted 4 lines

This trivial fix retrieves the network namespace from frag queue and use it to get the network device in the right namespace.

The one area where ipv4 and ipv6 code didn't get fully considated, and voila! ipv4 got it right and ipv6 had the bug :-)

Patch applied, thanks!