diff mbox series

[RFC,ethtool] ethtool: Improve compatibility between netlink and ioctl interfaces

Message ID 20201102184036.866513-1-idosch@idosch.org
State New
Headers show
Series [RFC,ethtool] ethtool: Improve compatibility between netlink and ioctl interfaces | expand

Commit Message

Ido Schimmel Nov. 2, 2020, 6:40 p.m. UTC
From: Ido Schimmel <idosch@nvidia.com>

With the ioctl interface, when autoneg is enabled, but without
specifying speed, duplex or link modes, the advertised link modes are
set to the supported link modes by the ethtool user space utility.

This does not happen when using the netlink interface. Fix this
incompatibility problem by having ethtool query the supported link modes
from the kernel and advertise all of them when only "autoneg on" is
specified.

Before:

# 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

After:

# 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

Signed-off-by: Ido Schimmel <idosch@nvidia.com>
---
Michal / Jakub, let me know if you see a better way. Sending as RFC
since I want to run it through regression first.
---
 netlink/settings.c | 115 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 115 insertions(+)

Comments

Michal Kubecek Nov. 2, 2020, 10:58 p.m. UTC | #1
On Mon, Nov 02, 2020 at 08:40:36PM +0200, Ido Schimmel wrote:
> From: Ido Schimmel <idosch@nvidia.com>

> 

> With the ioctl interface, when autoneg is enabled, but without

> specifying speed, duplex or link modes, the advertised link modes are

> set to the supported link modes by the ethtool user space utility.

> 

> This does not happen when using the netlink interface. Fix this

> incompatibility problem by having ethtool query the supported link modes

> from the kernel and advertise all of them when only "autoneg on" is

> specified.

> 

> Before:

> 

> # 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

> 

> After:

> 

> # 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

> 

> Signed-off-by: Ido Schimmel <idosch@nvidia.com>

> ---

> Michal / Jakub, let me know if you see a better way. Sending as RFC

> since I want to run it through regression first.

> ---

>  netlink/settings.c | 115 +++++++++++++++++++++++++++++++++++++++++++++

>  1 file changed, 115 insertions(+)

> 

> diff --git a/netlink/settings.c b/netlink/settings.c

> index 41a2e5af1945..1f856b1b14d5 100644

> --- a/netlink/settings.c

> +++ b/netlink/settings.c

> @@ -1110,6 +1110,113 @@ static const struct param_parser sset_params[] = {

>  	{}

>  };

>  

> +static bool sset_is_autoneg_only(const struct nl_context *nlctx)

> +{

> +	return nlctx->argc == 2 && !strcmp(nlctx->argp[0], "autoneg") &&

> +	       !strcmp(nlctx->argp[1], "on");

> +}


This would only return true if there is only "autoneg on" on command
line; the ioctl parser fills all supported modes whenever none of
"speed", "duplex" and "advertise" is present, even if there are other
parameters not related to advertised modes selection (e.g. "wol").

Doing this properly from command line would require us to duplicate the
parser here which would be very inconvenient and impractical w.r.t.
future extensions.

What would probably make more sense would be modifying nl_parse() not to
send the messages itself in PARSER_GROUP_MSG case but return them back
to caller (like it does in other cases when there is only one message).
Then we could check the ETHTOOL_MSG_LINKMODES_SET message (if there is
one) for presence of ETHTOOL_A_LINKMODES_AUTONEG,
ETHTOOL_A_LINKMODES_OURS, ETHTOOL_A_LINKMODES_SPEED and
ETHTOOL_A_LINKMODES_DUPLEX (and value of ETHTOOL_A_LINKMODES_AUTONEG)
and add ETHTOOL_A_LINKMODES_OURS if needed.

I'll prepare a proof of concept of such nl_parse() rework. Fortunately
this is the only subcommand using PARSER_GROUP_MSG so that there are no
other callers that would need adjusting.

