diff options
| author | Weilong Chen <chenweilong@huawei.com> | 2014-01-16 04:24:31 -0500 |
|---|---|---|
| committer | David S. Miller <davem@davemloft.net> | 2014-01-19 23:02:02 -0500 |
| commit | 82ef3d5d5f3ffd757c960693c4fe7a0051211849 (patch) | |
| tree | 2494c00a2fc1d9153734672cfbe7e96e215aa14a | |
| parent | 671314a5abb7abb8346cd3f16f75c1e55ed7667b (diff) | |
net: fix "queues" uevent between network namespaces
When I create a new namespace with 'ip netns add net0', or add/remove
new links in a namespace with 'ip link add/delete type veth', rx/tx
queues events can be got in all namespaces. That is because rx/tx queue
ktypes do not have namespace support, and their kobj parents are setted to
NULL. This patch is to fix it.
Reported-by: Libo Chen <chenlibo@huawei.com>
Signed-off-by: Libo Chen <chenlibo@huawei.com>
Signed-off-by: Weilong Chen <chenweilong@huawei.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
| -rw-r--r-- | lib/kobject_uevent.c | 10 | ||||
| -rw-r--r-- | net/core/net-sysfs.c | 26 |
2 files changed, 34 insertions, 2 deletions
diff --git a/lib/kobject_uevent.c b/lib/kobject_uevent.c index 52e5abbc41db..5f72767ddd9b 100644 --- a/lib/kobject_uevent.c +++ b/lib/kobject_uevent.c | |||
| @@ -88,11 +88,17 @@ out: | |||
| 88 | #ifdef CONFIG_NET | 88 | #ifdef CONFIG_NET |
| 89 | static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) | 89 | static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) |
| 90 | { | 90 | { |
| 91 | struct kobject *kobj = data; | 91 | struct kobject *kobj = data, *ksobj; |
| 92 | const struct kobj_ns_type_operations *ops; | 92 | const struct kobj_ns_type_operations *ops; |
| 93 | 93 | ||
| 94 | ops = kobj_ns_ops(kobj); | 94 | ops = kobj_ns_ops(kobj); |
| 95 | if (ops) { | 95 | if (!ops && kobj->kset) { |
| 96 | ksobj = &kobj->kset->kobj; | ||
| 97 | if (ksobj->parent != NULL) | ||
| 98 | ops = kobj_ns_ops(ksobj->parent); | ||
| 99 | } | ||
| 100 | |||
| 101 | if (ops && ops->netlink_ns && kobj->ktype->namespace) { | ||
| 96 | const void *sock_ns, *ns; | 102 | const void *sock_ns, *ns; |
| 97 | ns = kobj->ktype->namespace(kobj); | 103 | ns = kobj->ktype->namespace(kobj); |
| 98 | sock_ns = ops->netlink_ns(dsk); | 104 | sock_ns = ops->netlink_ns(dsk); |
diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 7eeadeecc5a2..93886246a0b4 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c | |||
| @@ -744,10 +744,23 @@ static void rx_queue_release(struct kobject *kobj) | |||
| 744 | dev_put(queue->dev); | 744 | dev_put(queue->dev); |
| 745 | } | 745 | } |
| 746 | 746 | ||
| 747 | static const void *rx_queue_namespace(struct kobject *kobj) | ||
| 748 | { | ||
| 749 | struct netdev_rx_queue *queue = to_rx_queue(kobj); | ||
| 750 | struct device *dev = &queue->dev->dev; | ||
| 751 | const void *ns = NULL; | ||
| 752 | |||
| 753 | if (dev->class && dev->class->ns_type) | ||
| 754 | ns = dev->class->namespace(dev); | ||
| 755 | |||
| 756 | return ns; | ||
| 757 | } | ||
| 758 | |||
| 747 | static struct kobj_type rx_queue_ktype = { | 759 | static struct kobj_type rx_queue_ktype = { |
| 748 | .sysfs_ops = &rx_queue_sysfs_ops, | 760 | .sysfs_ops = &rx_queue_sysfs_ops, |
| 749 | .release = rx_queue_release, | 761 | .release = rx_queue_release, |
| 750 | .default_attrs = rx_queue_default_attrs, | 762 | .default_attrs = rx_queue_default_attrs, |
| 763 | .namespace = rx_queue_namespace | ||
| 751 | }; | 764 | }; |
| 752 | 765 | ||
| 753 | static int rx_queue_add_kobject(struct net_device *net, int index) | 766 | static int rx_queue_add_kobject(struct net_device *net, int index) |
| @@ -1093,10 +1106,23 @@ static void netdev_queue_release(struct kobject *kobj) | |||
| 1093 | dev_put(queue->dev); | 1106 | dev_put(queue->dev); |
| 1094 | } | 1107 | } |
| 1095 | 1108 | ||
| 1109 | static const void *netdev_queue_namespace(struct kobject *kobj) | ||
| 1110 | { | ||
| 1111 | struct netdev_queue *queue = to_netdev_queue(kobj); | ||
| 1112 | struct device *dev = &queue->dev->dev; | ||
| 1113 | const void *ns = NULL; | ||
| 1114 | |||
| 1115 | if (dev->class && dev->class->ns_type) | ||
| 1116 | ns = dev->class->namespace(dev); | ||
| 1117 | |||
| 1118 | return ns; | ||
| 1119 | } | ||
| 1120 | |||
| 1096 | static struct kobj_type netdev_queue_ktype = { | 1121 | static struct kobj_type netdev_queue_ktype = { |
| 1097 | .sysfs_ops = &netdev_queue_sysfs_ops, | 1122 | .sysfs_ops = &netdev_queue_sysfs_ops, |
| 1098 | .release = netdev_queue_release, | 1123 | .release = netdev_queue_release, |
| 1099 | .default_attrs = netdev_queue_default_attrs, | 1124 | .default_attrs = netdev_queue_default_attrs, |
| 1125 | .namespace = netdev_queue_namespace, | ||
| 1100 | }; | 1126 | }; |
| 1101 | 1127 | ||
| 1102 | static int netdev_queue_add_kobject(struct net_device *net, int index) | 1128 | static int netdev_queue_add_kobject(struct net_device *net, int index) |
