Skip to contentSkip to conversation

nl80211: Allow set network namespace by fd

PATCH Applied Vadim Kochan 2 participants 8 messages Jan 12, 2015 – Jan 23, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nl80211: Allow set network namespace by fd

From: Vadim Kochan <[email protected]>

Added new NL80211_ATTR_NETNS_FD which allows to
set namespace via nl80211 by fd.

---
 include/uapi/linux/nl80211.h |  2 ++
 net/core/net_namespace.c     |  1 +
 net/wireless/nl80211.c       | 16 +++++++++++-----
 3 files changed, 14 insertions(+), 5 deletions(-)
include/uapi/linux/nl80211.h +2 -0
index a963d48..47757cb 100644
@@ -2098,6 +2098,8 @@ enum nl80211_attrs {
 
 	NL80211_ATTR_SURVEY_RADIO_STATS,
 
+	NL80211_ATTR_NETNS_FD,
+
 	/* add attributes here, update the policy in nl80211.c */
 
 	__NL80211_ATTR_AFTER_LAST,
net/core/net_namespace.c +1 -0
index 7f15517..5d5ee8f 100644
@@ -361,6 +361,7 @@ struct net *get_net_ns_by_fd(int fd)
 	return ERR_PTR(-EINVAL);
 }
 #endif
+EXPORT_SYMBOL_GPL(get_net_ns_by_fd);
 
 struct net *get_net_ns_by_pid(pid_t pid)
 {
net/wireless/nl80211.c +11 -5
index 7c2ce26..dfa3284 100644
@@ -397,6 +397,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = {
 	[NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 },
 	[NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN },
 	[NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG },
+	[NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 },
 };
 
 /* policy for the key attributes */
@@ -7744,14 +7745,19 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info)
 	struct cfg80211_registered_device *rdev = info->user_ptr[0];
 	struct net *net;
 	int err;
-	u32 pid;
 
-	if (!info->attrs[NL80211_ATTR_PID])
-		return -EINVAL;
+	if (info->attrs[NL80211_ATTR_PID]) {
+		u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
+
+		net = get_net_ns_by_pid(pid);
+	} else if (info->attrs[NL80211_ATTR_NETNS_FD]) {
+		u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]);
 
-	pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]);
+		net = get_net_ns_by_fd(fd);
+	} else {
+		return -EINVAL;
+	}
 
-	net = get_net_ns_by_pid(pid);
 	if (IS_ERR(net))
 		return PTR_ERR(net);
 
Signature · 1 line
2.1.3
maintainer
#1 lore raw

net/core/net_namespace.c struct net *get_net_ns_by_fd(int fd) · line 364

Quoted 7 lines · Vadim Kochan
net/core/net_namespace.c +1 -0
@@ -361,6 +361,7 @@ struct net *get_net_ns_by_fd(int fd)
 	return ERR_PTR(-EINVAL);
 }
 #endif
+EXPORT_SYMBOL_GPL(get_net_ns_by_fd);

Does this seem OK? Vadim is adding support for using the ns-by-fd in nl80211, which can be a module as part of cfg80211.

johannes

#2 lore raw
Quoted 13 lines · Johannes Berg

net/core/net_namespace.c struct net *get_net_ns_by_fd(int fd) · line 364

Quoted 7 lines · Vadim Kochan
net/core/net_namespace.c +1 -0
@@ -361,6 +361,7 @@ struct net *get_net_ns_by_fd(int fd)
 	return ERR_PTR(-EINVAL);
 }
 #endif
+EXPORT_SYMBOL_GPL(get_net_ns_by_fd);

Does this seem OK? Vadim is adding support for using the ns-by-fd in nl80211, which can be a module as part of cfg80211.

Quoted 2 lines

johannes

PING ... in case if this email was missed ...

Thanks,

#3 lore raw
Quoted 14 lines · Vadim Kochan
Quoted 13 lines · Johannes Berg

net/core/net_namespace.c struct net *get_net_ns_by_fd(int fd) · line 364

Quoted 7 lines · Vadim Kochan
net/core/net_namespace.c +1 -0
@@ -361,6 +361,7 @@ struct net *get_net_ns_by_fd(int fd)
 	return ERR_PTR(-EINVAL);
 }
 #endif
+EXPORT_SYMBOL_GPL(get_net_ns_by_fd);

Does this seem OK? Vadim is adding support for using the ns-by-fd in nl80211, which can be a module as part of cfg80211.

Quoted 5 lines
Quoted 2 lines

johannes

PING ... in case if this email was missed ...

Thanks,

Hi Johannes,

Does it mean that patch will be rejected in case if no one answer on this ?:)

Thanks,

maintainer
#4 lore raw
Quoted 17 lines · Vadim Kochan
Quoted 16 lines · Vadim Kochan
Quoted 15 lines · Johannes Berg

net/core/net_namespace.c struct net *get_net_ns_by_fd(int fd) · line 364

Quoted 7 lines · Vadim Kochan
net/core/net_namespace.c +1 -0
@@ -361,6 +361,7 @@ struct net *get_net_ns_by_fd(int fd)
 	return ERR_PTR(-EINVAL);
 }
 #endif
+EXPORT_SYMBOL_GPL(get_net_ns_by_fd);

Does this seem OK? Vadim is adding support for using the ns-by-fd in nl80211, which can be a module as part of cfg80211.

johannes

Quoted 8 lines
Quoted 3 lines

PING ... in case if this email was missed ...

Thanks,

Hi Johannes,

Does it mean that patch will be rejected in case if no one answer on this ?:)

Nah, I'll eventually take it :)

johannes

#6 lore raw
Quoted 10 lines · Johannes Berg
Quoted 4 lines · Vadim Kochan

From: Vadim Kochan <[email protected]>

Added new NL80211_ATTR_NETNS_FD which allows to
set namespace via nl80211 by fd.

Applied.

johannes

Hi,

I have changes for 'iw' for setting netns by name in the same way as it works in 'ip link set dev XXX netns <NAME>', so it uses /var/run/netns path by default or absolute path if it sees "/" in the netns name.

So may be I will send the patch as RFC just to see a feedback ?

Thanks,

maintainer
#7 lore raw
Quoted 5 lines · Vadim Kochan

I have changes for 'iw' for setting netns by name in the same way as it works in 'ip link set dev XXX netns <NAME>', so it uses /var/run/netns path by default or absolute path if it sees "/" in the netns name.

So may be I will send the patch as RFC just to see a feedback ?

Sure, sounds good.

johannes