> +static int linkmodes_reply_adver_all_cb(const struct nlmsghdr *nlhdr,


                              ^^^^^ advert?

> +					void *data)

> +{

> +	const struct nlattr *bitset_tb[ETHTOOL_A_BITSET_MAX + 1] = {};

> +	const struct nlattr *tb[ETHTOOL_A_LINKMODES_MAX + 1] = {};

> +	DECLARE_ATTR_TB_INFO(bitset_tb);

> +	struct nl_context *nlctx = data;

> +	struct nl_msg_buff *msgbuff;

> +	DECLARE_ATTR_TB_INFO(tb);

> +	struct nl_socket *nlsk;

> +	struct nlattr *nest;

> +	int ret;

> +

> +	ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);

> +	if (ret < 0)

> +		return ret;

> +	if (!tb[ETHTOOL_A_LINKMODES_OURS])

> +		return -EINVAL;

> +

> +	ret = mnl_attr_parse_nested(tb[ETHTOOL_A_LINKMODES_OURS], attr_cb,

> +				    &bitset_tb_info);

> +	if (ret < 0)

> +		return ret;

> +	if (!bitset_tb[ETHTOOL_A_BITSET_SIZE] ||

> +	    !bitset_tb[ETHTOOL_A_BITSET_VALUE] ||

> +	    !bitset_tb[ETHTOOL_A_BITSET_MASK])

> +		return -EINVAL;

> +

> +	ret = netlink_init_ethnl2_socket(nlctx);

> +	if (ret < 0)

> +		return ret;

> +

> +	nlsk = nlctx->ethnl2_socket;

> +	msgbuff = &nlsk->msgbuff;

> +

> +	ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_LINKMODES_SET,

> +		       NLM_F_REQUEST | NLM_F_ACK);

> +	if (ret < 0)

> +		return ret;

> +	if (ethnla_fill_header(msgbuff, ETHTOOL_A_LINKMODES_HEADER,

> +			       nlctx->devname, 0))

> +		return -EMSGSIZE;

> +

> +	if (ethnla_put_u8(msgbuff, ETHTOOL_A_LINKMODES_AUTONEG, AUTONEG_ENABLE))

> +		return -EMSGSIZE;

> +

> +	/* Use the size and mask from the reply and set the value to the mask,

> +	 * so that all supported link modes will be advertised.

> +	 */

> +	ret = -EMSGSIZE;

> +	nest = ethnla_nest_start(msgbuff, ETHTOOL_A_LINKMODES_OURS);

> +	if (!nest)

> +		return -EMSGSIZE;

> +

> +	if (ethnla_put_u32(msgbuff, ETHTOOL_A_BITSET_SIZE,

> +			   mnl_attr_get_u32(bitset_tb[ETHTOOL_A_BITSET_SIZE])))

> +		goto err;

> +

> +	if (ethnla_put(msgbuff, ETHTOOL_A_BITSET_VALUE,

> +		       mnl_attr_get_payload_len(bitset_tb[ETHTOOL_A_BITSET_MASK]),

> +		       mnl_attr_get_payload(bitset_tb[ETHTOOL_A_BITSET_MASK])))

> +		goto err;

> +

> +	if (ethnla_put(msgbuff, ETHTOOL_A_BITSET_MASK,

> +		       mnl_attr_get_payload_len(bitset_tb[ETHTOOL_A_BITSET_MASK]),

> +		       mnl_attr_get_payload(bitset_tb[ETHTOOL_A_BITSET_MASK])))

> +		goto err;

> +

> +	ethnla_nest_end(msgbuff, nest);


To fully replicate ioctl code behaviour, we should only set the bits
corresponding to "real" link modes, not "special" ones (e.g.
ETHTOOL_LINK_MODE_TP_BIT).

> +

> +	ret = nlsock_sendmsg(nlsk, NULL);

> +	if (ret < 0)

> +		return ret;

> +	ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx);

> +	if (ret < 0)

