Improve compatibility between netlink and ioctl interfaces
Subsystems (2)
cover Improve compatibility between netlink and ioctl interfaces
From: Ido Schimmel <[email protected]>
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: yesExample #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: yesIn 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(-)
Signature · 1 line
2.26.2
RFC PATCH 1/2 update UAPI header copies
From: Ido Schimmel <[email protected]>
Update to kernel commit XXX.
--- uapi/linux/ethtool_netlink.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
uapi/linux/ethtool_netlink.h +4 -1
@@ -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 ,
Signature · 1 line
2.26.2
RFC PATCH 2/2 netlink: Set 'ETHTOOL_FLAG_LEGACY' for compatibility with legacy ioctl interface
In reply to Ido SchimmelFrom: Ido Schimmel <[email protected]>
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.
--- netlink/netlink.c | 13 +++++++++++++ netlink/netlink.h | 2 ++ netlink/parser.c | 5 ++++- 3 files changed, 19 insertions(+), 1 deletion(-)
netlink/netlink.c +13 -0
@@ -289,6 +289,19 @@ u32 get_stats_flag(struct nl_context *nlctx, unsigned int nlcmd,return nlctx->ops_info[nlcmd].hdr_flags ÐTOOL_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 ÐTOOL_FLAG_LEGACY ; +} +/* initialization */ static int genl_read_ops(struct nl_context *nlctx,
netlink/netlink.h +2 -0
@@ -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);
netlink/parser.c +4 -1
@@ -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 :
Signature · 1 line
2.26.2