diff options
Diffstat (limited to 'net/core/net-sysfs.c')
-rw-r--r-- | net/core/net-sysfs.c | 63 |
1 files changed, 47 insertions, 16 deletions
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index c57c4b228bb5..99e7052d7323 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> |
@@ -467,6 +469,7 @@ static struct attribute_group wireless_group = { | |||
467 | .attrs = wireless_attrs, | 469 | .attrs = wireless_attrs, |
468 | }; | 470 | }; |
469 | #endif | 471 | #endif |
472 | #endif /* CONFIG_SYSFS */ | ||
470 | 473 | ||
471 | #ifdef CONFIG_RPS | 474 | #ifdef CONFIG_RPS |
472 | /* | 475 | /* |
@@ -766,7 +769,38 @@ static void rx_queue_remove_kobjects(struct net_device *net) | |||
766 | kset_unregister(net->queues_kset); | 769 | kset_unregister(net->queues_kset); |
767 | } | 770 | } |
768 | #endif /* CONFIG_RPS */ | 771 | #endif /* CONFIG_RPS */ |
769 | #endif /* CONFIG_SYSFS */ | 772 | |
773 | static const void *net_current_ns(void) | ||
774 | { | ||
775 | return current->nsproxy->net_ns; | ||
776 | } | ||
777 | |||
778 | static const void *net_initial_ns(void) | ||
779 | { | ||
780 | return &init_net; | ||
781 | } | ||
782 | |||
783 | static const void *net_netlink_ns(struct sock *sk) | ||
784 | { | ||
785 | return sock_net(sk); | ||
786 | } | ||
787 | |||
788 | static struct kobj_ns_type_operations net_ns_type_operations = { | ||
789 | .type = KOBJ_NS_TYPE_NET, | ||
790 | .current_ns = net_current_ns, | ||
791 | .netlink_ns = net_netlink_ns, | ||
792 | .initial_ns = net_initial_ns, | ||
793 | }; | ||
794 | |||
795 | static void net_kobj_ns_exit(struct net *net) | ||
796 | { | ||
797 | kobj_ns_exit(KOBJ_NS_TYPE_NET, net); | ||
798 | } | ||
799 | |||
800 | static struct pernet_operations kobj_net_ops = { | ||
801 | .exit = net_kobj_ns_exit, | ||
802 | }; | ||
803 | |||
770 | 804 | ||
771 | #ifdef CONFIG_HOTPLUG | 805 | #ifdef CONFIG_HOTPLUG |
772 | static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) | 806 | static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) |
@@ -774,9 +808,6 @@ static int netdev_uevent(struct device *d, struct kobj_uevent_env *env) | |||
774 | struct net_device *dev = to_net_dev(d); | 808 | struct net_device *dev = to_net_dev(d); |
775 | int retval; | 809 | int retval; |
776 | 810 | ||
777 | if (!net_eq(dev_net(dev), &init_net)) | ||
778 | return 0; | ||
779 | |||
780 | /* pass interface to uevent. */ | 811 | /* pass interface to uevent. */ |
781 | retval = add_uevent_var(env, "INTERFACE=%s", dev->name); | 812 | retval = add_uevent_var(env, "INTERFACE=%s", dev->name); |
782 | if (retval) | 813 | if (retval) |
@@ -806,6 +837,13 @@ static void netdev_release(struct device *d) | |||
806 | kfree((char *)dev - dev->padded); | 837 | kfree((char *)dev - dev->padded); |
807 | } | 838 | } |
808 | 839 | ||
840 | static const void *net_namespace(struct device *d) | ||
841 | { | ||
842 | struct net_device *dev; | ||
843 | dev = container_of(d, struct net_device, dev); | ||
844 | return dev_net(dev); | ||
845 | } | ||
846 | |||
809 | static struct class net_class = { | 847 | static struct class net_class = { |
810 | .name = "net", | 848 | .name = "net", |
811 | .dev_release = netdev_release, | 849 | .dev_release = netdev_release, |
@@ -815,6 +853,8 @@ static struct class net_class = { | |||
815 | #ifdef CONFIG_HOTPLUG | 853 | #ifdef CONFIG_HOTPLUG |
816 | .dev_uevent = netdev_uevent, | 854 | .dev_uevent = netdev_uevent, |
817 | #endif | 855 | #endif |
856 | .ns_type = &net_ns_type_operations, | ||
857 | .namespace = net_namespace, | ||
818 | }; | 858 | }; |
819 | 859 | ||
820 | /* Delete sysfs entries but hold kobject reference until after all | 860 | /* Delete sysfs entries but hold kobject reference until after all |
@@ -826,9 +866,6 @@ void netdev_unregister_kobject(struct net_device * net) | |||
826 | 866 | ||
827 | kobject_get(&dev->kobj); | 867 | kobject_get(&dev->kobj); |
828 | 868 | ||
829 | if (!net_eq(dev_net(net), &init_net)) | ||
830 | return; | ||
831 | |||
832 | #ifdef CONFIG_RPS | 869 | #ifdef CONFIG_RPS |
833 | rx_queue_remove_kobjects(net); | 870 | rx_queue_remove_kobjects(net); |
834 | #endif | 871 | #endif |
@@ -843,6 +880,7 @@ int netdev_register_kobject(struct net_device *net) | |||
843 | const struct attribute_group **groups = net->sysfs_groups; | 880 | const struct attribute_group **groups = net->sysfs_groups; |
844 | int error = 0; | 881 | int error = 0; |
845 | 882 | ||
883 | device_initialize(dev); | ||
846 | dev->class = &net_class; | 884 | dev->class = &net_class; |
847 | dev->platform_data = net; | 885 | dev->platform_data = net; |
848 | dev->groups = groups; | 886 | dev->groups = groups; |
@@ -865,9 +903,6 @@ int netdev_register_kobject(struct net_device *net) | |||
865 | #endif | 903 | #endif |
866 | #endif /* CONFIG_SYSFS */ | 904 | #endif /* CONFIG_SYSFS */ |
867 | 905 | ||
868 | if (!net_eq(dev_net(net), &init_net)) | ||
869 | return 0; | ||
870 | |||
871 | error = device_add(dev); | 906 | error = device_add(dev); |
872 | if (error) | 907 | if (error) |
873 | return error; | 908 | return error; |
@@ -896,13 +931,9 @@ void netdev_class_remove_file(struct class_attribute *class_attr) | |||
896 | EXPORT_SYMBOL(netdev_class_create_file); | 931 | EXPORT_SYMBOL(netdev_class_create_file); |
897 | EXPORT_SYMBOL(netdev_class_remove_file); | 932 | EXPORT_SYMBOL(netdev_class_remove_file); |
898 | 933 | ||
899 | void netdev_initialize_kobject(struct net_device *net) | ||
900 | { | ||
901 | struct device *device = &(net->dev); | ||
902 | device_initialize(device); | ||
903 | } | ||
904 | |||
905 | int netdev_kobject_init(void) | 934 | int netdev_kobject_init(void) |
906 | { | 935 | { |
936 | kobj_ns_type_register(&net_ns_type_operations); | ||
937 | register_pernet_subsys(&kobj_net_ops); | ||
907 | return class_register(&net_class); | 938 | return class_register(&net_class); |
908 | } | 939 | } |