> +		return ret;

> +

> +	return MNL_CB_OK;

> +

> +err:

> +	ethnla_nest_cancel(msgbuff, nest);

> +	return ret;

> +}

> +

> +static int sset_adver_all(struct nl_context *nlctx)


                   ^^^^^ advert?

Michal

> +{

> +	struct nl_socket *nlsk = nlctx->ethnl_socket;

> +	int ret;

> +

> +	if (netlink_cmd_check(nlctx->ctx, ETHTOOL_MSG_LINKMODES_GET, false) ||

> +	    netlink_cmd_check(nlctx->ctx, ETHTOOL_MSG_LINKMODES_SET, false))

> +		return -EOPNOTSUPP;

> +

> +	ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_LINKMODES_GET,

> +				      ETHTOOL_A_LINKMODES_HEADER,

> +				      ETHTOOL_FLAG_COMPACT_BITSETS);

> +	if (ret < 0)

> +		return ret;

> +	return nlsock_send_get_request(nlsk, linkmodes_reply_adver_all_cb);

> +}

> +

>  int nl_sset(struct cmd_context *ctx)

>  {

>  	struct nl_context *nlctx = ctx->nlctx;

> @@ -1120,6 +1227,14 @@ int nl_sset(struct cmd_context *ctx)

>  	nlctx->argc = ctx->argc;

>  	nlctx->devname = ctx->devname;

>  

> +	/* For compatibility reasons with ioctl-based ethtool, when "autoneg

> +	 * on" is specified without "advertise", "speed" and "duplex", we need

> +	 * to query the supported link modes from the kernel and advertise all

> +	 * of them.

> +	 */

> +	if (sset_is_autoneg_only(nlctx))

> +		return sset_adver_all(nlctx);

> +

>  	ret = nl_parser(nlctx, sset_params, NULL, PARSER_GROUP_MSG);

>  	if (ret < 0)

>  		return 1;

> -- 

> 2.26.2

>
Ido Schimmel Nov. 3, 2020, 2:24 p.m. UTC | #2
On Mon, Nov 02, 2020 at 11:58:03PM +0100, Michal Kubecek wrote:
> On Mon, Nov 02, 2020 at 08:40:36PM +0200, Ido Schimmel wrote:

> > +static int linkmodes_reply_adver_all_cb(const struct nlmsghdr *nlhdr,

> 

>                               ^^^^^ advert?

> 

> > +					void *data)

> > +{

> > +	const struct nlattr *bitset_tb[ETHTOOL_A_BITSET_MAX + 1] = {};

> > +	const struct nlattr *tb[ETHTOOL_A_LINKMODES_MAX + 1] = {};

> > +	DECLARE_ATTR_TB_INFO(bitset_tb);

> > +	struct nl_context *nlctx = data;

> > +	struct nl_msg_buff *msgbuff;

> > +	DECLARE_ATTR_TB_INFO(tb);

> > +	struct nl_socket *nlsk;

> > +	struct nlattr *nest;

> > +	int ret;

> > +

> > +	ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);

> > +	if (ret < 0)

> > +		return ret;

> > +	if (!tb[ETHTOOL_A_LINKMODES_OURS])

> > +		return -EINVAL;

> > +

> > +	ret = mnl_attr_parse_nested(tb[ETHTOOL_A_LINKMODES_OURS], attr_cb,

> > +				    &bitset_tb_info);

> > +	if (ret < 0)

> > +		return ret;

> > +	if (!bitset_tb[ETHTOOL_A_BITSET_SIZE] ||

> > +	    !bitset_tb[ETHTOOL_A_BITSET_VALUE] ||

> > +	    !bitset_tb[ETHTOOL_A_BITSET_MASK])

> > +		return -EINVAL;

> > +

> > +	ret = netlink_init_ethnl2_socket(nlctx);

> > +	if (ret < 0)

> > +		return ret;

> > +

> > +	nlsk = nlctx->ethnl2_socket;

> > +	msgbuff = &nlsk->msgbuff;

> > +

> > +	ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_LINKMODES_SET,

> > +		       NLM_F_REQUEST | NLM_F_ACK);

