Skip to content

Commit c383edc

Browse files
braunerdavem330
authored andcommitted
rtnetlink: add rtnl_get_net_ns_capable()
get_target_net() will be used in follow-up patches in ipv{4,6} codepaths to retrieve network namespaces based on network namespace identifiers. So remove the static declaration and export in the rtnetlink header. Also, rename it to rtnl_get_net_ns_capable() to make it obvious what this function is doing. Export rtnl_get_net_ns_capable() so it can be used when ipv6 is built as a module. Signed-off-by: Christian Brauner <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent d4cc597 commit c383edc

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

include/net/rtnetlink.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ int rtnl_configure_link(struct net_device *dev, const struct ifinfomsg *ifm);
165165

166166
int rtnl_nla_parse_ifla(struct nlattr **tb, const struct nlattr *head, int len,
167167
struct netlink_ext_ack *exterr);
168+
struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid);
168169

169170
#define MODULE_ALIAS_RTNL_LINK(kind) MODULE_ALIAS("rtnl-link-" kind)
170171

net/core/rtnetlink.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,15 @@ static bool link_dump_filtered(struct net_device *dev,
18451845
return false;
18461846
}
18471847

1848-
static struct net *get_target_net(struct sock *sk, int netnsid)
1848+
/**
1849+
* rtnl_get_net_ns_capable - Get netns if sufficiently privileged.
1850+
* @sk: netlink socket
1851+
* @netnsid: network namespace identifier
1852+
*
1853+
* Returns the network namespace identified by netnsid on success or an error
1854+
* pointer on failure.
1855+
*/
1856+
struct net *rtnl_get_net_ns_capable(struct sock *sk, int netnsid)
18491857
{
18501858
struct net *net;
18511859

@@ -1862,6 +1870,7 @@ static struct net *get_target_net(struct sock *sk, int netnsid)
18621870
}
18631871
return net;
18641872
}
1873+
EXPORT_SYMBOL_GPL(rtnl_get_net_ns_capable);
18651874

18661875
static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
18671876
{
@@ -1897,7 +1906,7 @@ static int rtnl_dump_ifinfo(struct sk_buff *skb, struct netlink_callback *cb)
18971906
ifla_policy, NULL) >= 0) {
18981907
if (tb[IFLA_IF_NETNSID]) {
18991908
netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
1900-
tgt_net = get_target_net(skb->sk, netnsid);
1909+
tgt_net = rtnl_get_net_ns_capable(skb->sk, netnsid);
19011910
if (IS_ERR(tgt_net)) {
19021911
tgt_net = net;
19031912
netnsid = -1;
@@ -2765,7 +2774,7 @@ static int rtnl_dellink(struct sk_buff *skb, struct nlmsghdr *nlh,
27652774

27662775
if (tb[IFLA_IF_NETNSID]) {
27672776
netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
2768-
tgt_net = get_target_net(NETLINK_CB(skb).sk, netnsid);
2777+
tgt_net = rtnl_get_net_ns_capable(NETLINK_CB(skb).sk, netnsid);
27692778
if (IS_ERR(tgt_net))
27702779
return PTR_ERR(tgt_net);
27712780
}
@@ -3175,7 +3184,7 @@ static int rtnl_getlink(struct sk_buff *skb, struct nlmsghdr *nlh,
31753184

31763185
if (tb[IFLA_IF_NETNSID]) {
31773186
netnsid = nla_get_s32(tb[IFLA_IF_NETNSID]);
3178-
tgt_net = get_target_net(NETLINK_CB(skb).sk, netnsid);
3187+
tgt_net = rtnl_get_net_ns_capable(NETLINK_CB(skb).sk, netnsid);
31793188
if (IS_ERR(tgt_net))
31803189
return PTR_ERR(tgt_net);
31813190
}

0 commit comments

Comments
 (0)