linux-wireless.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] Provide netdev naming-policy via sysfs
@ 2014-03-16 17:21 David Herrmann
  2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: David Herrmann @ 2014-03-16 17:21 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-kernel,
	linux-wireless, David Herrmann

Hi

This is v2 of the netdev naming-policy series. You can find v1 here:
  http://thread.gmane.org/gmane.linux.kernel/1657015
Changes in v2:
  - fix mac80211 core to set NET_NAME_ENUM for wlan%d kernel-provided names
  - acked-by udev developers


This series implements a new sysfs attribute for netdevs called
"name_assign_type". It provides an integer that describes where an interface
name comes from. See Patch #1 for a description of this attribute. It is
modelled after the existing "addr_assign_type" attribute.

The main use-case is to allow udev to skip applying reliable ifnames to virtual
devices. For instance, if wifi-P2P devices are created, wpas already provides a
suitable naming-policy and udev shouldn't touch these devices. Same is true for
other virtual devices.
The idea is that if a device-name was provided by user-space, we should always
prefer fixing this naming-policy instead of making udev rename the device. For
kernel provided names that's hardly possible, though. Providing the
naming-policy source via sysfs is thus a simple way to see whether renames are
needed.

Additionally, this field allows to detect whether a netdev has been manually
renamed, which is quite useful for debugging and during crash-recovery.
Furthermore, it fixes real udev bugs if a netdev is already renamed in the
initrd and udev only runs in the real root. Detecting renames avoids overwriting
custom user provided names.

Thanks
David

David Herrmann (4):
  net: add name_assign_type netdev attribute
  mac80211: set NET_NAME_USER for user-space created ifs
  ath6kl: set NET_NAME_USER for P2P ifs
  brcmfmac: set NET_NAME_USER for P2P ifs

 drivers/net/wireless/ath/ath6kl/cfg80211.c    | 5 ++++-
 drivers/net/wireless/ath/ath6kl/cfg80211.h    | 1 +
 drivers/net/wireless/ath/ath6kl/core.c        | 4 ++--
 drivers/net/wireless/brcm80211/brcmfmac/p2p.c | 1 +
 include/linux/netdevice.h                     | 6 ++++++
 net/core/dev.c                                | 7 +++++++
 net/core/net-sysfs.c                          | 2 ++
 net/core/rtnetlink.c                          | 2 ++
 net/mac80211/cfg.c                            | 2 +-
 net/mac80211/ieee80211_i.h                    | 1 +
 net/mac80211/iface.c                          | 2 ++
 net/mac80211/main.c                           | 2 +-
 12 files changed, 30 insertions(+), 5 deletions(-)

-- 
1.9.0


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v2 1/4] net: add name_assign_type netdev attribute
  2014-03-16 17:21 [PATCH v2 0/4] Provide netdev naming-policy via sysfs David Herrmann
@ 2014-03-16 17:21 ` David Herrmann
  2014-03-16 19:17   ` Ben Hutchings
                     ` (2 more replies)
  2014-03-16 17:21 ` [PATCH v2 2/4] mac80211: set NET_NAME_USER for user-space created ifs David Herrmann
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 11+ messages in thread
From: David Herrmann @ 2014-03-16 17:21 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-kernel,
	linux-wireless, David Herrmann

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 <dh.herrmann@gmail.com>
Acked-by: Tom Gundersen <teg@jklm.no>
---
 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 b8d8c80..d3040c5 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:
@@ -1248,6 +1253,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 587f9fb..4a2b360 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 daed9a6..886403e 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);
@@ -377,6 +378,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 fc122fd..f1bd0fe 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1967,6 +1967,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);
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 2/4] mac80211: set NET_NAME_USER for user-space created ifs
  2014-03-16 17:21 [PATCH v2 0/4] Provide netdev naming-policy via sysfs David Herrmann
  2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
@ 2014-03-16 17:21 ` David Herrmann
  2014-03-16 17:21 ` [PATCH v2 3/4] ath6kl: set NET_NAME_USER for P2P ifs David Herrmann
  2014-03-16 17:21 ` [PATCH v2 4/4] brcmfmac: " David Herrmann
  3 siblings, 0 replies; 11+ messages in thread
From: David Herrmann @ 2014-03-16 17:21 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-kernel,
	linux-wireless, David Herrmann, Johannes Berg

The nl80211 interface allows creating new netdevs from user-space. The
name is *always* provided by user-space, so we should set NET_NAME_USER to
provide that information via sysfs. But we must not set it for the default
wlan%d names as these are kernel-provided names.

This allows udev to not rename dynamically created wifi devices (like wifi
P2P devices).

Cc: Johannes Berg <johannes.berg@intel.com>
Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Tom Gundersen <teg@jklm.no>
---
 net/mac80211/cfg.c         | 2 +-
 net/mac80211/ieee80211_i.h | 1 +
 net/mac80211/iface.c       | 2 ++
 net/mac80211/main.c        | 2 +-
 4 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
index 1acb291..34f10fe 100644
--- a/net/mac80211/cfg.c
+++ b/net/mac80211/cfg.c
@@ -31,7 +31,7 @@ static struct wireless_dev *ieee80211_add_iface(struct wiphy *wiphy,
 	struct ieee80211_sub_if_data *sdata;
 	int err;
 
-	err = ieee80211_if_add(local, name, &wdev, type, params);
+	err = ieee80211_if_add(local, name, NET_NAME_USER, &wdev, type, params);
 	if (err)
 		return ERR_PTR(err);
 
diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
index 0d1a0f8..96f453a 100644
--- a/net/mac80211/ieee80211_i.h
+++ b/net/mac80211/ieee80211_i.h
@@ -1469,6 +1469,7 @@ int ieee80211_channel_switch(struct wiphy *wiphy, struct net_device *dev,
 int ieee80211_iface_init(void);
 void ieee80211_iface_exit(void);
 int ieee80211_if_add(struct ieee80211_local *local, const char *name,
+		     unsigned char name_assign_type,
 		     struct wireless_dev **new_wdev, enum nl80211_iftype type,
 		     struct vif_params *params);
 int ieee80211_if_change_type(struct ieee80211_sub_if_data *sdata,
diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
index b8d331e..fe84853 100644
--- a/net/mac80211/iface.c
+++ b/net/mac80211/iface.c
@@ -1574,6 +1574,7 @@ static void ieee80211_assign_perm_addr(struct ieee80211_local *local,
 }
 
 int ieee80211_if_add(struct ieee80211_local *local, const char *name,
+		     unsigned char name_assign_type,
 		     struct wireless_dev **new_wdev, enum nl80211_iftype type,
 		     struct vif_params *params)
 {
@@ -1617,6 +1618,7 @@ int ieee80211_if_add(struct ieee80211_local *local, const char *name,
 					+ IEEE80211_ENCRYPT_HEADROOM;
 		ndev->needed_tailroom = IEEE80211_ENCRYPT_TAILROOM;
 
+		ndev->name_assign_type = name_assign_type;
 		ret = dev_alloc_name(ndev, ndev->name);
 		if (ret < 0) {
 			free_netdev(ndev);
diff --git a/net/mac80211/main.c b/net/mac80211/main.c
index b055f6a5..ee32a83 100644
--- a/net/mac80211/main.c
+++ b/net/mac80211/main.c
@@ -1012,7 +1012,7 @@ int ieee80211_register_hw(struct ieee80211_hw *hw)
 
 	/* add one default STA interface if supported */
 	if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
-		result = ieee80211_if_add(local, "wlan%d", NULL,
+		result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
 					  NL80211_IFTYPE_STATION, NULL);
 		if (result)
 			wiphy_warn(local->hw.wiphy,
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 3/4] ath6kl: set NET_NAME_USER for P2P ifs
  2014-03-16 17:21 [PATCH v2 0/4] Provide netdev naming-policy via sysfs David Herrmann
  2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
  2014-03-16 17:21 ` [PATCH v2 2/4] mac80211: set NET_NAME_USER for user-space created ifs David Herrmann
@ 2014-03-16 17:21 ` David Herrmann
  2014-03-16 17:21 ` [PATCH v2 4/4] brcmfmac: " David Herrmann
  3 siblings, 0 replies; 11+ messages in thread