> > +	if (ret < 0)

> > +		return ret;

> > +	if (ethnla_fill_header(msgbuff, ETHTOOL_A_LINKMODES_HEADER,

> > +			       nlctx->devname, 0))

> > +		return -EMSGSIZE;

> > +

> > +	if (ethnla_put_u8(msgbuff, ETHTOOL_A_LINKMODES_AUTONEG, AUTONEG_ENABLE))

> > +		return -EMSGSIZE;

> > +

> > +	/* Use the size and mask from the reply and set the value to the mask,

> > +	 * so that all supported link modes will be advertised.

> > +	 */

> > +	ret = -EMSGSIZE;

> > +	nest = ethnla_nest_start(msgbuff, ETHTOOL_A_LINKMODES_OURS);

> > +	if (!nest)

> > +		return -EMSGSIZE;

> > +

> > +	if (ethnla_put_u32(msgbuff, ETHTOOL_A_BITSET_SIZE,

> > +			   mnl_attr_get_u32(bitset_tb[ETHTOOL_A_BITSET_SIZE])))

> > +		goto err;

> > +

> > +	if (ethnla_put(msgbuff, ETHTOOL_A_BITSET_VALUE,

> > +		       mnl_attr_get_payload_len(bitset_tb[ETHTOOL_A_BITSET_MASK]),

> > +		       mnl_attr_get_payload(bitset_tb[ETHTOOL_A_BITSET_MASK])))

> > +		goto err;

> > +

> > +	if (ethnla_put(msgbuff, ETHTOOL_A_BITSET_MASK,

> > +		       mnl_attr_get_payload_len(bitset_tb[ETHTOOL_A_BITSET_MASK]),

> > +		       mnl_attr_get_payload(bitset_tb[ETHTOOL_A_BITSET_MASK])))

> > +		goto err;

> > +

> > +	ethnla_nest_end(msgbuff, nest);

> 

> To fully replicate ioctl code behaviour, we should only set the bits

> corresponding to "real" link modes, not "special" ones (e.g.

> ETHTOOL_LINK_MODE_TP_BIT).


Michal,

I have the changes you requested here:
https://github.com/idosch/ethtool/commit/b34d15839f2662808c566c04eda726113e20ee59

Do you want to integrate it with your nl_parse() rework or should I?

Thanks
Michal Kubecek Nov. 3, 2020, 11:55 p.m. UTC | #3
On Tue, Nov 03, 2020 at 04:24:30PM +0200, Ido Schimmel wrote:
> 

> I have the changes you requested here:

> https://github.com/idosch/ethtool/commit/b34d15839f2662808c566c04eda726113e20ee59

> 

> Do you want to integrate it with your nl_parse() rework or should I?


I pushed the combined series to

  https://git.kernel.org/pub/scm/linux/kernel/git/mkubecek/ethtool.git

as branch mk/master/advertise-all. I only ran few quick tests so far,
it's not submission ready yet.

First two patches are unrelated fixes found while testing, I'm going to
submit and push them separately. Third patch reworks nl_parser()
handling of multiple request messages as indicated in my previous mail.
Fourth patch is the ioctl compatibility fix.

Michal
Ido Schimmel Nov. 4, 2020, 10:05 a.m. UTC | #4
On Wed, Nov 04, 2020 at 12:55:01AM +0100, Michal Kubecek wrote:
> On Tue, Nov 03, 2020 at 04:24:30PM +0200, Ido Schimmel wrote:
> > 
> > I have the changes you requested here:
> > https://github.com/idosch/ethtool/commit/b34d15839f2662808c566c04eda726113e20ee59
> > 
> > Do you want to integrate it with your nl_parse() rework or should I?
> 
> I pushed the combined series to
> 
>   https://git.kernel.org/pub/scm/linux/kernel/git/mkubecek/ethtool.git
> 
> as branch mk/master/advertise-all. I only ran few quick tests so far,
> it's not submission ready yet.
> 
> First two patches are unrelated fixes found while testing, I'm going to
> submit and push them separately. Third patch reworks nl_parser()
> handling of multiple request messages as indicated in my previous mail.
> Fourth patch is the ioctl compatibility fix.

