net: Allow setting the network namespace by fd
Take advantage of the new abstraction and allow network devices to be placed in any network namespace that we have a fd to talk about. Acked-by: David S. Miller <davem@davemloft.net> Acked-by: Daniel Lezcano <daniel.lezcano@free.fr> Signed-off-by: Eric W. Biederman <ebiederm@xmission.com>
This commit is contained in:
@@ -1043,6 +1043,7 @@ const struct nla_policy ifla_policy[IFLA_MAX+1] = {
|
||||
[IFLA_LINKMODE] = { .type = NLA_U8 },
|
||||
[IFLA_LINKINFO] = { .type = NLA_NESTED },
|
||||
[IFLA_NET_NS_PID] = { .type = NLA_U32 },
|
||||
[IFLA_NET_NS_FD] = { .type = NLA_U32 },
|
||||
[IFLA_IFALIAS] = { .type = NLA_STRING, .len = IFALIASZ-1 },
|
||||
[IFLA_VFINFO_LIST] = {. type = NLA_NESTED },
|
||||
[IFLA_VF_PORTS] = { .type = NLA_NESTED },
|
||||
@@ -1091,6 +1092,8 @@ struct net *rtnl_link_get_net(struct net *src_net, struct nlattr *tb[])
|
||||
*/
|
||||
if (tb[IFLA_NET_NS_PID])
|
||||
net = get_net_ns_by_pid(nla_get_u32(tb[IFLA_NET_NS_PID]));
|
||||
else if (tb[IFLA_NET_NS_FD])
|
||||
net = get_net_ns_by_fd(nla_get_u32(tb[IFLA_NET_NS_FD]));
|
||||
else
|
||||
net = get_net(src_net);
|
||||
return net;
|
||||
@@ -1221,7 +1224,7 @@ static int do_setlink(struct net_device *dev, struct ifinfomsg *ifm,
|
||||
int send_addr_notify = 0;
|
||||
int err;
|
||||
|
||||
if (tb[IFLA_NET_NS_PID]) {
|
||||
if (tb[IFLA_NET_NS_PID] || tb[IFLA_NET_NS_FD]) {
|
||||
struct net *net = rtnl_link_get_net(dev_net(dev), tb);
|
||||
if (IS_ERR(net)) {
|
||||
err = PTR_ERR(net);
|
||||
|
Reference in New Issue
Block a user