From: Jakub Kicinski <kuba@kernel.org>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, piergiorgio.beruto@gmail.com,
Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH ethtool] netlink: settings: fix netlink support when PLCA is not present
Date: Mon, 24 Apr 2023 17:07:42 -0700 [thread overview]
Message-ID: <20230425000742.130480-1-kuba@kernel.org> (raw)
PLCA support threw the PLCA commands as required into the initial
support check at the start of nl_gset(). That's not correct.
The initial check (AFAIU) queries for the base support in the kernel
i.e. support for the commands which correspond to ioctls.
If those are not available (presumably very old kernel or kernel
without ethtool-netlink) we're better off using the ioctl.
For new functionality, however, falling back to ioctl
is counterproductive. New functionality (like PLCA) isn't
supported via the ioctl, anyway, and we're losing all the other
netlink-only functionality (I noticed that the link down statistics
are gone).
After much deliberation I decided to add a second check for
command support in gset_request(). Seems cleanest and if any
of the non-required commands narrows the capabilities (e.g.
does not support dump) we should just skip it too. Falling
back to ioctl would again be a regression.
Fixes: cf02fc1b1095 ("add support for IEEE 802.3cg-2019 Clause 148")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
netlink/settings.c | 31 ++++++++++++++++---------------
1 file changed, 16 insertions(+), 15 deletions(-)
diff --git a/netlink/settings.c b/netlink/settings.c
index 168b182530a2..4fd75d2e0a5a 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -963,13 +963,17 @@ int plca_status_reply_cb(const struct nlmsghdr *nlhdr, void *data)
return MNL_CB_OK;
}
-static int gset_request(struct nl_context *nlctx, uint8_t msg_type,
+static int gset_request(struct cmd_context *ctx, uint8_t msg_type,
uint16_t hdr_attr, mnl_cb_t cb)
{
+ struct nl_context *nlctx = ctx->nlctx;
struct nl_socket *nlsk = nlctx->ethnl_socket;
u32 flags;
int ret;
+ if (netlink_cmd_check(ctx, msg_type, true))
+ return 0;
+
flags = get_stats_flag(nlctx, msg_type, hdr_attr);
ret = nlsock_prep_get_request(nlsk, msg_type, hdr_attr, flags);
@@ -980,61 +984,58 @@ static int gset_request(struct nl_context *nlctx, uint8_t msg_type,
int nl_gset(struct cmd_context *ctx)
{
- struct nl_context *nlctx = ctx->nlctx;
int ret;
+ /* Check for the base set of commands */
if (netlink_cmd_check(ctx, ETHTOOL_MSG_LINKMODES_GET, true) ||
netlink_cmd_check(ctx, ETHTOOL_MSG_LINKINFO_GET, true) ||
netlink_cmd_check(ctx, ETHTOOL_MSG_WOL_GET, true) ||
netlink_cmd_check(ctx, ETHTOOL_MSG_DEBUG_GET, true) ||
- netlink_cmd_check(ctx, ETHTOOL_MSG_LINKSTATE_GET, true) ||
- netlink_cmd_check(ctx, ETHTOOL_MSG_PLCA_GET_CFG, true) ||
- netlink_cmd_check(ctx, ETHTOOL_MSG_PLCA_GET_STATUS, true))
+ netlink_cmd_check(ctx, ETHTOOL_MSG_LINKSTATE_GET, true))
return -EOPNOTSUPP;
- nlctx->suppress_nlerr = 1;
+ ctx->nlctx->suppress_nlerr = 1;
- ret = gset_request(nlctx, ETHTOOL_MSG_LINKMODES_GET,
+ ret = gset_request(ctx, ETHTOOL_MSG_LINKMODES_GET,
ETHTOOL_A_LINKMODES_HEADER, linkmodes_reply_cb);
if (ret == -ENODEV)
return ret;
- ret = gset_request(nlctx, ETHTOOL_MSG_LINKINFO_GET,
+ ret = gset_request(ctx, ETHTOOL_MSG_LINKINFO_GET,
ETHTOOL_A_LINKINFO_HEADER, linkinfo_reply_cb);
if (ret == -ENODEV)
return ret;
- ret = gset_request(nlctx, ETHTOOL_MSG_WOL_GET, ETHTOOL_A_WOL_HEADER,
+ ret = gset_request(ctx, ETHTOOL_MSG_WOL_GET, ETHTOOL_A_WOL_HEADER,
wol_reply_cb);
if (ret == -ENODEV)
return ret;
- ret = gset_request(nlctx, ETHTOOL_MSG_PLCA_GET_CFG,
+ ret = gset_request(ctx, ETHTOOL_MSG_PLCA_GET_CFG,
ETHTOOL_A_PLCA_HEADER, plca_cfg_reply_cb);
if (ret == -ENODEV)
return ret;
- ret = gset_request(nlctx, ETHTOOL_MSG_DEBUG_GET, ETHTOOL_A_DEBUG_HEADER,
+ ret = gset_request(ctx, ETHTOOL_MSG_DEBUG_GET, ETHTOOL_A_DEBUG_HEADER,
debug_reply_cb);
if (ret == -ENODEV)
return ret;
- ret = gset_request(nlctx, ETHTOOL_MSG_LINKSTATE_GET,
+ ret = gset_request(ctx, ETHTOOL_MSG_LINKSTATE_GET,
ETHTOOL_A_LINKSTATE_HEADER, linkstate_reply_cb);
if (ret == -ENODEV)
return ret;
- ret = gset_request(nlctx, ETHTOOL_MSG_PLCA_GET_STATUS,
+ ret = gset_request(ctx, ETHTOOL_MSG_PLCA_GET_STATUS,
ETHTOOL_A_PLCA_HEADER, plca_status_reply_cb);
if (ret == -ENODEV)
return ret;
- if (!nlctx->no_banner) {
+ if (!ctx->nlctx->no_banner) {
printf("No data available\n");
return 75;
}
-
return 0;
}
--
2.40.0
next reply other threads:[~2023-04-25 0:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 0:07 Jakub Kicinski [this message]
2023-04-25 10:33 ` [PATCH ethtool] netlink: settings: fix netlink support when PLCA is not present Piergiorgio Beruto
2023-04-25 14:40 ` Piergiorgio Beruto
2023-04-25 15:34 ` Jakub Kicinski
2023-05-07 22:40 ` patchwork-bot+netdevbpf
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=20230425000742.130480-1-kuba@kernel.org \
--to=kuba@kernel.org \
--cc=mkubecek@suse.cz \
--cc=netdev@vger.kernel.org \
--cc=piergiorgio.beruto@gmail.com \
/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).