netns: returns always an id in __peernet2id()
All callers of this function expect a nsid, not an error. Thus, returns NETNSA_NSID_NOT_ASSIGNED in case of error so that callers don't have to convert the error to NETNSA_NSID_NOT_ASSIGNED. Signed-off-by: Nicolas Dichtel <nicolas.dichtel@6wind.com> Acked-by: Thomas Graf <tgraf@suug.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:
parent
43996fdd9b
commit
109582af18
|
@ -192,10 +192,12 @@ static int __peernet2id(struct net *net, struct net *peer, bool alloc)
|
||||||
if (id > 0)
|
if (id > 0)
|
||||||
return id;
|
return id;
|
||||||
|
|
||||||
if (alloc)
|
if (alloc) {
|
||||||
return alloc_netid(net, peer, -1);
|
id = alloc_netid(net, peer, -1);
|
||||||
|
return id >= 0 ? id : NETNSA_NSID_NOT_ASSIGNED;
|
||||||
|
}
|
||||||
|
|
||||||
return -ENOENT;
|
return NETNSA_NSID_NOT_ASSIGNED;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* This function returns the id of a peer netns. If no id is assigned, one will
|
/* This function returns the id of a peer netns. If no id is assigned, one will
|
||||||
|
@ -204,10 +206,8 @@ static int __peernet2id(struct net *net, struct net *peer, bool alloc)
|
||||||
int peernet2id(struct net *net, struct net *peer)
|
int peernet2id(struct net *net, struct net *peer)
|
||||||
{
|
{
|
||||||
bool alloc = atomic_read(&peer->count) == 0 ? false : true;
|
bool alloc = atomic_read(&peer->count) == 0 ? false : true;
|
||||||
int id;
|
|
||||||
|
|
||||||
id = __peernet2id(net, peer, alloc);
|
return __peernet2id(net, peer, alloc);
|
||||||
return id >= 0 ? id : NETNSA_NSID_NOT_ASSIGNED;
|
|
||||||
}
|
}
|
||||||
EXPORT_SYMBOL(peernet2id);
|
EXPORT_SYMBOL(peernet2id);
|
||||||
|
|
||||||
|
@ -554,13 +554,10 @@ static int rtnl_net_fill(struct sk_buff *skb, u32 portid, u32 seq, int flags,
|
||||||
rth = nlmsg_data(nlh);
|
rth = nlmsg_data(nlh);
|
||||||
rth->rtgen_family = AF_UNSPEC;
|
rth->rtgen_family = AF_UNSPEC;
|
||||||
|
|
||||||
if (nsid >= 0) {
|
if (nsid >= 0)
|
||||||
id = nsid;
|
id = nsid;
|
||||||
} else {
|
else
|
||||||
id = __peernet2id(net, peer, false);
|
id = __peernet2id(net, peer, false);
|
||||||
if (id < 0)
|
|
||||||
id = NETNSA_NSID_NOT_ASSIGNED;
|
|
||||||
}
|
|
||||||
if (nla_put_s32(skb, NETNSA_NSID, id))
|
if (nla_put_s32(skb, NETNSA_NSID, id))
|
||||||
goto nla_put_failure;
|
goto nla_put_failure;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue