ethtool netlink interface, preliminary part
v3 cover ethtool netlink interface, preliminary part
As Jakub Kicinski suggested in ethtool netlink v7 discussion, this submission consists only of preliminary patches which raised no objections; first four patches already have Acked-by or Reviewed-by.
- patch 1 exposes permanent hardware address (as shown by "ethtool -P") via rtnetlink
- patch 2 is renames existing netlink helper to a better name
- patch 3 and 4 reorganize existing ethtool code (no functional change)
- patch 5 makes the table of link mode names available as an ethtool string set (will be needed for the netlink interface)
Once we get these out of the way, v8 of the first part of the ethtool netlink interface will follow.
Changes from v2 to v3: fix SPDX licence identifiers (patch 3 and 5).
Changes from v1 to v2: restore build time check that all link modes have assigned a name (patch 5).
Michal Kubecek (5):
rtnetlink: provide permanent hardware address in RTM_NEWLINK
netlink: rename nl80211_validate_nested() to nla_validate_nested()
ethtool: move to its own directory
ethtool: move string arrays into common file
ethtool: provide link mode names as a string set
include/net/netlink.h | 8 +-
include/uapi/linux/ethtool.h | 2 +
include/uapi/linux/if_link.h | 1 +
net/Makefile | 2 +-
net/core/Makefile | 2 +-
net/core/rtnetlink.c | 5 +
net/ethtool/Makefile | 3 +
net/ethtool/common.c | 171 ++++++++++++++++++++++++
net/ethtool/common.h | 22 +++
net/{core/ethtool.c => ethtool/ioctl.c} | 90 ++-----------
net/wireless/nl80211.c | 3 +-
11 files changed, 219 insertions(+), 90 deletions(-)
create mode 100644 net/ethtool/Makefile
create mode 100644 net/ethtool/common.c
create mode 100644 net/ethtool/common.h
rename net/{core/ethtool.c => ethtool/ioctl.c} (95%)Signature · 1 line
2.24.0
PATCH v3 1/5 rtnetlink: provide permanent hardware address in RTM_NEWLINK
Permanent hardware address of a network device was traditionally provided via ethtool ioctl interface but as Jiri Pirko pointed out in a review of ethtool netlink interface, rtnetlink is much more suitable for it so let's add it to the RTM_NEWLINK message.
Add IFLA_PERM_ADDRESS attribute to RTM_NEWLINK messages unless the permanent address is all zeros (i.e. device driver did not fill it). As permanent address is not modifiable, reject userspace requests containing IFLA_PERM_ADDRESS attribute.
Note: we already provide permanent hardware address for bond slaves; unfortunately we cannot drop that attribute for backward compatibility reasons.
v5 -> v6: only add the attribute if permanent address is not zero
--- include/uapi/linux/if_link.h | 1 + net/core/rtnetlink.c | 5 +++++ 2 files changed, 6 insertions(+)
include/uapi/linux/if_link.h +1 -0
@@ -169,6 +169,7 @@ enum {IFLA_MAX_MTU ,IFLA_PROP_LIST ,IFLA_ALT_IFNAME ,/* Alternative ifname */ +IFLA_PERM_ADDRESS , __IFLA_MAX };
net/core/rtnetlink.c +5 -0
@@ -1041,6 +1041,7 @@ static noinline size_t if_nlmsg_size(const struct net_device *dev, +nla_total_size (4 )/* IFLA_MIN_MTU */ +nla_total_size (4 )/* IFLA_MAX_MTU */ +rtnl_prop_list_size (dev) + +nla_total_size (MAX_ADDR_LEN )/* IFLA_PERM_ADDRESS */ +0 ; }
@@ -1757,6 +1758,9 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, nla_put_s32(skb, IFLA_NEW_IFINDEX, new_ifindex) < 0) goto nla_put_failure; +if (memchr_inv (dev->perm_addr,'\0' , dev->addr_len) && +nla_put (skb,IFLA_PERM_ADDRESS , dev->addr_len, dev->perm_addr)) + goto nla_put_failure;rcu_read_lock ();if (rtnl_fill_link_af (skb, dev, ext_filter_mask))
@@ -1822,6 +1826,7 @@ static const struct nla_policy ifla_policy[IFLA_MAX+1] = { [IFLA_PROP_LIST] = { .type = NLA_NESTED }, [IFLA_ALT_IFNAME ] = { .type =NLA_STRING , .len = ALTIFNAMSIZ - 1 }, + [IFLA_PERM_ADDRESS] = { .type = NLA_REJECT }, };static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX +1 ] = {
Signature · 1 line
2.24.0
PATCH v3 2/5 netlink: rename nl80211_validate_nested() to nla_validate_nested()
In reply to Michal KubecekFunction nl80211_validate_nested() is not specific to nl80211, it's a counterpart to nla_validate_nested_deprecated() with strict validation. For consistency with other validation and parse functions, rename it to nla_validate_nested().
--- include/net/netlink.h | 8 ++++---- net/wireless/nl80211.c | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-)
include/net/netlink.h +4 -4
@@ -1735,7 +1735,7 @@ static inline void nla_nest_cancel(struct sk_buff *skb, struct nlattr *start) }/** -* nla_validate_nested - Validate a stream of nested attributes +* __nla_validate_nested - Validate a stream of nested attributes * @start: container attribute * @maxtype: maximum attribute type to be expected * @policy: validation policy
@@ -1758,9 +1758,9 @@ static inline int __nla_validate_nested(const struct nlattr *start, int maxtype, }static inline int -nl80211_validate_nested (const struct nlattr *start,int maxtype, -const struct nla_policy *policy, -struct netlink_ext_ack *extack) +nla_validate_nested (const struct nlattr *start,int maxtype, +const struct nla_policy *policy, +struct netlink_ext_ack *extack) {return __nla_validate_nested (start, maxtype, policy,NL_VALIDATE_STRICT , extack);
net/wireless/nl80211.c +1 -2
@@ -12900,8 +12900,7 @@ static int nl80211_vendor_check_policy(const struct wiphy_vendor_command *vcmd,return -EINVAL ; } -return nl80211_validate_nested (attr, vcmd->maxattr, vcmd->policy, - extack); +return nla_validate_nested (attr, vcmd->maxattr, vcmd->policy, extack); }static int nl80211_vendor_cmd (struct sk_buff *skb,struct genl_info *info)
Signature · 1 line
2.24.0
PATCH v3 3/5 ethtool: move to its own directory
In reply to Michal KubecekThe ethtool netlink interface is going to be split into multiple files so that it will be more convenient to put all of them in a separate directory net/ethtool. Start by moving current ethtool.c with ioctl interface into this directory and renaming it to ioctl.c.
---
net/Makefile | 2 +-
net/core/Makefile | 2 +-
net/ethtool/Makefile | 3 +++
net/{core/ethtool.c => ethtool/ioctl.c} | 0
4 files changed, 5 insertions(+), 2 deletions(-)
create mode 100644 net/ethtool/Makefile
rename net/{core/ethtool.c => ethtool/ioctl.c} (100%)net/Makefile +1 -1
@@ -13,7 +13,7 @@ obj-$(CONFIG_NET) += $(tmp-y) # LLC has to be linked before the files in net/802/ obj-$(CONFIG_LLC) += llc/ -obj-$(CONFIG_NET) += ethernet/ 802/ sched/ netlink/ bpf/ +obj-$(CONFIG_NET) += ethernet/ 802/ sched/ netlink/ bpf/ ethtool/ obj-$(CONFIG_NETFILTER) += netfilter/ obj-$(CONFIG_INET) += ipv4/ obj-$(CONFIG_TLS) += tls/
net/core/Makefile +1 -1
@@ -8,7 +8,7 @@ obj-y := sock.o request_sock.o skbuff.o datagram.o stream.o scm.o \ obj-$(CONFIG_SYSCTL) += sysctl_net_core.o -obj-y += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \ +obj-y += dev.o dev_addr_lists.o dst.o netevent.o \ neighbour.o rtnetlink.o utils.o link_watch.o filter.o \ sock_diag.o dev_ioctl.o tso.o sock_reuseport.o \ fib_notifier.o xdp.o flow_offload.o
net/ethtool/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-y += ioctl.o
net/ethtool/ioctl.c renamed from net/core/ethtool.c +0 -0
Signature · 1 line
2.24.0
PATCH v3 4/5 ethtool: move string arrays into common file
In reply to Michal KubecekIntroduce file net/ethtool/common.c for code shared by ioctl and netlink ethtool interface. Move name tables of features, RSS hash functions, tunables and PHY tunables into this file.
--- net/ethtool/Makefile | 2 +- net/ethtool/common.c | 85 ++++++++++++++++++++++++++++++++++++++++++++ net/ethtool/common.h | 17 +++++++++ net/ethtool/ioctl.c | 84 ++----------------------------------------- 4 files changed, 105 insertions(+), 83 deletions(-) create mode 100644 net/ethtool/common.c create mode 100644 net/ethtool/common.h
net/ethtool/Makefile +1 -1
@@ -1,3 +1,3 @@ # SPDX-License-Identifier: GPL-2.0-only -obj-y += ioctl.o +obj-y += ioctl.o common.o
net/ethtool/common.c new file +85 -0
85 lines not on this page · raw message
net/ethtool/common.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ETHTOOL_COMMON_H +#define _ETHTOOL_COMMON_H + +#include <linux/ethtool.h> + +extern const char +netdev_features_strings[NETDEV_FEATURE_COUNT ][ETH_GSTRING_LEN ]; +extern const char +rss_hash_func_strings[ETH_RSS_HASH_FUNCS_COUNT ][ETH_GSTRING_LEN ]; +extern const char +tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN ]; +extern const char +phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN ]; + +#endif /* _ETHTOOL_COMMON_H */
net/ethtool/ioctl.c +2 -82
96 lines not on this page · raw message
Signature · 1 line
2.24.0
PATCH v3 5/5 ethtool: provide link mode names as a string set
In reply to Michal KubecekUnlike e.g. netdev features, the ethtool ioctl interface requires link mode table to be in sync between kernel and userspace for userspace to be able to display and set all link modes supported by kernel. The way arbitrary length bitsets are implemented in netlink interface, this will be no longer needed.
To allow userspace to access all link modes running kernel supports, add table of ethernet link mode names and make it available as a string set to userspace GET_STRSET requests. Add build time check to make sure names are defined for all modes declared in enum ethtool_link_mode_bit_indices.
Once the string set is available, make it also accessible via ioctl.
--- include/uapi/linux/ethtool.h | 2 + net/ethtool/common.c | 86 ++++++++++++++++++++++++++++++++++++ net/ethtool/common.h | 5 +++ net/ethtool/ioctl.c | 6 +++ 4 files changed, 99 insertions(+)
include/uapi/linux/ethtool.h +2 -0
@@ -593,6 +593,7 @@ struct ethtool_pauseparam {* @ETH_SS_RSS_HASH_FUNCS: RSS hush function names * @ETH_SS_PHY_STATS: Statistic names, for use with %ETHTOOL_GPHYSTATS * @ETH_SS_PHY_TUNABLES: PHY tunable names +* @ETH_SS_LINK_MODES: link mode names */ enum ethtool_stringset {ETH_SS_TEST =0 ,
@@ -604,6 +605,7 @@ enum ethtool_stringset {ETH_SS_TUNABLES ,ETH_SS_PHY_STATS ,ETH_SS_PHY_TUNABLES , + ETH_SS_LINK_MODES, };/**
net/ethtool/common.c +86 -0
89 lines not on this page · raw message
net/ethtool/common.h +5 -0
@@ -5,6 +5,10 @@#include <linux/ethtool.h> +/* compose link mode index from speed, type and duplex */ +#define ETHTOOL_LINK_MODE (speed, type, duplex) \ + ETHTOOL_LINK_MODE_ ## speed ## base ## type ## _ ## duplex ## _BIT +extern const char netdev_features_strings[NETDEV_FEATURE_COUNT ][ETH_GSTRING_LEN ]; extern const char
@@ -13,5 +17,6 @@ extern const char tunable_strings[__ETHTOOL_TUNABLE_COUNT][ETH_GSTRING_LEN ];extern const char phy_tunable_strings[__ETHTOOL_PHY_TUNABLE_COUNT][ETH_GSTRING_LEN ]; +extern const char link_mode_names[][ETH_GSTRING_LEN ];#endif /* _ETHTOOL_COMMON_H */
net/ethtool/ioctl.c +6 -0
@@ -154,6 +154,9 @@ static int __ethtool_get_sset_count(struct net_device *dev, int sset) !ops->get_ethtool_phy_stats)return phy_ethtool_get_sset_count (dev->phydev); +if (sset ==ETH_SS_LINK_MODES ) +return __ETHTOOL_LINK_MODE_MASK_NBITS; +if (ops->get_sset_count && ops->get_strings)return ops->get_sset_count (dev, sset);else
@@ -178,6 +181,9 @@ static void __ethtool_get_strings(struct net_device *dev,else if (stringset ==ETH_SS_PHY_STATS && dev->phydev && !ops->get_ethtool_phy_stats)phy_ethtool_get_strings (dev->phydev, data); +else if (stringset ==ETH_SS_LINK_MODES ) +memcpy (data, link_mode_names, + __ETHTOOL_LINK_MODE_MASK_NBITS *ETH_GSTRING_LEN );else /* ops->get_strings is valid because checked earlier */ ops->get_strings (dev, stringset, data);
Signature · 1 line
2.24.0
Quoted 10 lines · Michal Kubecek
As Jakub Kicinski suggested in ethtool netlink v7 discussion, this submission consists only of preliminary patches which raised no objections; first four patches already have Acked-by or Reviewed-by.
- patch 1 exposes permanent hardware address (as shown by "ethtool -P") via rtnetlink
- patch 2 is renames existing netlink helper to a better name
- patch 3 and 4 reorganize existing ethtool code (no functional change)
- patch 5 makes the table of link mode names available as an ethtool string set (will be needed for the netlink interface)
Re: [PATCH net-next v3 4/5] ethtool: move string arrays into common file
In reply to Michal KubecekQuoted 6 lines · Michal Kubecek
Introduce file
net/ethtool/common.cfor code shared by ioctl and netlink ethtool interface. Move name tables of features, RSS hash functions, tunables and PHY tunables into this file.Signed-off-by Michal Kubecek <[email protected]>Reviewed-by Jiri Pirko <[email protected]>
Signature · 1 line
Florian
Re: [PATCH net-next v3 5/5] ethtool: provide link mode names as a string set
In reply to Michal KubecekQuoted 11 lines · Michal Kubecek
Unlike e.g. netdev features, the ethtool ioctl interface requires link mode table to be in sync between kernel and userspace for userspace to be able to display and set all link modes supported by kernel. The way arbitrary length bitsets are implemented in netlink interface, this will be no longer needed.
To allow userspace to access all link modes running kernel supports, add table of ethernet link mode names and make it available as a string set to userspace
GET_STRSETrequests. Add build time check to make sure names are defined for all modes declared in enumethtool_link_mode_bit_indices.
Quoted 5 lines
Once the string set is available, make it also accessible via ioctl.
Signed-off-by Michal Kubecek <[email protected]>Reviewed-by Andrew Lunn <[email protected]>Reviewed-by Jiri Pirko <[email protected]>
I would have almost treated the _Half_ modes a special to omit specifying Full for 90% of the remaining modes and save both characters and room for errors, but that's fine this way too.
Signature · 1 line
Florian
Quoted 3 lines · Michal Kubecek
As Jakub Kicinski suggested in ethtool netlink v7 discussion, this submission consists only of preliminary patches which raised no objections; first four patches already have Acked-by or Reviewed-by.
Good strategy, let's make sure we can land the entire ethtool over netlink for v5.6, that would be a great milestone and would open up the door for quite a lot of development. Thanks for your persistence on the subject, because this is anything but fun.
Signature · 1 line
Florian
David Miller
maintainerFrom: Michal Kubecek <[email protected]>
Date: Wed, 11 Dec 2019 10:58:09 +0100 (CET)
Quoted 11 lines
As Jakub Kicinski suggested in ethtool netlink v7 discussion, this submission consists only of preliminary patches which raised no objections; first four patches already have Acked-by or Reviewed-by.
- patch 1 exposes permanent hardware address (as shown by "ethtool -P") via rtnetlink
- patch 2 is renames existing netlink helper to a better name
- patch 3 and 4 reorganize existing ethtool code (no functional change)
- patch 5 makes the table of link mode names available as an ethtool string set (will be needed for the netlink interface)
Quoted 7 lines
Once we get these out of the way, v8 of the first part of the ethtool netlink interface will follow.
Changes from v2 to v3: fix SPDX licence identifiers (patch 3 and 5).
Changes from v1 to v2: restore build time check that all link modes have assigned a name (patch 5).
Series applied to net-next, thanks.