From: David Herrmann @ 2014-03-16 17:21 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-kernel,
	linux-wireless, David Herrmann

P2P netdevs and other devices that are created via nl80211 from user-space
have a name provided by user-space. Therefore, set NET_NAME_USER so this
is correctly shown in sysfs.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Kalle Valo <kvalo@qca.qualcomm.com>
Acked-by: Tom Gundersen <teg@jklm.no>
---
 drivers/net/wireless/ath/ath6kl/cfg80211.c | 5 ++++-
 drivers/net/wireless/ath/ath6kl/cfg80211.h | 1 +
 drivers/net/wireless/ath/ath6kl/core.c     | 4 ++--
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.c b/drivers/net/wireless/ath/ath6kl/cfg80211.c
index c2c6f46..131d8ab 100644
--- a/drivers/net/wireless/ath/ath6kl/cfg80211.c
+++ b/drivers/net/wireless/ath/ath6kl/cfg80211.c
@@ -1512,7 +1512,8 @@ static struct wireless_dev *ath6kl_cfg80211_add_iface(struct wiphy *wiphy,
 		return ERR_PTR(-EINVAL);
 	}
 
-	wdev = ath6kl_interface_add(ar, name, type, if_idx, nw_type);
+	wdev = ath6kl_interface_add(ar, name, NET_NAME_USER, type,
+				    if_idx, nw_type);
 	if (!wdev)
 		return ERR_PTR(-ENOMEM);
 
