diff options
| author | Vadim Kochan <vadim4j@gmail.com> | 2015-01-12 09:34:05 -0500 |
|---|---|---|
| committer | Johannes Berg <johannes.berg@intel.com> | 2015-01-23 04:25:25 -0500 |
| commit | 4b681c82d2f9bef121c912ffcaac89a004af3f2c (patch) | |
| tree | af24f8eb044ffbddd346c3e34cd611963ab760ef | |
| parent | fa7e1fbcb52cc9efab394526a566d80fb31529bb (diff) | |
nl80211: Allow set network namespace by fd
Added new NL80211_ATTR_NETNS_FD which allows to
set namespace via nl80211 by fd.
Signed-off-by: Vadim Kochan <vadim4j@gmail.com>
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
| -rw-r--r-- | include/uapi/linux/nl80211.h | 2 | ||||
| -rw-r--r-- | net/core/net_namespace.c | 1 | ||||
| -rw-r--r-- | net/wireless/nl80211.c | 16 |
3 files changed, 14 insertions, 5 deletions
diff --git a/include/uapi/linux/nl80211.h b/include/uapi/linux/nl80211.h index f52797a90816..f68532b015db 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h | |||
| @@ -2098,6 +2098,8 @@ enum nl80211_attrs { | |||
| 2098 | 2098 | ||
| 2099 | NL80211_ATTR_SURVEY_RADIO_STATS, | 2099 | NL80211_ATTR_SURVEY_RADIO_STATS, |
| 2100 | 2100 | ||
| 2101 | NL80211_ATTR_NETNS_FD, | ||
| 2102 | |||
| 2101 | /* add attributes here, update the policy in nl80211.c */ | 2103 | /* add attributes here, update the policy in nl80211.c */ |
| 2102 | 2104 | ||
| 2103 | __NL80211_ATTR_AFTER_LAST, | 2105 | __NL80211_ATTR_AFTER_LAST, |
diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 7f155175bba8..5d5ee8f3e4ff 100644 --- a/net/core/net_namespace.c +++ b/net/core/net_namespace.c | |||
| @@ -361,6 +361,7 @@ struct net *get_net_ns_by_fd(int fd) | |||
| 361 | return ERR_PTR(-EINVAL); | 361 | return ERR_PTR(-EINVAL); |
| 362 | } | 362 | } |
| 363 | #endif | 363 | #endif |
| 364 | EXPORT_SYMBOL_GPL(get_net_ns_by_fd); | ||
| 364 | 365 | ||
| 365 | struct net *get_net_ns_by_pid(pid_t pid) | 366 | struct net *get_net_ns_by_pid(pid_t pid) |
| 366 | { | 367 | { |
diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index c5661c5ad8f3..c64100ec79e3 100644 --- a/net/wireless/nl80211.c +++ b/net/wireless/nl80211.c | |||
| @@ -397,6 +397,7 @@ static const struct nla_policy nl80211_policy[NUM_NL80211_ATTR] = { | |||
| 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, | 397 | [NL80211_ATTR_SMPS_MODE] = { .type = NLA_U8 }, |
| 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, | 398 | [NL80211_ATTR_MAC_MASK] = { .len = ETH_ALEN }, |
| 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, | 399 | [NL80211_ATTR_WIPHY_SELF_MANAGED_REG] = { .type = NLA_FLAG }, |
| 400 | [NL80211_ATTR_NETNS_FD] = { .type = NLA_U32 }, | ||
| 400 | }; | 401 | }; |
| 401 | 402 | ||
| 402 | /* policy for the key attributes */ | 403 | /* policy for the key attributes */ |
| @@ -7762,14 +7763,19 @@ static int nl80211_wiphy_netns(struct sk_buff *skb, struct genl_info *info) | |||
| 7762 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; | 7763 | struct cfg80211_registered_device *rdev = info->user_ptr[0]; |
| 7763 | struct net *net; | 7764 | struct net *net; |
| 7764 | int err; | 7765 | int err; |
| 7765 | u32 pid; | ||
| 7766 | 7766 | ||
| 7767 | if (!info->attrs[NL80211_ATTR_PID]) | 7767 | if (info->attrs[NL80211_ATTR_PID]) { |
| 7768 | return -EINVAL; | 7768 | u32 pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); |
| 7769 | |||
| 7770 | net = get_net_ns_by_pid(pid); | ||
| 7771 | } else if (info->attrs[NL80211_ATTR_NETNS_FD]) { | ||
| 7772 | u32 fd = nla_get_u32(info->attrs[NL80211_ATTR_NETNS_FD]); | ||
| 7769 | 7773 | ||
| 7770 | pid = nla_get_u32(info->attrs[NL80211_ATTR_PID]); | 7774 | net = get_net_ns_by_fd(fd); |
| 7775 | } else { | ||
| 7776 | return -EINVAL; | ||
| 7777 | } | ||
| 7771 | 7778 | ||
| 7772 | net = get_net_ns_by_pid(pid); | ||
| 7773 | if (IS_ERR(net)) | 7779 | if (IS_ERR(net)) |
| 7774 | return PTR_ERR(net); | 7780 | return PTR_ERR(net); |
| 7775 | 7781 | ||
