diff options
| -rw-r--r-- | include/linux/kobject.h | 1 | ||||
| -rw-r--r-- | net/Kconfig | 8 | ||||
| -rw-r--r-- | net/core/net-sysfs.c | 47 |
3 files changed, 56 insertions, 0 deletions
diff --git a/include/linux/kobject.h b/include/linux/kobject.h index b60d2dfe4e69..cf343a852534 100644 --- a/include/linux/kobject.h +++ b/include/linux/kobject.h | |||
| @@ -142,6 +142,7 @@ extern const struct sysfs_ops kobj_sysfs_ops; | |||
| 142 | */ | 142 | */ |
| 143 | enum kobj_ns_type { | 143 | enum kobj_ns_type { |
| 144 | KOBJ_NS_TYPE_NONE = 0, | 144 | KOBJ_NS_TYPE_NONE = 0, |
| 145 | KOBJ_NS_TYPE_NET, | ||
| 145 | KOBJ_NS_TYPES | 146 | KOBJ_NS_TYPES |
| 146 | }; | 147 | }; |
| 147 | 148 | ||
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 | ||
| 46 | menu "Networking options" | 46 | menu "Networking options" |
| 47 | 47 | ||
| 48 | config 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 | |||
| 48 | source "net/packet/Kconfig" | 56 | source "net/packet/Kconfig" |
| 49 | source "net/unix/Kconfig" | 57 | source "net/unix/Kconfig" |
| 50 | source "net/xfrm/Kconfig" | 58 | source "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 | |||
| 772 | static const void *net_current_ns(void) | ||
| 773 | { | ||
| 774 | return current->nsproxy->net_ns; | ||
| 775 | } | ||
| 776 | |||
| 777 | static const void *net_initial_ns(void) | ||
| 778 | { | ||
| 779 | return &init_net; | ||
| 780 | } | ||
| 781 | |||
| 782 | static const void *net_netlink_ns(struct sock *sk) | ||
| 783 | { | ||
| 784 | return sock_net(sk); | ||
| 785 | } | ||
| 786 | |||
| 787 | static 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 | |||
| 794 | static void net_kobj_ns_exit(struct net *net) | ||
| 795 | { | ||
| 796 | kobj_ns_exit(KOBJ_NS_TYPE_NET, net); | ||
| 797 | } | ||
| 798 | |||
| 799 | static 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 | ||
| 843 | static 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 | |||
| 809 | static struct class net_class = { | 850 | static 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 | ||
| 905 | int netdev_kobject_init(void) | 948 | int 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 | } |
