Provide netdev naming-policy via sysfs
Subsystems (5)
v6 cover Provide netdev naming-policy via sysfs
Hi
This is v6 of the name_assign_type attribute for netdevs. Changes since v5 [1]:
- Acked-by: Kay Sievers
- rebased on net-next of today
Aimed for 3.15, but feel free to delay for 3.16 if you want it in -next for some more time.
Thanks
David
[1] http://thread.gmane.org/gmane.linux.kernel/1673169
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 | 2 ++ include/uapi/linux/netdevice.h | 4 ++++ 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 +- 13 files changed, 30 insertions(+), 5 deletions(-)
Signature · 1 line
1.9.1
PATCH v6 1/4 net: add name_assign_type netdev attribute
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.
--- 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(+)
include/linux/netdevice.h +2 -0
@@ -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;
include/uapi/linux/netdevice.h +4 -0
@@ -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. */
net/core/dev.c +7 -0
@@ -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",
net/core/net-sysfs.c +2 -0
@@ -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,
net/core/rtnetlink.c +2 -0
@@ -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);
Signature · 1 line
1.9.1
PATCH v6 2/4 mac80211: set NET_NAME_USER for user-space created ifs
In reply to David HerrmannThe 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).
--- 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(-)
net/mac80211/cfg.c +1 -1
@@ -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);
net/mac80211/ieee80211_i.h +1 -0
@@ -1470,6 +1470,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,
net/mac80211/iface.c +2 -0
@@ -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);
net/mac80211/main.c +1 -1
@@ -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,
Signature · 1 line
1.9.1
PATCH v6 3/4 ath6kl: set NET_NAME_USER for P2P ifs
In reply to David HerrmannP2P 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.
--- 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(-)
drivers/net/wireless/ath/ath6kl/cfg80211.c +4 -1
@@ -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);
drivers/net/wireless/ath/ath6kl/cfg80211.h +1 -0
@@ -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,
drivers/net/wireless/ath/ath6kl/core.c +2 -2
@@ -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 ();
Signature · 1 line
1.9.1
PATCH v6 4/4 brcmfmac: set NET_NAME_USER for P2P ifs
In reply to David HerrmannNetdevs 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.
--- drivers/net/wireless/brcm80211/brcmfmac/p2p.c | 1 + 1 file changed, 1 insertion(+)
drivers/net/wireless/brcm80211/brcmfmac/p2p.c +1 -0
@@ -2308,6 +2308,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) {
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe linux-wireless" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
David Miller
maintainerFrom: David Herrmann <[email protected]>
Date: Wed, 2 Apr 2014 11:58:22 +0200
Quoted 6 lines
This is v6 of the
name_assign_typeattribute for netdevs. Changes since v5 [1]:
- Acked-by: Kay Sievers
- rebased on net-next of todayAimed for 3.15, but feel free to delay for 3.16 if you want it in -next for some more time.
I'm fine with the basic idea, but the implementation needs work and this will be deferred to 3.16 in any event.
We really need to specify the name allocation type at alloc_netdev() time, I know that's more work but that's the only way you can be sure you caught all such cases.
I know you missed the ISDN layer, where the name can come from the user via an ioctl(). I'm sure there were several more.
You can even do something like make alloc_netdev_enumerated() be a shorthand for alloc_netdev(size, name, NET_NAME_ENUM, ...)
Thanks.