vlan: take link netns into account in vlan_newlink()
Subsystems (2)
PATCH 1/1 vlan: take link netns into account in vlan_newlink()
When IFLA_LINK_NETNSID is set, the ifindex from IFLA_LINK comes from another netns.
--- net/8021q/vlan_netlink.c | 13 ++++++++++++- net/core/net_namespace.c | 1 + 2 files changed, 13 insertions(+), 1 deletion(-)
net/8021q/vlan_netlink.c +12 -1
@@ -118,6 +118,7 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev, {struct vlan_dev_priv *vlan =vlan_dev_priv (dev);struct net_device *real_dev; +struct net *link_net;__be16 proto;int err;
@@ -126,7 +127,17 @@ static int vlan_newlink(struct net *src_net, struct net_device *dev,if (!tb[IFLA_LINK ])return -EINVAL ; - real_dev =__dev_get_by_index (src_net,nla_get_u32 (tb[IFLA_LINK ])); +if (tb[IFLA_LINK_NETNSID ]) { +int id =nla_get_s32 (tb[IFLA_LINK_NETNSID ]); + + link_net =get_net_ns_by_id (src_net, id); +if (!link_net) +return -EINVAL ; + }else { + link_net =get_net (src_net); + } + real_dev =__dev_get_by_index (link_net,nla_get_u32 (tb[IFLA_LINK ])); +put_net (link_net);if (!real_dev)return -ENODEV ;
net/core/net_namespace.c +1 -0
@@ -219,6 +219,7 @@ struct net *get_net_ns_by_id(struct net *net, int id)return peer; } +EXPORT_SYMBOL (get_net_ns_by_id);/* * setup_net runs the initializers for the network namespace object.
Signature · 1 line
2.2.2
Quoted 4 lines · Nicolas Dichtel
When
IFLA_LINK_NETNSIDis set, the ifindex fromIFLA_LINKcomes from another netns.Signed-off-by Nicolas Dichtel <[email protected]>
Please, discard this patch. It's not the right fix. I will send an update later.
PATCH v2 1/1 rtnetlink: pass link_net to the newlink handler
When IFLA_LINK_NETNSID is used, the netdevice should be built in this link netns and moved at the end to another netns (pointed by the socket netns or IFLA_NET_NS_[PID|FD]).
Existing user of the newlink handler will use the netns argument (src_net) to find a link netdevice or to check some other information into the link netns. For example, to find a netdevice, two information are required: an ifindex (usually from IFLA_LINK) and a netns (this link netns).
Note: when using IFLA_LINK_NETNSID and IFLA_NET_NS_[PID|FD], a user may create a netdevice that stands in netnsX and with its link part in netnsY, by sending a rtnl message from netnsZ.
---
v2: instead of patching each subsystem, pass the right netns to
the newlink handler
net/core/rtnetlink.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/core/rtnetlink.c +1 -1
@@ -2148,7 +2148,7 @@ replay: dev->ifindex = ifm->ifi_index;if (ops->newlink) { - err = ops->newlink (net, dev, tb, data); + err = ops->newlink (link_net ? : net, dev, tb, data);/* Drivers should call free_netdev() in ->destructor * and unregister it on failure after registration * so that device could be finally freed in rtnl_unlock.
Signature · 1 line
2.2.2
Re: [PATCH net-next v2] rtnetlink: pass link_net to the newlink handler
From: Nicolas Dichtel <[email protected]>
Date: Tue, 27 Jan 2015 11:13:08 +0100
Quoted 9 lines
When
IFLA_LINK_NETNSIDis used, the netdevice should be built in this link netns and moved at the end to another netns (pointed by the socket netns or IFLA_NET_NS_[PID|FD]).Existing user of the newlink handler will use the netns argument (
src_net) to find a link netdevice or to check some other information into the link netns. For example, to find a netdevice, two information are required: an ifindex (usually fromIFLA_LINK) and a netns (this link netns).
Quoted 5 lines
Note: when using
IFLA_LINK_NETNSIDand IFLA_NET_NS_[PID|FD], a user may create a netdevice that stands in netnsX and with its link part in netnsY, by sending a rtnl message from netnsZ.Signed-off-by Nicolas Dichtel <[email protected]>
Applied, thanks.