@@ -3630,6 +3631,7 @@ void ath6kl_cfg80211_vif_cleanup(struct ath6kl_vif *vif)
 }
 
 struct wireless_dev *ath6kl_interface_add(struct ath6kl *ar, const char *name,
+					  unsigned char name_assign_type,
 					  enum nl80211_iftype type,
 					  u8 fw_vif_idx, u8 nw_type)
 {
@@ -3666,6 +3668,7 @@ struct wireless_dev *ath6kl_interface_add(struct ath6kl *ar, const char *name,
 			ndev->dev_addr[4] ^= 0x80;
 	}
 
+	ndev->name_assign_type = name_assign_type;
 	init_netdev(ndev);
 
 	ath6kl_init_control_info(vif);
diff --git a/drivers/net/wireless/ath/ath6kl/cfg80211.h b/drivers/net/wireless/ath/ath6kl/cfg80211.h
index b59becd..5aa57a7 100644
--- a/drivers/net/wireless/ath/ath6kl/cfg80211.h
+++ b/drivers/net/wireless/ath/ath6kl/cfg80211.h
@@ -25,6 +25,7 @@ enum ath6kl_cfg_suspend_mode {
 };
 
 struct wireless_dev *ath6kl_interface_add(struct ath6kl *ar, const char *name,
+					  unsigned char name_assign_type,
 					  enum nl80211_iftype type,
 					  u8 fw_vif_idx, u8 nw_type);
 void ath6kl_cfg80211_ch_switch_notify(struct ath6kl_vif *vif, int freq,
diff --git a/drivers/net/wireless/ath/ath6kl/core.c b/drivers/net/wireless/ath/ath6kl/core.c
index 4b46adb..3cc8145 100644
--- a/drivers/net/wireless/ath/ath6kl/core.c
+++ b/drivers/net/wireless/ath/ath6kl/core.c
@@ -195,8 +195,8 @@ int ath6kl_core_init(struct ath6kl *ar, enum ath6kl_htc_type htc_type)
 	rtnl_lock();
 
 	/* Add an initial station interface */
-	wdev = ath6kl_interface_add(ar, "wlan%d", NL80211_IFTYPE_STATION, 0,
-				    INFRA_NETWORK);
+	wdev = ath6kl_interface_add(ar, "wlan%d", NET_NAME_ENUM,
+				    NL80211_IFTYPE_STATION, 0, INFRA_NETWORK);
 
 	rtnl_unlock();
 
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH v2 4/4] brcmfmac: set NET_NAME_USER for P2P ifs
  2014-03-16 17:21 [PATCH v2 0/4] Provide netdev naming-policy via sysfs David Herrmann
                   ` (2 preceding siblings ...)
  2014-03-16 17:21 ` [PATCH v2 3/4] ath6kl: set NET_NAME_USER for P2P ifs David Herrmann
@ 2014-03-16 17:21 ` David Herrmann
  3 siblings, 0 replies; 11+ messages in thread
From: David Herrmann @ 2014-03-16 17:21 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-kernel,
	linux-wireless, David Herrmann

Netdevs created via nl80211 (currently only P2P ifs) have names provided
by user-space. Therefore, set the naming-policy to NET_NAME_USER so it is
correctly shown in sysfs.

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Acked-by: Arend van Spriel <arend@broadcom.com>
Acked-by: Tom Gundersen <teg@jklm.no>
---
 drivers/net/wireless/brcm80211/brcmfmac/p2p.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
index fc4f98b..6af4d26 100644
--- a/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
+++ b/drivers/net/wireless/brcm80211/brcmfmac/p2p.c
@@ -2310,6 +2310,7 @@ struct wireless_dev *brcmf_p2p_add_vif(struct wiphy *wiphy, const char *name,
 		goto fail;
 	}
 
+	ifp->ndev->name_assign_type = NET_NAME_USER;
 	strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
 	err = brcmf_net_attach(ifp, true);
 	if (err) {
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/4] net: add name_assign_type netdev attribute
  2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
@ 2014-03-16 19:17   ` Ben Hutchings
  2014-03-16 21:53     ` David Herrmann
  2014-03-17 17:03   ` [PATCH v3 " David Herrmann
  2014-03-17 18:01   ` [PATCH v4 " David Herrmann
  2 siblings, 1 reply; 11+ messages in thread
From: Ben Hutchings @ 2014-03-16 19:17 UTC (permalink / raw)
  To: David Herrmann
  Cc: netdev, David S. Miller, Tom Gundersen, Johannes berg,
	linux-kernel, linux-wireless

[-- Attachment #1: Type: text/plain, Size: 827 bytes --]

On Sun, 2014-03-16 at 18:21 +0100, David Herrmann wrote:
[...]
> --- 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 */
[...]

I think these definitions should be put in a UAPI header.  Even if the
names don't end up being used by userland, that would make it clear that
the numbers are a stable ABI.

Ben.

-- 
Ben Hutchings
Computers are not intelligent.	They only think they are.

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 811 bytes --]

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH v2 1/4] net: add name_assign_type netdev attribute
  2014-03-16 19:17   ` Ben Hutchings
@ 2014-03-16 21:53     ` David Herrmann
  0 siblings, 0 replies; 11+ messages in thread
From: David Herrmann @ 2014-03-16 21:53 UTC (permalink / raw)
  To: Ben Hutchings
  Cc: netdev, David S. Miller, Tom Gundersen, Johannes berg,
	linux-kernel, linux-wireless

Hi

On Sun, Mar 16, 2014 at 8:17 PM, Ben Hutchings <ben@decadent.org.uk> wrote:
> On Sun, 2014-03-16 at 18:21 +0100, David Herrmann wrote:
> [...]
>> --- 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 */
> [...]
>
> I think these definitions should be put in a UAPI header.  Even if the
> names don't end up being used by userland, that would make it clear that
> the numbers are a stable ABI.

I tried to follow addr_assign_type as closely as possible. The
NET_ADDR_* constants are only defined internally either. I am fine
with exporting the constants, just want to make sure there's no reason
to hide them that I'm not aware of.

Thanks
David

^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v3 1/4] net: add name_assign_type netdev attribute
  2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
  2014-03-16 19:17   ` Ben Hutchings
@ 2014-03-17 17:03   ` David Herrmann
  2014-03-17 17:12     ` David Laight
  2014-03-17 18:01   ` [PATCH v4 " David Herrmann
  2 siblings, 1 reply; 11+ messages in thread
From: David Herrmann @ 2014-03-17 17:03 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-wireless,
	linux-kernel, Ben Hutchings, David Herrmann

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 <dh.herrmann@gmail.com>
Acked-by: Tom Gundersen <teg@jklm.no>
---
v3:
 - move constants to uapi header (suggested by Ben)

 include/linux/netdevice.h      | 1 +
 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, 16 insertions(+)

diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index b8d8c80..6698e87 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1248,6 +1248,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/include/uapi/linux/netdevice.h b/include/uapi/linux/netdevice.h
index 6b9500b..ea963e4 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 587f9fb..4a2b360 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 daed9a6..886403e 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);
@@ -377,6 +378,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 fc122fd..f1bd0fe 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1967,6 +1967,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);
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* RE: [PATCH v3 1/4] net: add name_assign_type netdev attribute
  2014-03-17 17:03   ` [PATCH v3 " David Herrmann
@ 2014-03-17 17:12     ` David Laight
  0 siblings, 0 replies; 11+ messages in thread
From: David Laight @ 2014-03-17 17:12 UTC (permalink / raw)
  To: 'David Herrmann', netdev@vger.kernel.org
  Cc: David S. Miller, Tom Gundersen, Johannes berg,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	Ben Hutchings

From: David Herrmann
> 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.
...
> diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
> index b8d8c80..6698e87 100644
> --- a/include/linux/netdevice.h
> +++ b/include/linux/netdevice.h
> @@ -1248,6 +1248,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;

Do you really need to add 7 byte of padding here?
There seems to be some padding lurking elsewhere that really ought
to be mergable.

	David




^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH v4 1/4] net: add name_assign_type netdev attribute
  2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
  2014-03-16 19:17   ` Ben Hutchings
  2014-03-17 17:03   ` [PATCH v3 " David Herrmann
@ 2014-03-17 18:01   ` David Herrmann
  2014-03-17 19:28     ` David Miller
  2 siblings, 1 reply; 11+ messages in thread
From: David Herrmann @ 2014-03-17 18:01 UTC (permalink / raw)
  To: netdev
  Cc: David S. Miller, Tom Gundersen, Johannes berg, linux-wireless,
	linux-kernel, Ben Hutchings, David Laight, David Herrmann

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 <dh.herrmann@gmail.com>
Acked-by: Tom Gundersen <teg@jklm.no>
---
v3:
 - move constants to uapi header (Ben Hutchings)
v4:
 - avoid padding after "name_assign_type" by moving it around (David Laight)

 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 b8d8c80..1d48cee 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -1376,6 +1376,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 6b9500b..ea963e4 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 587f9fb..4a2b360 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 daed9a6..886403e 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);
@@ -377,6 +378,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 fc122fd..f1bd0fe 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -1967,6 +1967,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);
-- 
1.9.0


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH v4 1/4] net: add name_assign_type netdev attribute
  2014-03-17 18:01   ` [PATCH v4 " David Herrmann
@ 2014-03-17 19:28     ` David Miller
  0 siblings, 0 replies; 11+ messages in thread
From: David Miller @ 2014-03-17 19:28 UTC (permalink / raw)
  To: dh.herrmann
  Cc: netdev, teg, johannes, linux-wireless, linux-kernel, ben,
	David.Laight


When you post new versions of patches, you should post the entire series
again.

This way it is unambiguous what patches go which which others.

Thanks.

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2014-03-17 19:28 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-16 17:21 [PATCH v2 0/4] Provide netdev naming-policy via sysfs David Herrmann
2014-03-16 17:21 ` [PATCH v2 1/4] net: add name_assign_type netdev attribute David Herrmann
2014-03-16 19:17   ` Ben Hutchings
2014-03-16 21:53     ` David Herrmann
2014-03-17 17:03   ` [PATCH v3 " David Herrmann
2014-03-17 17:12     ` David Laight
2014-03-17 18:01   ` [PATCH v4 " David Herrmann
2014-03-17 19:28     ` David Miller
2014-03-16 17:21 ` [PATCH v2 2/4] mac80211: set NET_NAME_USER for user-space created ifs David Herrmann
2014-03-16 17:21 ` [PATCH v2 3/4] ath6kl: set NET_NAME_USER for P2P ifs David Herrmann
2014-03-16 17:21 ` [PATCH v2 4/4] brcmfmac: " David Herrmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).