netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH ethtool 0/2] Improve compatibility between netlink and ioctl interfaces
@ 2020-10-27 14:51 Ido Schimmel
  2020-10-27 14:51 ` [RFC PATCH ethtool 1/2] update UAPI header copies Ido Schimmel
  2020-10-27 14:51 ` [RFC PATCH ethtool 2/2] netlink: Set 'ETHTOOL_FLAG_LEGACY' for compatibility with legacy ioctl interface Ido Schimmel
  0 siblings, 2 replies; 3+ messages in thread
From: Ido Schimmel @ 2020-10-27 14:51 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, mkubecek, f.fainelli, andrew, David.Laight, mlxsw,
	Ido Schimmel

From: Ido Schimmel <idosch@nvidia.com>

This patch set teaches ethtool to set the 'ETHTOOL_FLAG_LEGACY' flag in
the ethtool netlink request header of the various commands mapped to
'ethtool set' in order to improve compatibility with the legacy ioctl
interface.

The current use case is to ensure that the kernel will advertise all the
supported link modes when autoneg is enabled, but without specifying
other parameters.

To prevent the kernel from complaining about unknown flags, the flag is
only set in the request header in case the kernel supports it. This is
achieved by using the recently introduced per-operation policy dump
infrastructure.

Example #1 - ethtool and kernel are both aware of the flag
==========================================================

# ethtool -s eth0 advertise 0xC autoneg on
# ethtool -s eth0 autoneg on
# ethtool eth0
Settings for eth0:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Supported FEC modes: Not reported
	Advertised link modes:  10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Speed: 1000Mb/s
	Duplex: Full
	Auto-negotiation: on
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	MDI-X: on (auto)
	Supports Wake-on: umbg
	Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
	Link detected: yes

Example #2 - only ethtool is aware of the flag
==============================================