Great, thank you. I pushed the patches to our regression. Will go over
the results tomorrow and let you know.
Ido Schimmel Nov. 5, 2020, 12:43 p.m. UTC | #5
On Wed, Nov 04, 2020 at 12:05:18PM +0200, Ido Schimmel wrote:
> On Wed, Nov 04, 2020 at 12:55:01AM +0100, Michal Kubecek wrote:
> > On Tue, Nov 03, 2020 at 04:24:30PM +0200, Ido Schimmel wrote:
> > > 
> > > I have the changes you requested here:
> > > https://github.com/idosch/ethtool/commit/b34d15839f2662808c566c04eda726113e20ee59
> > > 
> > > Do you want to integrate it with your nl_parse() rework or should I?
> > 
> > I pushed the combined series to
> > 
> >   https://git.kernel.org/pub/scm/linux/kernel/git/mkubecek/ethtool.git
> > 
> > as branch mk/master/advertise-all. I only ran few quick tests so far,
> > it's not submission ready yet.
> > 
> > First two patches are unrelated fixes found while testing, I'm going to
> > submit and push them separately. Third patch reworks nl_parser()
> > handling of multiple request messages as indicated in my previous mail.
> > Fourth patch is the ioctl compatibility fix.
> 
> Great, thank you. I pushed the patches to our regression. Will go over
> the results tomorrow and let you know.

Looks OK. Thanks again.
diff mbox series

Patch

diff --git a/netlink/settings.c b/netlink/settings.c
index 41a2e5af1945..1f856b1b14d5 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -1110,6 +1110,113 @@  static const struct param_parser sset_params[] = {
 	{}
 };
 
