From: Eric W. Biederman <ebiederm@xmission.com>
The problem. Network devices show up in sysfs and with the network
namespace active multiple devices with the same name can show up in
the same directory, ouch!
To avoid that problem and allow existing applications in network namespaces
to see the same interface that is currently presented in sysfs, this
patch enables the tagging directory support in sysfs.
By using the network namespace pointers as tags to separate out the
the sysfs directory entries we ensure that we don't have conflicts
in the directories and applications only see a limited set of
the network devices.
Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
---
include/linux/kobject.h | 1 +
net/Kconfig | 8 ++++++++
net/core/net-sysfs.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/include/linux/kobject.h b/include/linux/kobject.h
index b60d2df..cf343a8 100644
--- a/include/linux/kobject.h
+++ b/include/linux/kobject.h
@@ -142,6 +142,7 @@ extern const struct sysfs_ops kobj_sysfs_ops;
*/
enum kobj_ns_type {
KOBJ_NS_TYPE_NONE = 0,
+ KOBJ_NS_TYPE_NET,
KOBJ_NS_TYPES
};
diff --git a/net/Kconfig b/net/Kconfig
index 041c35e..265e33b 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -45,6 +45,14 @@ config COMPAT_NETLINK_MESSAGES
menu "Networking options"
+config NET_NS
+ bool "Network namespace support"
+ default n
+ depends on EXPERIMENTAL && NAMESPACES
+ help
+ Allow user space to create what appear to be multiple instances
+ of the network stack.
+
source "net/packet/Kconfig"
source "net/unix/Kconfig"
source "net/xfrm/Kconfig"
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 099c753..1b98e36 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -13,7 +13,9 @@
#include <linux/kernel.h>
#include <linux/netdevice.h>
#include <linux/if_arp.h>
+#include <linux/nsproxy.h>
#include ...Hi Eric, I'm confused - NET_NS is defined in init/Kconfig right now. Is the tree you're working from very different from mine, or is this the unfortunate I think the kobj_ns_type_register() needs to be under ifdef CONFIG_SYSFS as well, bc net_ns_type_operations is defined under ifdef CONFIG_SYSFS. -serge --
Old patches, nothing that complains when you make a mistake like this, and apparently I have a blind spot in my personal code review. At one point it was not possible to enable the network namespace until the sysfs stuff was enabled, but things have been going on long enough kobj_ns_type_register should not be under CONFIG_SYSFS. Which means that kobj_ns_type_operations needs not to be under CONFIG_SYSFS as well. That you for spotting that bug. Grr. Eric --
np - outside of that, Acked-by: Serge E. Hallyn <serue@us.ibm.com> I saw no problems with the other patches, just don't feel qualified to give an ack. thanks, -serge --
I had a couple of stupid bugs in:
netns: Teach network device kobjects which namespace they are in.
- I duplicated the Kconfig for the NET_NS
- The build was broken when sysfs was not compiled in
The sysfs breakage is because after I moved the operations
for the sysfs to the kobject layer, to make things cleaner
I forgot to move the ifdefs. Opps.
I'm not quite certain how I got introduced a second NET_NS Kconfig,
but it was probably a 3 way merge somewhere along the way that
did not notice that the NET_NS Kconfig option had mvoed and thout
that was a bug. It probably slipped in because it used to be the
sysfs patches were the first patches in my network namespace patches.
Some things just don't go like you would expect.
Neither of these bugs actually affect anything in the common case
but they should be fixed.
Thanks to Serge for noticing they were present.
Reported-by: Serge E. Hallyn <serue@us.ibm.com>
Signed-off-by: Eric W. Biederman <ebiederm@aristanetworks.com>
---
net/Kconfig | 8 --------
net/core/net-sysfs.c | 8 +++-----
2 files changed, 3 insertions(+), 13 deletions(-)
diff --git a/net/Kconfig b/net/Kconfig
index 265e33b..041c35e 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -45,14 +45,6 @@ config COMPAT_NETLINK_MESSAGES
menu "Networking options"
-config NET_NS
- bool "Network namespace support"
- default n
- depends on EXPERIMENTAL && NAMESPACES
- help
- Allow user space to create what appear to be multiple instances
- of the network stack.
-
source "net/packet/Kconfig"
source "net/unix/Kconfig"
source "net/xfrm/Kconfig"
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index 0727c57..c4c5157 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -467,6 +467,7 @@ static struct attribute_group wireless_group = {
.attrs = wireless_attrs,
};
#endif
+#endif /* CONFIG_SYSFS */
static const void *net_current_ns(void)
{
@@ -495,11 +496,10 @@ static void net_kobj_ns_exit(struct net ...From: ebiederm@xmission.com (Eric W. Biederman) Acked-by: David S. Miller <davem@davemloft.net> --
