From patchwork Mon Jan 12 14:34:05 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Kochan X-Patchwork-Id: 5610751 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 43295C058D for ; Mon, 12 Jan 2015 14:44:40 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 6702D2064B for ; Mon, 12 Jan 2015 14:44:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 7962820649 for ; Mon, 12 Jan 2015 14:44:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751707AbbALOog (ORCPT ); Mon, 12 Jan 2015 09:44:36 -0500 Received: from mail-lb0-f178.google.com ([209.85.217.178]:40346 "EHLO mail-lb0-f178.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751257AbbALOog (ORCPT ); Mon, 12 Jan 2015 09:44:36 -0500 Received: by mail-lb0-f178.google.com with SMTP id u14so17865381lbd.9 for ; Mon, 12 Jan 2015 06:44:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=TSzAaupnqBIRgATQjNNoPf4jyFjcZhSmQj5YW7LOzSQ=; b=Dw0BowLVxO2r735KpFth2/4EaUU5vIT/xsV+olnHhUtCaQJTyVWZkESRDWTGGPKpz3 2ajJL23ncmodU86FE3nC+Imr8zmxryoSOwwI8EvTdyKg7f9NJoHDvRweW2CwJd2ZIVWd ArDF3BD1ITHXsxQ7IL/G/Fo+IEjCyUZYSZAlzeimRGw1qWf0GX7tIgBQWRk4UVG/igO3 rdO4uo/U1+QUKNc2KS8s720BWKOS8vVaqOCxquZRyPrrUYduLe58XrPyATVYcTZru+yy Sv6FqfjZqtn/JsmARU7jaxRZ8WMK5Xz3Q6otUOsoIx80ahEturgTheiq++hvAqEo0E8H USXQ== X-Received: by 10.112.125.202 with SMTP id ms10mr36952343lbb.33.1421073874456; Mon, 12 Jan 2015 06:44:34 -0800 (PST) Received: from angus-think.wlc.globallogic.com ([195.234.75.250]) by mx.google.com with ESMTPSA id k1sm38542laf.19.2015.01.12.06.44.32 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 12 Jan 2015 06:44:33 -0800 (PST) From: Vadim Kochan To: johannes@sipsolutions.net Cc: linux-wireless@vger.kernel.org, Vadim Kochan Subject: [PATCH mac80211-next] nl80211: Allow set network namespace by fd Date: Mon, 12 Jan 2015 16:34:05 +0200 Message-Id: <1421073245-20312-1-git-send-email-vadim4j@gmail.com> X-Mailer: git-send-email 2.1.3 Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Vadim Kochan Added new NL80211_ATTR_NETNS_FD which allows to set namespace via nl80211 by fd. Signed-off-by: Vadim Kochan --- include/uapi/linux/nl80211.h | 2 ++ net/core/net_namespace.c | 1 + 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 a963d48..47757cb 100644 --- a/include/uapi/linux/nl80211.h +++ b/include/uapi/linux/nl80211.h @@ -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, diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c index 7f15517..5d5ee8f 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) return ERR_PTR(-EINVAL); } #endif +EXPORT_SYMBOL_GPL(get_net_ns_by_fd); struct net *get_net_ns_by_pid(pid_t pid) { diff --git a/net/wireless/nl80211.c b/net/wireless/nl80211.c index 7c2ce26..dfa3284 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] = { [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);