From patchwork Fri Jan 23 15:13:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vadim Kochan X-Patchwork-Id: 5694681 X-Patchwork-Delegate: johannes@sipsolutions.net Return-Path: X-Original-To: patchwork-linux-wireless@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id EB0739F358 for ; Fri, 23 Jan 2015 15:24:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 0912F20211 for ; Fri, 23 Jan 2015 15:24:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 17D6E201B9 for ; Fri, 23 Jan 2015 15:24:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753722AbbAWPYa (ORCPT ); Fri, 23 Jan 2015 10:24:30 -0500 Received: from mail-wi0-f176.google.com ([209.85.212.176]:46791 "EHLO mail-wi0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751464AbbAWPYa (ORCPT ); Fri, 23 Jan 2015 10:24:30 -0500 Received: by mail-wi0-f176.google.com with SMTP id em10so3584808wid.3 for ; Fri, 23 Jan 2015 07:24:28 -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=fR6V+d2OI550KhJQ2oRzcTHaBiQQMkBLxgpMKpY696A=; b=tPl4O5U1FD6oUrolp6fMbO25ixQXFmEJEdoIABohSd/4ns65nb2+4LERgcAG2axxUS ZAKGS6zFBvEUUumHk0Jml1cK2vXrj8KCJxom9eE2Z5bMf8OL/RPACRq3K9AGRjnr344d MOjzD55zFljsMDiCg2LEzxO//aNFT27+mK5jLrssymiAYbpLEfa0/nIC8WCilERqtzI9 lDdyk2m8I9bAK0lARHyB5CyKsX9mAP89M+w7cS/3zJ3zQak4dRpCl9ihh/Bwnzd3Nmgv o8jCkgUzfjcxgLhfWzDXmyLRdN3OeDr9XFF2gErzqH5NMDP+WBW3nhl5Kd4z1wykrMzo 3TTg== X-Received: by 10.180.212.113 with SMTP id nj17mr4872891wic.54.1422026668740; Fri, 23 Jan 2015 07:24:28 -0800 (PST) Received: from angus-think.wlc.globallogic.com ([195.234.75.250]) by mx.google.com with ESMTPSA id s9sm2253506wiz.12.2015.01.23.07.24.27 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 23 Jan 2015 07:24:28 -0800 (PST) From: Vadim Kochan To: linux-wireless@vger.kernel.org Cc: Vadim Kochan Subject: [RFC iw next] phy: Allow set netns by fd Date: Fri, 23 Jan 2015 17:13:47 +0200 Message-Id: <1422026027-5806-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 possibility to change network namespace for phy device by network namespace name from /var/run/netns or by absolute file path: iw phy XXX set netns | First iw tries to find given nsname from /var/run/netns or by absoute path (in case if nsname contains "/") and if it failed to open nsname file then iw uses given argument as . Also added missing NL80211 attributes before NL80211_CMD_SET_WIPHY_NETNS. Signed-off-by: Vadim Kochan --- nl80211.h | 6 ++++++ phy.c | 44 ++++++++++++++++++++++++++++++++++++++------ 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/nl80211.h b/nl80211.h index c0383e9..a200a0b 100644 --- a/nl80211.h +++ b/nl80211.h @@ -2072,6 +2072,12 @@ enum nl80211_attrs { NL80211_ATTR_WIPHY_SELF_MANAGED_REG, + NL80211_ATTR_EXT_FEATURES, + + 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/phy.c b/phy.c index aab462d..8d51ed6 100644 --- a/phy.c +++ b/phy.c @@ -2,6 +2,9 @@ #include #include #include +#include +#include +#include #include #include @@ -296,6 +299,24 @@ COMMAND(set, retry, "[short ] [long ]", NL80211_CMD_SET_WIPHY, 0, CIB_PHY, handle_retry, "Set retry limit."); +#ifndef NETNS_RUN_DIR +#define NETNS_RUN_DIR "/var/run/netns" +#endif +int netns_get_fd(const char *name) +{ + char pathbuf[MAXPATHLEN]; + const char *path, *ptr; + + path = name; + ptr = strchr(name, '/'); + if (!ptr) { + snprintf(pathbuf, sizeof(pathbuf), "%s/%s", + NETNS_RUN_DIR, name ); + path = pathbuf; + } + return open(path, O_RDONLY); +} + static int handle_netns(struct nl80211_state *state, struct nl_cb *cb, struct nl_msg *msg, @@ -303,6 +324,7 @@ static int handle_netns(struct nl80211_state *state, enum id_input id) { char *end; + int fd; if (argc != 1) return 1; @@ -310,19 +332,29 @@ static int handle_netns(struct nl80211_state *state, if (!*argv[0]) return 1; - NLA_PUT_U32(msg, NL80211_ATTR_PID, - strtoul(argv[0], &end, 10)); + if ((fd = netns_get_fd(argv[0])) >= 0) { + NLA_PUT_U32(msg, NL80211_ATTR_NETNS_FD, fd); + } else { + NLA_PUT_U32(msg, NL80211_ATTR_PID, + strtoul(argv[0], &end, 10)); + if (*end != '\0') + return 1; - if (*end != '\0') - return 1; + } return 0; + nla_put_failure: return -ENOBUFS; } -COMMAND(set, netns, "", +COMMAND(set, netns, " | ", NL80211_CMD_SET_WIPHY_NETNS, 0, CIB_PHY, handle_netns, - "Put this wireless device into a different network namespace"); + "Put this wireless device into a different network namespace:\n" + " - change network namespace by name from "NETNS_RUN_DIR"\n" + " or by absolute path (man ip-netns)\n" + " - change network namespace by process id\n" + "If file does not exist then given argument is used as \n" + ); static int handle_coverage(struct nl80211_state *state, struct nl_cb *cb,