* [PATCH net-next 1/2] netns: define extack error msg for nsis cmds
@ 2017-06-09 12:41 Nicolas Dichtel
2017-06-09 12:41 ` [PATCH net-next 2/2] netns: fix error code when the nsid is already used Nicolas Dichtel
2017-06-10 19:59 ` [PATCH net-next 1/2] netns: define extack error msg for nsis cmds David Miller
0 siblings, 2 replies; 4+ messages in thread
From: Nicolas Dichtel @ 2017-06-09 12:41 UTC (permalink / raw)
To: davem; +Cc: netdev, Nicolas Dichtel, Jamal Hadi Salim
It helps the user to identify errors.
CC: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
net/core/net_namespace.c | 42 +++++++++++++++++++++++++++++++++---------
1 file changed, 33 insertions(+), 9 deletions(-)
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 26bbfababff2..1f60c180e2de 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -596,6 +596,7 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
{
struct net *net = sock_net(skb->sk);
struct nlattr *tb[NETNSA_MAX + 1];
+ struct nlattr *nla;
struct net *peer;
int nsid, err;
@@ -603,23 +604,35 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
rtnl_net_policy, extack);
if (err < 0)
return err;
- if (!tb[NETNSA_NSID])
+ if (!tb[NETNSA_NSID]) {
+ NL_SET_ERR_MSG(extack, "nsid is missing");
return -EINVAL;
+ }
nsid = nla_get_s32(tb[NETNSA_NSID]);
- if (tb[NETNSA_PID])
+ if (tb[NETNSA_PID]) {
peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
- else if (tb[NETNSA_FD])
+ nla = tb[NETNSA_PID];
+ } else if (tb[NETNSA_FD]) {
peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
- else
+ nla = tb[NETNSA_FD];
+ } else {
+ NL_SET_ERR_MSG(extack, "Peer netns reference is missing");
return -EINVAL;
- if (IS_ERR(peer))
+ }
+ if (IS_ERR(peer)) {
+ NL_SET_BAD_ATTR(extack, nla);
+ NL_SET_ERR_MSG(extack, "Peer netns reference is invalid");
return PTR_ERR(peer);
+ }
spin_lock_bh(&net->nsid_lock);
if (__peernet2id(net, peer) >= 0) {
spin_unlock_bh(&net->nsid_lock);
err = -EEXIST;
+ NL_SET_BAD_ATTR(extack, nla);
+ NL_SET_ERR_MSG(extack,
+ "Peer netns already has a nsid assigned");
goto out;
}
@@ -628,6 +641,9 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
if (err >= 0) {
rtnl_net_notifyid(net, RTM_NEWNSID, err);
err = 0;
+ } else if (err == -ENOSPC && nsid >= 0) {
+ NL_SET_BAD_ATTR(extack, tb[NETNSA_NSID]);
+ NL_SET_ERR_MSG(extack, "The specified nsid is already used");
}
out:
put_net(peer);
@@ -670,6 +686,7 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh,
{
struct net *net = sock_net(skb->sk);
struct nlattr *tb[NETNSA_MAX + 1];
+ struct nlattr *nla;
struct sk_buff *msg;
struct net *peer;
int err, id;
@@ -678,15 +695,22 @@ static int rtnl_net_getid(struct sk_buff *skb, struct nlmsghdr *nlh,
rtnl_net_policy, extack);
if (err < 0)
return err;
- if (tb[NETNSA_PID])
+ if (tb[NETNSA_PID]) {
peer = get_net_ns_by_pid(nla_get_u32(tb[NETNSA_PID]));
- else if (tb[NETNSA_FD])
+ nla = tb[NETNSA_PID];
+ } else if (tb[NETNSA_FD]) {
peer = get_net_ns_by_fd(nla_get_u32(tb[NETNSA_FD]));
- else
+ nla = tb[NETNSA_FD];
+ } else {
+ NL_SET_ERR_MSG(extack, "Peer netns reference is missing");
return -EINVAL;
+ }
- if (IS_ERR(peer))
+ if (IS_ERR(peer)) {
+ NL_SET_BAD_ATTR(extack, nla);
+ NL_SET_ERR_MSG(extack, "Peer netns reference is invalid");
return PTR_ERR(peer);
+ }
msg = nlmsg_new(rtnl_net_get_size(), GFP_KERNEL);
if (!msg) {
--
2.8.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net-next 2/2] netns: fix error code when the nsid is already used
2017-06-09 12:41 [PATCH net-next 1/2] netns: define extack error msg for nsis cmds Nicolas Dichtel
@ 2017-06-09 12:41 ` Nicolas Dichtel
2017-06-10 19:59 ` David Miller
2017-06-10 19:59 ` [PATCH net-next 1/2] netns: define extack error msg for nsis cmds David Miller
1 sibling, 1 reply; 4+ messages in thread
From: Nicolas Dichtel @ 2017-06-09 12:41 UTC (permalink / raw)
To: davem; +Cc: netdev, Nicolas Dichtel, Jamal Hadi Salim
When the user tries to assign a specific nsid, idr_alloc() is called with
the range [nsid, nsid+1]. If this nsid is already used, idr_alloc() returns
ENOSPC (No space left on device). In our case, it's better to return
EEXIST to make it clear that the nsid is not available.
CC: Jamal Hadi Salim <jhs@mojatatu.com>
Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
---
net/core/net_namespace.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
index 1f60c180e2de..2178db8e47cd 100644
--- a/net/core/net_namespace.c
+++ b/net/core/net_namespace.c
@@ -642,6 +642,7 @@ static int rtnl_net_newid(struct sk_buff *skb, struct nlmsghdr *nlh,
rtnl_net_notifyid(net, RTM_NEWNSID, err);
err = 0;
} else if (err == -ENOSPC && nsid >= 0) {
+ err = -EEXIST;
NL_SET_BAD_ATTR(extack, tb[NETNSA_NSID]);
NL_SET_ERR_MSG(extack, "The specified nsid is already used");
}
--
2.8.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next 1/2] netns: define extack error msg for nsis cmds
2017-06-09 12:41 [PATCH net-next 1/2] netns: define extack error msg for nsis cmds Nicolas Dichtel
2017-06-09 12:41 ` [PATCH net-next 2/2] netns: fix error code when the nsid is already used Nicolas Dichtel
@ 2017-06-10 19:59 ` David Miller
1 sibling, 0 replies; 4+ messages in thread
From: David Miller @ 2017-06-10 19:59 UTC (permalink / raw)
To: nicolas.dichtel; +Cc: netdev, jhs
From: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Date: Fri, 9 Jun 2017 14:41:56 +0200
> It helps the user to identify errors.
>
> CC: Jamal Hadi Salim <jhs@mojatatu.com>
> Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Applied, but please in the future always provide a proper "[PATCH 0/N]
" header posting with a patch series.
Thank you.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2017-06-10 19:59 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-06-09 12:41 [PATCH net-next 1/2] netns: define extack error msg for nsis cmds Nicolas Dichtel
2017-06-09 12:41 ` [PATCH net-next 2/2] netns: fix error code when the nsid is already used Nicolas Dichtel
2017-06-10 19:59 ` David Miller
2017-06-10 19:59 ` [PATCH net-next 1/2] netns: define extack error msg for nsis cmds David Miller
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).