Skip to contentSkip to conversation

ethtool netlink interface, preliminary part

PATCH Superseded Michal Kubecek 6 participants 17 messages Dec 10, 2019 – Dec 11, 2019

Subsystems (4)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 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.

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
#1 lore raw

PATCH v2 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
index 8aec8769d944..1d69f637c5d6 100644
@@ -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
index 02916f43bf63..20bc406f3871 100644
@@ -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
#2 lore raw

Re: [PATCH net-next v2 1/5] rtnetlink: provide permanent hardware address in RTM_NEWLINK

net/core/rtnetlink.c static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · line 1832

Quoted 8 lines · Michal Kubecek
net/core/rtnetlink.c +1 -0
@@ -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] = {

Jiri, I just noticed ifla_policy didn't get strict_start_type set when ALT_IFNAME was added, should we add it in net? 🤔

#3 lore raw

Re: [PATCH net-next v2 1/5] rtnetlink: provide permanent hardware address in RTM_NEWLINK

Quoted 8 lines · Tue, Dec 10, 2019 at 06:51:05PM CET, [email protected] wrote:
Quoted 7 lines · Michal Kubecek
net/core/rtnetlink.c +1 -0
@@ -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 },
 };
 
Quoted 4 lines

net/core/rtnetlink.c static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · line 1832

Quoted 1 line
net/core/rtnetlink.c +0 -0
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {

Jiri, I just noticed ifla_policy didn't get strict_start_type set when ALT_IFNAME was added, should we add it in net? 🤔

Hmm, I guess that is a good idea.

maintainer
#4 lore raw

Re: [PATCH net-next v2 1/5] rtnetlink: provide permanent hardware address in RTM_NEWLINK

In reply to Jakub Kicinski
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · Michal Kubecek
net/core/rtnetlink.c +1 -0
@@ -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 },
 };
 
Quoted 4 lines

net/core/rtnetlink.c static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · line 1832

Quoted 1 line
net/core/rtnetlink.c +0 -0
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {

Jiri, I just noticed ifla_policy didn't get strict_start_type set when ALT_IFNAME was added, should we add it in net? 🤔

Does it need one? It shouldn't be used with nla_parse_nested_deprecated(), and if it's used with nla_parse_nested() then it doesn't matter?

johannes

maintainer
#5 lore raw

Re: [PATCH net-next v2 1/5] rtnetlink: provide permanent hardware address in RTM_NEWLINK

Quoted 9 lines · Johannes Berg
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · Michal Kubecek
net/core/rtnetlink.c +1 -0
@@ -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 },
 };
 
Quoted 8 lines
Quoted 4 lines

net/core/rtnetlink.c static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · line 1832

Quoted 1 line
net/core/rtnetlink.c +0 -0
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {

Jiri, I just noticed ifla_policy didn't get strict_start_type set when ALT_IFNAME was added, should we add it in net? 🤔

Does it need one? It shouldn't be used with nla_parse_nested_deprecated(), and if it's used with nla_parse_nested() then it doesn't matter?

No, wait. I misread, you said "when ALT_IFNAME was added" but somehow I managed to read "when it was added"...

So yeah, it should have one. Dunno about net, your call. I'd probably not bother for an NLA_REJECT attribute, there's little use including it anyway.

johannes

#6 lore raw

Re: [PATCH net-next v2 1/5] rtnetlink: provide permanent hardware address in RTM_NEWLINK

Quoted 19 lines · Johannes Berg
Quoted 9 lines · Johannes Berg
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · Michal Kubecek
net/core/rtnetlink.c +1 -0
@@ -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 },
 };
 
Quoted 8 lines
Quoted 4 lines

net/core/rtnetlink.c static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · line 1832

Quoted 1 line
net/core/rtnetlink.c +0 -0
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {

Jiri, I just noticed ifla_policy didn't get strict_start_type set when ALT_IFNAME was added, should we add it in net? 🤔

Does it need one? It shouldn't be used with nla_parse_nested_deprecated(), and if it's used with nla_parse_nested() then it doesn't matter?

Quoted 7 lines

No, wait. I misread, you said "when ALT_IFNAME was added" but somehow I managed to read "when it was added"...

So yeah, it should have one. Dunno about net, your call. I'd probably not bother for an NLA_REJECT attribute, there's little use including it anyway.

It's new in net, so it has to be there not net-next.

maintainer
#7 lore raw

Re: [PATCH net-next v2 1/5] rtnetlink: provide permanent hardware address in RTM_NEWLINK

Quoted 23 lines · David Ahern
Quoted 22 lines · Johannes Berg
Quoted 9 lines · Johannes Berg
Quoted 8 lines · Jakub Kicinski
Quoted 7 lines · Michal Kubecek
net/core/rtnetlink.c +1 -0
@@ -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 },
 };
 
Quoted 8 lines
Quoted 4 lines

