netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ido Schimmel <idosch@idosch.org>
To: Michal Kubecek <mkubecek@suse.cz>
Cc: netdev@vger.kernel.org, kuba@kernel.org, mlxsw@nvidia.com,
	Ido Schimmel <idosch@nvidia.com>
Subject: Re: [RFC PATCH ethtool] ethtool: Improve compatibility between netlink and ioctl interfaces
Date: Tue, 3 Nov 2020 16:24:30 +0200	[thread overview]
Message-ID: <20201103142430.GA951743@shredder> (raw)
In-Reply-To: <20201102225803.pcrqf6nhjlvmfxwt@lion.mk-sys.cz>

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

  reply	other threads:[~2020-11-03 14:27 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-02 18:40 [RFC PATCH ethtool] ethtool: Improve compatibility between netlink and ioctl interfaces Ido Schimmel
2020-11-02 22:58 ` Michal Kubecek
2020-11-03 14:24   ` Ido Schimmel [this message]
2020-11-03 23:55     ` Michal Kubecek
2020-11-04 10:05       ` Ido Schimmel
2020-11-05 12:43         ` Ido Schimmel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201103142430.GA951743@shredder \
    --to=idosch@idosch.org \
    --cc=idosch@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --cc=mlxsw@nvidia.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).