# ethtool -s eth0 advertise 0xC autoneg on
# ethtool -s eth0 autoneg on
# ethtool eth0
Settings for eth0:
	Supported ports: [ TP ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Full
	Supported pause frame use: No
	Supports auto-negotiation: Yes
	Supported FEC modes: Not reported
	Advertised link modes:  100baseT/Half 100baseT/Full
	Advertised pause frame use: No
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Speed: 1000Mb/s
	Duplex: Full
	Auto-negotiation: on
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: internal
	MDI-X: off (auto)
	Supports Wake-on: umbg
	Wake-on: d
        Current message level: 0x00000007 (7)
                               drv probe link
	Link detected: yes

In example #2 the kernel does not advertise all the supported link
modes, but it does not complain about unknown flags either, thus
preventing breakage with old kernels.

Ido Schimmel (2):
  update UAPI header copies
  netlink: Set 'ETHTOOL_FLAG_LEGACY' for compatibility with legacy ioctl
    interface

 netlink/netlink.c            | 13 +++++++++++++
 netlink/netlink.h            |  2 ++
 netlink/parser.c             |  5 ++++-
 uapi/linux/ethtool_netlink.h |  5 ++++-
 4 files changed, 23 insertions(+), 2 deletions(-)

-- 
2.26.2


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

* [RFC PATCH ethtool 1/2] update UAPI header copies
  2020-10-27 14:51 [RFC PATCH ethtool 0/2] Improve compatibility between netlink and ioctl interfaces Ido Schimmel
@ 2020-10-27 14:51 ` Ido Schimmel
  2020-10-27 14:51 ` [RFC PATCH ethtool 2/2] netlink: Set 'ETHTOOL_FLAG_LEGACY' for compatibility with legacy ioctl interface Ido Schimmel
  1 sibling, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2020-10-27 14:51 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, mkubecek, f.fainelli, andrew, David.Laight, mlxsw,
	Ido Schimmel

From: Ido Schimmel <idosch@nvidia.com>

Update to kernel commit XXX.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 uapi/linux/ethtool_netlink.h | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/uapi/linux/ethtool_netlink.h b/uapi/linux/ethtool_netlink.h
index c022883cdb22..030f95d2ccdf 100644
--- a/uapi/linux/ethtool_netlink.h
+++ b/uapi/linux/ethtool_netlink.h
@@ -94,10 +94,13 @@ enum {
 #define ETHTOOL_FLAG_OMIT_REPLY	(1 << 1)
 /* request statistics, if supported by the driver */
 #define ETHTOOL_FLAG_STATS		(1 << 2)
+/* be compatible with legacy ioctl interface */
+#define ETHTOOL_FLAG_LEGACY		(1 << 3)
 
 #define ETHTOOL_FLAG_ALL (ETHTOOL_FLAG_COMPACT_BITSETS | \
 			  ETHTOOL_FLAG_OMIT_REPLY | \
-			  ETHTOOL_FLAG_STATS)
+			  ETHTOOL_FLAG_STATS | \
+			  ETHTOOL_FLAG_LEGACY)
 
 enum {
 	ETHTOOL_A_HEADER_UNSPEC,
-- 
2.26.2


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

* [RFC PATCH ethtool 2/2] netlink: Set 'ETHTOOL_FLAG_LEGACY' for compatibility with legacy ioctl interface
  2020-10-27 14:51 [RFC PATCH ethtool 0/2] Improve compatibility between netlink and ioctl interfaces Ido Schimmel
  2020-10-27 14:51 ` [RFC PATCH ethtool 1/2] update UAPI header copies Ido Schimmel
@ 2020-10-27 14:51 ` Ido Schimmel
  1 sibling, 0 replies; 3+ messages in thread
From: Ido Schimmel @ 2020-10-27 14:51 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, mkubecek, f.fainelli, andrew, David.Laight, mlxsw,
	Ido Schimmel

From: Ido Schimmel <idosch@nvidia.com>

Set the above mentioned flag in the ethtool netlink request header of
the various commands mapped to 'ethtool set' (e.g.,
'ETHTOOL_MSG_LINKMODES_SET').

The purpose of the flag is to indicate to the kernel to be compatible
with legacy ioctl interface. The current use case is to ensure that the
kernel will advertise all the supported link modes when autoneg is
enabled, but without specifying other parameters.

To prevent the kernel from complaining about unknown flags, the flag is
only set in the request header in case the kernel supports it. This is
achieved by using the recently introduced per-operation policy dump
infrastructure.

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
 netlink/netlink.c | 13 +++++++++++++
 netlink/netlink.h |  2 ++
 netlink/parser.c  |  5 ++++-
 3 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/netlink/netlink.c b/netlink/netlink.c
index f655f6ea25b7..11c5a639f381 100644
--- a/netlink/netlink.c
+++ b/netlink/netlink.c
@@ -289,6 +289,19 @@ u32 get_stats_flag(struct nl_context *nlctx, unsigned int nlcmd,
 	return nlctx->ops_info[nlcmd].hdr_flags & ETHTOOL_FLAG_STATS;
 }
 
+u32 get_legacy_flag(struct nl_context *nlctx, unsigned int nlcmd,
+		    unsigned int hdrattr)
+{
+	if (nlcmd > ETHTOOL_MSG_USER_MAX ||
+	    !(nlctx->ops_info[nlcmd].op_flags & GENL_CMD_CAP_HASPOL))
+		return 0;
+
+	if (read_flags_policy(nlctx, nlctx->ethnl_socket, nlcmd, hdrattr) < 0)
+		return 0;
+
+	return nlctx->ops_info[nlcmd].hdr_flags & ETHTOOL_FLAG_LEGACY;
+}
+
 /* initialization */
 
 static int genl_read_ops(struct nl_context *nlctx,
diff --git a/netlink/netlink.h b/netlink/netlink.h
index c02558540218..97a1e72ff930 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -74,6 +74,8 @@ const char *get_dev_name(const struct nlattr *nest);
 int get_dev_info(const struct nlattr *nest, int *ifindex, char *ifname);
 u32 get_stats_flag(struct nl_context *nlctx, unsigned int nlcmd,
 		   unsigned int hdrattr);
+u32 get_legacy_flag(struct nl_context *nlctx, unsigned int nlcmd,
+		    unsigned int hdrattr);
 
 int linkmodes_reply_cb(const struct nlmsghdr *nlhdr, void *data);
 int linkinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data);
diff --git a/netlink/parser.c b/netlink/parser.c
index 3b25f5d5a88e..7d4d51235628 100644
--- a/netlink/parser.c
+++ b/netlink/parser.c
@@ -996,6 +996,7 @@ int nl_parser(struct nl_context *nlctx, const struct param_parser *params,
 	for (parser = params; parser->arg; parser++) {
 		struct nl_msg_buff *msgbuff;
 		struct nlattr *nest;
+		u32 flags;
 
 		n_params++;
 		if (group_style == PARSER_GROUP_NONE || !parser->group)
@@ -1018,9 +1019,11 @@ int nl_parser(struct nl_context *nlctx, const struct param_parser *params,
 				goto out_free_buffs;
 			break;
 		case PARSER_GROUP_MSG:
+			flags = get_legacy_flag(nlctx, parser->group,
+						ETHTOOL_A_LINKINFO_HEADER);
 			if (ethnla_fill_header(msgbuff,
 					       ETHTOOL_A_LINKINFO_HEADER,
-					       nlctx->devname, 0))
+					       nlctx->devname, flags))
 				goto out_free_buffs;
 			break;
 		default:
-- 
2.26.2


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

end of thread, other threads:[~2020-10-27 17:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-27 14:51 [RFC PATCH ethtool 0/2] Improve compatibility between netlink and ioctl interfaces Ido Schimmel
2020-10-27 14:51 ` [RFC PATCH ethtool 1/2] update UAPI header copies Ido Schimmel
2020-10-27 14:51 ` [RFC PATCH ethtool 2/2] netlink: Set 'ETHTOOL_FLAG_LEGACY' for compatibility with legacy ioctl interface Ido Schimmel

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