Commit 317f4810 authored by Nicolas Dichtel's avatar Nicolas Dichtel Committed by David S. Miller

rtnl: allow to create device with IFLA_LINK_NETNSID set

This patch adds the ability to create a netdevice in a specified netns and
then move it into the final netns. In fact, it allows to have a symetry between
get and set rtnl messages.
Signed-off-by: default avatarNicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 1728d4fa
...@@ -1248,6 +1248,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { ...@@ -1248,6 +1248,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = {
[IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN }, [IFLA_PHYS_PORT_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
[IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */ [IFLA_CARRIER_CHANGES] = { .type = NLA_U32 }, /* ignored */
[IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN }, [IFLA_PHYS_SWITCH_ID] = { .type = NLA_BINARY, .len = MAX_PHYS_ITEM_ID_LEN },
[IFLA_LINK_NETNSID] = { .type = NLA_S32 },
}; };
static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = { static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {
...@@ -2021,7 +2022,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2021,7 +2022,7 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
struct nlattr *slave_attr[m_ops ? m_ops->slave_maxtype + 1 : 0]; struct nlattr *slave_attr[m_ops ? m_ops->slave_maxtype + 1 : 0];
struct nlattr **data = NULL; struct nlattr **data = NULL;
struct nlattr **slave_data = NULL; struct nlattr **slave_data = NULL;
struct net *dest_net; struct net *dest_net, *link_net = NULL;
if (ops) { if (ops) {
if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) { if (ops->maxtype && linkinfo[IFLA_INFO_DATA]) {
...@@ -2127,7 +2128,18 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2127,7 +2128,18 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
if (IS_ERR(dest_net)) if (IS_ERR(dest_net))
return PTR_ERR(dest_net); return PTR_ERR(dest_net);
dev = rtnl_create_link(dest_net, ifname, name_assign_type, ops, tb); if (tb[IFLA_LINK_NETNSID]) {
int id = nla_get_s32(tb[IFLA_LINK_NETNSID]);
link_net = get_net_ns_by_id(dest_net, id);
if (!link_net) {
err = -EINVAL;
goto out;
}
}
dev = rtnl_create_link(link_net ? : dest_net, ifname,
name_assign_type, ops, tb);
if (IS_ERR(dev)) { if (IS_ERR(dev)) {
err = PTR_ERR(dev); err = PTR_ERR(dev);
goto out; goto out;
...@@ -2155,9 +2167,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh) ...@@ -2155,9 +2167,16 @@ static int rtnl_newlink(struct sk_buff *skb, struct nlmsghdr *nlh)
} }
} }
err = rtnl_configure_link(dev, ifm); err = rtnl_configure_link(dev, ifm);
if (err < 0) if (err < 0) {
unregister_netdevice(dev); unregister_netdevice(dev);
goto out;
}
if (link_net)
err = dev_change_net_namespace(dev, dest_net, ifname);
out: out:
if (link_net)
put_net(link_net);
put_net(dest_net); put_net(dest_net);
return err; return err;
} }
......
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