From patchwork Wed Apr 2 09:58:23 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Herrmann X-Patchwork-Id: 336301 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id D2C3E1400E0 for ; Wed, 2 Apr 2014 20:59:42 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758235AbaDBJ6x (ORCPT ); Wed, 2 Apr 2014 05:58:53 -0400 Received: from mail-bk0-f49.google.com ([209.85.214.49]:54801 "EHLO mail-bk0-f49.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758197AbaDBJ6t (ORCPT ); Wed, 2 Apr 2014 05:58:49 -0400 Received: by mail-bk0-f49.google.com with SMTP id my13so11195bkb.22 for ; Wed, 02 Apr 2014 02:58:47 -0700 (PDT) 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=blNO1hTjGc7q70j6d6h6gghv8mYth7GBT8q+Bz8siCM=; b=qttRS5BPUMI9py+NnKg2hsDdhn+Mnnp5RZ76ahXtuUYQJRHVxMd1guA2o9jCFM9Wgg 1Szw+GucRls7Z73hqI+lz11OIcAK/mTmvm9oNauFpseasNCHI/vMTSRYFkwNtEVzTkf7 kyfXCD3J9ZuPBxud/F3XKG4MfXf+/BkUrQnNDxuLUrdf5ZkdeGalOv8Gs45ilUt6SRBA YzmO5YSQb6Rgm5OF0hzdkoF6QXBFE9faxaVAHAeRLhoD9fR46owAnjFt6GlRsiX+aUNt dspVd/4BmPjtZX3Lztx/VshYK5UT2z8AU80goUaw6psjyDgEQ6/ap9Deo47Ez03msDm0 0/rA== X-Received: by 10.204.168.206 with SMTP id v14mr193986bky.26.1396432727452; Wed, 02 Apr 2014 02:58:47 -0700 (PDT) Received: from localhost.localdomain (nat.nue.novell.com. [195.135.221.2]) by mx.google.com with ESMTPSA id el11sm1677744bkb.8.2014.04.02.02.58.45 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 02 Apr 2014 02:58:46 -0700 (PDT) From: David Herrmann To: netdev@vger.kernel.org Cc: "David S. Miller" , Tom Gundersen , Johannes berg , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Kay Sievers , David Herrmann Subject: [PATCH v6 1/4] net: add name_assign_type netdev attribute Date: Wed, 2 Apr 2014 11:58:23 +0200 Message-Id: <1396432706-14470-2-git-send-email-dh.herrmann@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1396432706-14470-1-git-send-email-dh.herrmann@gmail.com> References: <1396432706-14470-1-git-send-email-dh.herrmann@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Acked-by: Tom Gundersen Acked-by: Kay Sievers --- include/linux/netdevice.h | 2 ++ include/uapi/linux/netdevice.h | 4 ++++ net/core/dev.c | 7 +++++++ net/core/net-sysfs.c | 2 ++ net/core/rtnetlink.c | 2 ++ 5 files changed, 17 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 775cc95..e016edd 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1372,6 +1372,8 @@ struct net_device { struct kset *queues_kset; #endif + unsigned char name_assign_type; /* name assignment type */ + bool uc_promisc; unsigned int promiscuity; unsigned int allmulti; diff --git a/include/uapi/linux/netdevice.h b/include/uapi/linux/netdevice.h index fdfbd1c..af50a04 100644 --- a/include/uapi/linux/netdevice.h +++ b/include/uapi/linux/netdevice.h @@ -36,6 +36,10 @@ /* Initial net device group. All devices belong to group 0 by default. */ #define INIT_NETDEV_GROUP 0 +/* interface name assignment types (sysfs name_assign_type attribute) */ +#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 */ /* Media selection options. */ diff --git a/net/core/dev.c b/net/core/dev.c index 48d81e4..b901aaa 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 4623962..a39ae01 100644 --- a/net/core/net-sysfs.c +++ b/net/core/net-sysfs.c @@ -105,6 +105,7 @@ static ssize_t netdev_store(struct device *dev, struct device_attribute *attr, NETDEVICE_SHOW_RO(dev_id, fmt_hex); NETDEVICE_SHOW_RO(dev_port, fmt_dec); +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); @@ -387,6 +388,7 @@ static struct attribute *net_class_attrs[] = { &dev_attr_dev_port.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 d4ff417..2e4be7f 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -1971,6 +1971,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);