When the user asks for a new nsid, he can let the kernel choose it (by providing -1 in NETNSA_NSID). In this case, it's useful to answer to the netlink message with the chosen nsid.
Signed-off-by: Nicolas Dichtel <nicolas.dich...@6wind.com> --- net/core/net_namespace.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 8f5fa5d5becd..266d095296f3 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c @@ -810,8 +810,32 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh, err = alloc_netid(net, peer, nsid); spin_unlock_bh(&net->nsid_lock); if (err >= 0) { + struct net_fill_args fillargs = { + .portid = NETLINK_CB(skb).portid, + .seq = nlh->nlmsg_seq, + .cmd = RTM_NEWNSID, + .nsid = err, + }; + struct sk_buff *msg; + + /* The id has been allocated, thus first notify listeners */ rtnl_net_notifyid(net, RTM_NEWNSID, err); - err = 0; + + /* Then, try to send the new nsid to the sender */ + msg = nlmsg_new(rtnl_net_get_size(), GFP_KERNEL); + if (!msg) { + err = -ENOMEM; + NL_SET_ERR_MSG(extack, "Unable to alloc reply msg"); + goto out; + } + + err = rtnl_net_fill(msg, &fillargs); + if (err < 0) { + kfree_skb(msg); + goto out; + } + + err = rtnl_unicast(msg, net, NETLINK_CB(skb).portid); } else if (err == -ENOSPC && nsid >= 0) { err = -EEXIST; NL_SET_BAD_ATTR(extack, tb[NETNSA_NSID]); -- 2.23.0