Commit 82ef3d5d authored by Weilong Chen's avatar Weilong Chen Committed by David S. Miller

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: default avatarLibo Chen <chenlibo@huawei.com>
Signed-off-by: default avatarLibo Chen <chenlibo@huawei.com>
Signed-off-by: default avatarWeilong Chen <chenweilong@huawei.com>
Acked-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 671314a5
...@@ -88,11 +88,17 @@ int kobject_action_type(const char *buf, size_t count, ...@@ -88,11 +88,17 @@ int kobject_action_type(const char *buf, size_t count,
#ifdef CONFIG_NET #ifdef CONFIG_NET
static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data) static int kobj_bcast_filter(struct sock *dsk, struct sk_buff *skb, void *data)
{ {
struct kobject *kobj = data; struct kobject *kobj = data, *ksobj;
const struct kobj_ns_type_operations *ops; const struct kobj_ns_type_operations *ops;
ops = kobj_ns_ops(kobj); ops = kobj_ns_ops(kobj);
if (ops) { if (!ops && kobj->kset) {
ksobj = &kobj->kset->kobj;
if (ksobj->parent != NULL)
ops = kobj_ns_ops(ksobj->parent);
}
if (ops && ops->netlink_ns && kobj->ktype->namespace) {
const void *sock_ns, *ns; const void *sock_ns, *ns;
ns = kobj->ktype->namespace(kobj); ns = kobj->ktype->namespace(kobj);
sock_ns = ops->netlink_ns(dsk); sock_ns = ops->netlink_ns(dsk);
......
...@@ -744,10 +744,23 @@ static void rx_queue_release(struct kobject *kobj) ...@@ -744,10 +744,23 @@ static void rx_queue_release(struct kobject *kobj)
dev_put(queue->dev); dev_put(queue->dev);
} }
static const void *rx_queue_namespace(struct kobject *kobj)
{
struct netdev_rx_queue *queue = to_rx_queue(kobj);
struct device *dev = &queue->dev->dev;
const void *ns = NULL;
if (dev->class && dev->class->ns_type)
ns = dev->class->namespace(dev);
return ns;
}
static struct kobj_type rx_queue_ktype = { static struct kobj_type rx_queue_ktype = {
.sysfs_ops = &rx_queue_sysfs_ops, .sysfs_ops = &rx_queue_sysfs_ops,
.release = rx_queue_release, .release = rx_queue_release,
.default_attrs = rx_queue_default_attrs, .default_attrs = rx_queue_default_attrs,
.namespace = rx_queue_namespace
}; };
static int rx_queue_add_kobject(struct net_device *net, int index) 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,10 +1106,23 @@ static void netdev_queue_release(struct kobject *kobj)
dev_put(queue->dev); dev_put(queue->dev);
} }
static const void *netdev_queue_namespace(struct kobject *kobj)
{
struct netdev_queue *queue = to_netdev_queue(kobj);
struct device *dev = &queue->dev->dev;
const void *ns = NULL;
if (dev->class && dev->class->ns_type)
ns = dev->class->namespace(dev);
return ns;
}
static struct kobj_type netdev_queue_ktype = { static struct kobj_type netdev_queue_ktype = {
.sysfs_ops = &netdev_queue_sysfs_ops, .sysfs_ops = &netdev_queue_sysfs_ops,
.release = netdev_queue_release, .release = netdev_queue_release,
.default_attrs = netdev_queue_default_attrs, .default_attrs = netdev_queue_default_attrs,
.namespace = netdev_queue_namespace,
}; };
static int netdev_queue_add_kobject(struct net_device *net, int index) static int netdev_queue_add_kobject(struct net_device *net, int index)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment