From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
To: davem@davemloft.net
Cc: netdev@vger.kernel.org, Nicolas Dichtel <nicolas.dichtel@6wind.com>
Subject: [PATCH net-next 2/2] netns/rtnl: return the new nsid to the user
Date: Mon, 30 Sep 2019 18:02:14 +0200 [thread overview]
Message-ID: <20190930160214.4512-3-nicolas.dichtel@6wind.com> (raw)
In-Reply-To: <20190930160214.4512-1-nicolas.dichtel@6wind.com>
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.dichtel@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
next prev parent reply other threads:[~2019-09-30 16:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-09-30 16:02 [PATCH net-next 0/2] Ease nsid allocation Nicolas Dichtel
2019-09-30 16:02 ` [PATCH net-next 1/2] netns: move rtnl_net_get_size() and rtnl_net_fill() Nicolas Dichtel
2019-09-30 16:02 ` Nicolas Dichtel [this message]
2019-10-02 1:20 ` [PATCH net-next 0/2] Ease nsid allocation David Miller
2019-10-02 8:46 ` Nicolas Dichtel
2019-10-02 14:58 ` David Miller
2019-10-03 16:19 ` Guillaume Nault
2019-10-04 15:45 ` Nicolas Dichtel
2019-10-08 23:00 ` Guillaume Nault
2019-10-07 11:58 ` [PATCH net] netns: fix NLM_F_ECHO mechanism for RTM_NEWNSID Nicolas Dichtel
2019-10-08 23:10 ` Guillaume Nault
2019-10-09 8:07 ` Nicolas Dichtel
2019-10-09 13:48 ` Guillaume Nault
2019-10-09 9:19 ` [PATCH net v2] " Nicolas Dichtel
2019-10-09 13:48 ` Guillaume Nault
2019-10-10 4:06 ` Jakub Kicinski
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190930160214.4512-3-nicolas.dichtel@6wind.com \
--to=nicolas.dichtel@6wind.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).