+static bool sset_is_autoneg_only(const struct nl_context *nlctx)
+{
+	return nlctx->argc == 2 && !strcmp(nlctx->argp[0], "autoneg") &&
+	       !strcmp(nlctx->argp[1], "on");
+}
+
+static int linkmodes_reply_adver_all_cb(const struct nlmsghdr *nlhdr,
+					void *data)
+{
+	const struct nlattr *bitset_tb[ETHTOOL_A_BITSET_MAX + 1] = {};
+	const struct nlattr *tb[ETHTOOL_A_LINKMODES_MAX + 1] = {};
+	DECLARE_ATTR_TB_INFO(bitset_tb);
+	struct nl_context *nlctx = data;
+	struct nl_msg_buff *msgbuff;
+	DECLARE_ATTR_TB_INFO(tb);
+	struct nl_socket *nlsk;
+	struct nlattr *nest;
+	int ret;
+
+	ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+	if (ret < 0)
+		return ret;
+	if (!tb[ETHTOOL_A_LINKMODES_OURS])
+		return -EINVAL;
+
+	ret = mnl_attr_parse_nested(tb[ETHTOOL_A_LINKMODES_OURS], attr_cb,
+				    &bitset_tb_info);
+	if (ret < 0)
+		return ret;
+	if (!bitset_tb[ETHTOOL_A_BITSET_SIZE] ||
+	    !bitset_tb[ETHTOOL_A_BITSET_VALUE] ||
+	    !bitset_tb[ETHTOOL_A_BITSET_MASK])
+		return -EINVAL;
+
+	ret = netlink_init_ethnl2_socket(nlctx);
+	if (ret < 0)
+		return ret;
+
+	nlsk = nlctx->ethnl2_socket;
+	msgbuff = &nlsk->msgbuff;
+
+	ret = msg_init(nlctx, msgbuff, ETHTOOL_MSG_LINKMODES_SET,
+		       NLM_F_REQUEST | NLM_F_ACK);
+	if (ret < 0)
+		return ret;
+	if (ethnla_fill_header(msgbuff, ETHTOOL_A_LINKMODES_HEADER,
+			       nlctx->devname, 0))
+		return -EMSGSIZE;
+
+	if (ethnla_put_u8(msgbuff, ETHTOOL_A_LINKMODES_AUTONEG, AUTONEG_ENABLE))
+		return -EMSGSIZE;
+
+	/* Use the size and mask from the reply and set the value to the mask,
+	 * so that all supported link modes will be advertised.
+	 */
+	ret = -EMSGSIZE;
+	nest = ethnla_nest_start(msgbuff, ETHTOOL_A_LINKMODES_OURS);
+	if (!nest)
+		return -EMSGSIZE;
+
+	if (ethnla_put_u32(msgbuff, ETHTOOL_A_BITSET_SIZE,
+			   mnl_attr_get_u32(bitset_tb[ETHTOOL_A_BITSET_SIZE])))
+		goto err;
+
+	if (ethnla_put(msgbuff, ETHTOOL_A_BITSET_VALUE,
+		       mnl_attr_get_payload_len(bitset_tb[ETHTOOL_A_BITSET_MASK]),
+		       mnl_attr_get_payload(bitset_tb[ETHTOOL_A_BITSET_MASK])))
+		goto err;
+
+	if (ethnla_put(msgbuff, ETHTOOL_A_BITSET_MASK,
+		       mnl_attr_get_payload_len(bitset_tb[ETHTOOL_A_BITSET_MASK]),
+		       mnl_attr_get_payload(bitset_tb[ETHTOOL_A_BITSET_MASK])))
+		goto err;
+
+	ethnla_nest_end(msgbuff, nest);
+
+	ret = nlsock_sendmsg(nlsk, NULL);
+	if (ret < 0)
+		return ret;
+	ret = nlsock_process_reply(nlsk, nomsg_reply_cb, nlctx);
+	if (ret < 0)
+		return ret;
+
+	return MNL_CB_OK;
+
+err:
+	ethnla_nest_cancel(msgbuff, nest);
+	return ret;
+}
+
+static int sset_adver_all(struct nl_context *nlctx)
+{
+	struct nl_socket *nlsk = nlctx->ethnl_socket;
+	int ret;
+
+	if (netlink_cmd_check(nlctx->ctx, ETHTOOL_MSG_LINKMODES_GET, false) ||
+	    netlink_cmd_check(nlctx->ctx, ETHTOOL_MSG_LINKMODES_SET, false))
+		return -EOPNOTSUPP;
+
+	ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_LINKMODES_GET,
+				      ETHTOOL_A_LINKMODES_HEADER,
+				      ETHTOOL_FLAG_COMPACT_BITSETS);
+	if (ret < 0)
+		return ret;
+	return nlsock_send_get_request(nlsk, linkmodes_reply_adver_all_cb);
+}
+
 int nl_sset(struct cmd_context *ctx)
 {
 	struct nl_context *nlctx = ctx->nlctx;
@@ -1120,6 +1227,14 @@  int nl_sset(struct cmd_context *ctx)
 	nlctx->argc = ctx->argc;
 	nlctx->devname = ctx->devname;
 
+	/* For compatibility reasons with ioctl-based ethtool, when "autoneg
+	 * on" is specified without "advertise", "speed" and "duplex", we need
+	 * to query the supported link modes from the kernel and advertise all
+	 * of them.
+	 */
+	if (sset_is_autoneg_only(nlctx))
+		return sset_adver_all(nlctx);
+
 	ret = nl_parser(nlctx, sset_params, NULL, PARSER_GROUP_MSG);
 	if (ret < 0)
 		return 1;