net/core/rtnetlink.c static const struct nla_policy ifla_policy[IFLA_MAX+1] = { · line 1832

Quoted 1 line
net/core/rtnetlink.c +0 -0
 static const struct nla_policy ifla_info_policy[IFLA_INFO_MAX+1] = {

Jiri, I just noticed ifla_policy didn't get strict_start_type set when ALT_IFNAME was added, should we add it in net? 🤔

Does it need one? It shouldn't be used with nla_parse_nested_deprecated(), and if it's used with nla_parse_nested() then it doesn't matter?

No, wait. I misread, you said "when ALT_IFNAME was added" but somehow I managed to read "when it was added"...

Quoted 6 lines
Quoted 4 lines

So yeah, it should have one. Dunno about net, your call. I'd probably not bother for an NLA_REJECT attribute, there's little use including it anyway.

It's new in net, so it has to be there not net-next.

Oh, ok. Well, I was actually thinking to just add it on the next attribute or so, but I guess now that we're discussing it there's a higher chance of it actually happening :)

johannes

#8 lore raw

PATCH v2 2/5 netlink: rename nl80211_validate_nested() to nla_validate_nested()

In reply to Michal Kubecek

Function 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
index b140c8f1be22..56c365dc6dc7 100644
@@ -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
index da5262b2298b..fa3526592c51 100644
@@ -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
#9 lore raw

PATCH v2 3/5 ethtool: move to its own directory

In reply to Michal Kubecek

The 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
index 449fc0b221f8..848303d98d3d 100644
@@ -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
index a104dc8faafc..3e2c378e5f31 100644
@@ -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
new file mode 100644
index 000000000000..3ebfab2bca66
@@ -0,0 +1,3 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-y		+= ioctl.o
net/ethtool/ioctl.c renamed from net/core/ethtool.c +0 -0
similarity index 100%
rename from net/core/ethtool.c
rename to net/ethtool/ioctl.c
Signature · 1 line
2.24.0
#10 lore raw

PATCH v2 4/5 ethtool: move string arrays into common file

In reply to Michal Kubecek

Introduce 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
index 3ebfab2bca66..fe70d3a1d545 100644
@@ -1,3 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0
 
-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
new file mode 100644
index 000000000000..41b2efc1e4e1
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
+
+#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
maintainer
#11 lore raw

Re: [PATCH net-next v2 4/5] ethtool: move string arrays into common file

net/ethtool/common.c line 1

Quoted 4 lines

+++ b/net/ethtool/common.c

net/ethtool/common.c new file +1 -0
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note

Is the Linux-syscall-note relevant here? This isn't really used for syscalls directly?

The exception says it's "to mark user space API (uapi) header files so they can be included into non GPL compliant user space application code".

net/ethtool/common.h line 1

Quoted 3 lines
net/ethtool/common.h new file +2 -0
+++ b/net/ethtool/common.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Same here.

johannes

#12 lore raw

Re: [PATCH net-next v2 4/5] ethtool: move string arrays into common file

Quoted 11 lines · Johannes Berg

net/ethtool/common.c line 1

Quoted 4 lines

+++ b/net/ethtool/common.c

net/ethtool/common.c new file +1 -0
@@ -0,0 +1,85 @@
+// SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note

Is the Linux-syscall-note relevant here? This isn't really used for syscalls directly?

The exception says it's "to mark user space API (uapi) header files so they can be included into non GPL compliant user space application code".

I'm hardly an expert but almost all occurences of "Linux-syscall-note" are in UAPI headers so you are most likely right. IIRC I copied the line into include/uapi/linux/ethtool_netlink.h (which was the first new file) from neighbor ethtool.h and then used the same in all other files.

I'll send a v3 with "GPL-2.0-only" (as there also seems to be a trend of moving to SPDX v3 identifiers) in a moment.

Michal

Quoted 9 lines

net/ethtool/common.h line 1

Quoted 4 lines
net/ethtool/common.h new file +2 -0
+++ b/net/ethtool/common.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */

Same here.

johannes

#13 lore raw

PATCH v2 5/5 ethtool: provide link mode names as a string set

In reply to 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_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
index d4591792f0b4..f44155840b07 100644
@@ -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
index 41b2efc1e4e1..3fe09c236145 100644
@@ -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
index b262db5a1d91..aed2c2cf1623 100644
@@ -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
maintainer Reviewed-by on v2 5/5
#14 lore raw

Re: [PATCH net-next v2 5/5] ethtool: provide link mode names as a string set

Quoted 6 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.

Quoted 8 lines

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.

Andrew

Reviewed-by on v2 5/5
#15 lore raw

Re: [PATCH net-next v2 5/5] ethtool: provide link mode names as a string set

In reply to Michal Kubecek
Quoted 6 lines · Tue, Dec 10, 2019 at 02:08:13PM CET, [email protected] wrote:

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.

Quoted 8 lines

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.

Reviewed-by on the v2 series
#16 lore raw
In reply to Michal Kubecek
Quoted 11 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)

Quoted 2 lines

Once we get these out of the way, v8 of the first part of the ethtool netlink interface will follow.

Thank you!