From patchwork Thu Feb 27 14:47:11 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 3733841 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 3B4EA9F2F7 for ; Thu, 27 Feb 2014 14:48:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 49016201DC for ; Thu, 27 Feb 2014 14:48:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4918C20122 for ; Thu, 27 Feb 2014 14:48:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753012AbaB0Orc (ORCPT ); Thu, 27 Feb 2014 09:47:32 -0500 Received: from mail-ee0-f53.google.com ([74.125.83.53]:40405 "EHLO mail-ee0-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751976AbaB0Or1 (ORCPT ); Thu, 27 Feb 2014 09:47:27 -0500 Received: by mail-ee0-f53.google.com with SMTP id e51so376200eek.40 for ; Thu, 27 Feb 2014 06:47:25 -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:in-reply-to:references; bh=GZwIDS6EGpuEFKN0Cnov/PsrDRzhgPi1g4xq9j+0V8Y=; b=VMoKjYBtl+SCzC037chrXbOpY7IrqCW4/tUq2R77GWLEAk0v86gFcaFwyX+emF0xus unRJiQBDuCFzZVQ8IzRN+48sAb/hvpTwrUVUK+h6ArGjU8BCLXi3208i2yT68Pbfj/8r 5OrfZ0RhyFSHnpk5k6UWSbCQl3opOEIxncycg8PJKEXfvq8lCl7t9ncF+cTUmDmN+IhP Rnf0+uOcZim9ls6jLx8xJtpgTsuGa/YyiFJJHKPgteVbWbvoEhJ8vmObpW8aVV/pTSyZ /0LuGuxmPQ1VIbI3GOiLwNoexDah1JjsBCbN/MJ6GKZw6OcdFR8AywsVsk5nwGMgT4gt qSBg== X-Received: by 10.14.176.66 with SMTP id a42mr10083071eem.101.1393512445862; Thu, 27 Feb 2014 06:47:25 -0800 (PST) Received: from david-tp.localdomain (stgt-5f72aa4f.pool.mediaWays.net. [95.114.170.79]) by mx.google.com with ESMTPSA id 43sm17691835eeh.13.2014.02.27.06.47.24 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Feb 2014 06:47:25 -0800 (PST) From: David Herrmann To: netdev@vger.kernel.org Cc: "David S. Miller" , Kay Sievers , Tom Gundersen , Johannes berg , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, David Herrmann Subject: [PATCH 1/4] net: add name_assign_type netdev attribute Date: Thu, 27 Feb 2014 15:47:11 +0100 Message-Id: <1393512434-1325-2-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 1.9.0 In-Reply-To: <1393512434-1325-1-git-send-email-dh.herrmann@gmail.com> References: <1393512434-1325-1-git-send-email-dh.herrmann@gmail.com> 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, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable 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 The name_assign_type attribute gives hints where the interface name of a given net-device comes from. Three different values are currently defined: NET_NAME_ENUM: This is the default. The ifname is provided by the kernel with an enumerated suffix. Names may be reused and unstable. NET_NAME_USER: The ifname was provided by user-space during net-device setup. NET_NAME_RENAMED: The net-device has been renamed via RTNL. Once this type is set, it cannot change again. This attribute comes in handy for reliable net-device names. If an ifname is provided by user-space, we can safely assume that the naming-policy avoids reuse and is stable. Only if it was set by the kernel, the interfaces might need to be renamed. The NET_NAME_RENAMED value allows us to detect whether some-one else already renamed the device, in which case we shouldn't touch it again. The NET_NAME_USER value allows us to detect whether some other naming policy created the device, in which case there's no need to rename it. The most significant use-case is to detect virtual wifi-P2P devices, which are named by wpa_supplicant et al. We shouldn't rename them as wpas already provides a proper naming-policy. Note that this patch only provides the core infrastructure. The different net-dev types need to be manually fixed to use NET_NAME_USER instead of the default (NET_NAME_ENUM). NET_NAME_ENUM is the least restrictive, though, so it seems safe to use it as fallback for non-converted net-dev types. Signed-off-by: David Herrmann --- include/linux/netdevice.h | 6 ++++++ net/core/dev.c | 7 +++++++ net/core/net-sysfs.c | 2 ++ net/core/rtnetlink.c | 2 ++ 4 files changed, 17 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index e8eeebd..d3a11c8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -74,6 +74,11 @@ void netdev_set_default_ethtool_ops(struct net_device *dev, #define NET_RX_SUCCESS 0 /* keep 'em coming, baby */ #define NET_RX_DROP 1 /* packet dropped */ +/* interface name assignment types */ +#define NET_NAME_ENUM 0 /* enumerated by kernel (default) */ +#define NET_NAME_USER 1 /* provided by user-space */ +#define NET_NAME_RENAMED 2 /* renamed by user-space */ + /* * Transmit return codes: transmit return codes originate from three different * namespaces: @@ -1165,6 +1170,7 @@ struct net_device { * of the interface. */ char name[IFNAMSIZ]; + unsigned char name_assign_type; /* name assignment type */ /* device name hash chain, please keep it close to name[] */ struct hlist_node name_hlist; diff --git a/net/core/dev.c b/net/core/dev.c index b1b0c8d..3608fb2 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -1083,6 +1083,7 @@ static int dev_get_valid_name(struct net *net, int dev_change_name(struct net_device *dev, const char *newname) { char oldname[IFNAMSIZ]; + unsigned char old_assign_type; int err = 0; int ret; struct net *net; @@ -1109,10 +1110,14 @@ int dev_change_name(struct net_device *dev, const char *newname) return err; } + old_assign_type = dev->name_assign_type; + dev->name_assign_type = NET_NAME_RENAMED; + rollback: ret = device_rename(&dev->dev, dev->name); if (ret) { memcpy(dev->name, oldname, IFNAMSIZ); + dev->name_assign_type = old_assign_type; write_seqcount_end(&devnet_rename_seq); return ret; } @@ -1141,6 +1146,8 @@ rollback: write_seqcount_begin(&devnet_rename_seq); memcpy(dev->name, oldname, IFNAMSIZ); memcpy(oldname, newname, IFNAMSIZ); + dev->name_assign_type = old_assign_type; + old_assign_type = NET_NAME_RENAMED; goto rollback; } else { pr_err("%s: name change rollback failed: %d\n", diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c index 9388624..72a8ce5 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -104,6 +104,7 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, } NETDEVICE_SHOW_RO(dev_id, fmt_hex); +NETDEVICE_SHOW_RO(name_assign_type, fmt_dec); NETDEVICE_SHOW_RO(addr_assign_type, fmt_dec); NETDEVICE_SHOW_RO(addr_len, fmt_dec); NETDEVICE_SHOW_RO(iflink, fmt_dec); @@ -375,6 +376,7 @@ static struct attribute *net_class_attrs[] = { &dev_attr_dev_id.attr, &dev_attr_iflink.attr, &dev_attr_ifindex.attr, + &dev_attr_name_assign_type.attr, &dev_attr_addr_assign_type.attr, &dev_attr_addr_len.attr, &dev_attr_link_mode.attr, diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 1a0dac2..e10baa0 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1962,6 +1962,8 @@ replay: } dev->ifindex = ifm->ifi_index; + if (tb[IFLA_IFNAME]) + dev->name_assign_type = NET_NAME_USER; if (ops->newlink) { err = ops->newlink(net, dev, tb, data);