aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2010-05-04 20:36:45 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-05-21 12:37:32 -0400
commit608b4b9548dedf4185ca47edcaae4bff2ceb62de (patch)
tree6855a119e99a4e0142c17b8cc4aa08968f3f6ab6 /net
parent07e98962fa778b9782c8845dfcb06a84cc050744 (diff)
netns: Teach network device kobjects which namespace they are in.
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> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'net')
-rw-r--r--net/Kconfig8
-rw-r--r--net/core/net-sysfs.c47
2 files changed, 55 insertions, 0 deletions
diff --git a/net/Kconfig b/net/Kconfig
index 0d68b40fc0e6..f49532053a98 100644
--- a/net/Kconfig
+++ b/net/Kconfig
@@ -45,6 +45,14 @@ config COMPAT_NETLINK_MESSAGES
45 45
46menu "Networking options" 46menu "Networking options"
47 47
48config NET_NS
49 bool "Network namespace support"
50 default n
51 depends on EXPERIMENTAL && NAMESPACES
52 help
53 Allow user space to create what appear to be multiple instances
54 of the network stack.
55
48source "net/packet/Kconfig" 56source "net/packet/Kconfig"
49source "net/unix/Kconfig" 57source "net/unix/Kconfig"
50source "net/xfrm/Kconfig" 58source "net/xfrm/Kconfig"
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
index c57c4b228bb5..b388cdab9316 100644
--- a/net/core/net-sysfs.c
+++ b/net/core/net-sysfs.c
@@ -14,7 +14,9 @@
14#include <linux/netdevice.h> 14#include <linux/netdevice.h>
15#include <linux/if_arp.h> 15#include <linux/if_arp.h>
16#include <linux/slab.h> 16#include <linux/slab.h>
17#include <linux/nsproxy.h>
17#include <net/sock.h> 18#include <net/sock.h>
19#include <net/net_namespace.h>
18#include <linux/rtnetlink.h> 20#include <linux/rtnetlink.h>
19#include <linux/wireless.h> 21#include <linux/wireless.h>
20#include <linux/vmalloc.h> 22#include <linux/vmalloc.h>
@@ -766,6 +768,38 @@ static void rx_queue_remove_kobjects(struct net_device *net)
766 kset_unregister(net->queues_kset); 768 kset_unregister(net->queues_kset);
767} 769}
768#endif /* CONFIG_RPS */ 770#endif /* CONFIG_RPS */
771
772static const void *net_current_ns(void)
773{
774 return current->nsproxy->net_ns;
775}
776
777static const void *net_initial_ns(void)
778{
779 return &init_net;
780}
781
782static const void *net_netlink_ns(struct sock *sk)
783{
784 return sock_net(sk);
785}
786
787static struct kobj_ns_type_operations net_ns_type_operations = {
788 .type = KOBJ_NS_TYPE_NET,
789 .current_ns = net_current_ns,
790 .netlink_ns = net_netlink_ns,
791 .initial_ns = net_initial_ns,
792};
793
794static void net_kobj_ns_exit(struct net *net)
795{
796 kobj_ns_exit(KOBJ_NS_TYPE_NET, net);
797}
798
799static struct pernet_operations sysfs_net_ops = {
800 .exit = net_kobj_ns_exit,
801};
802
769#endif /* CONFIG_SYSFS */ 803#endif /* CONFIG_SYSFS */
770 804
771#ifdef CONFIG_HOTPLUG 805#ifdef CONFIG_HOTPLUG
@@ -806,6 +840,13 @@ static void netdev_release(struct device *d)
806 kfree((char *)dev - dev->padded); 840 kfree((char *)dev - dev->padded);
807} 841}
808 842
843static const void *net_namespace(struct device *d)
844{
845 struct net_device *dev;
846 dev = container_of(d, struct net_device, dev);
847 return dev_net(dev);
848}
849
809static struct class net_class = { 850static struct class net_class = {
810 .name = "net", 851 .name = "net",
811 .dev_release = netdev_release, 852 .dev_release = netdev_release,
@@ -815,6 +856,8 @@ static struct class net_class = {
815#ifdef CONFIG_HOTPLUG 856#ifdef CONFIG_HOTPLUG
816 .dev_uevent = netdev_uevent, 857 .dev_uevent = netdev_uevent,
817#endif 858#endif
859 .ns_type = &net_ns_type_operations,
860 .namespace = net_namespace,
818}; 861};
819 862
820/* Delete sysfs entries but hold kobject reference until after all 863/* Delete sysfs entries but hold kobject reference until after all
@@ -904,5 +947,9 @@ void netdev_initialize_kobject(struct net_device *net)
904 947
905int netdev_kobject_init(void) 948int netdev_kobject_init(void)
906{ 949{
950 kobj_ns_type_register(&net_ns_type_operations);
951#ifdef CONFIG_SYSFS
952 register_pernet_subsys(&sysfs_net_ops);
953#endif
907 return class_register(&net_class); 954 return class_register(&net_class);
908} 955}