All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH ethtool-next] linkstate: report the number of hard link flaps
Date: Tue, 29 Nov 2022 17:37:36 -0800	[thread overview]
Message-ID: <20221130013736.90875-1-kuba@kernel.org> (raw)

Print the recently added link down event statistics when
present. We need to query the netlink policy to know if
the stats are supported.

Signed-off-by: Jakub Kicinski <kuba@kernel.org>
---
 netlink/settings.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/netlink/settings.c b/netlink/settings.c
index ea86e365383b..14ad0b46e102 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -5,6 +5,7 @@
  */
 
 #include <errno.h>
+#include <inttypes.h>
 #include <string.h>
 #include <stdio.h>
 
@@ -772,6 +773,13 @@ int linkstate_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 		}
 	}
 
+	if (tb[ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT]) {
+		uint32_t val;
+
+		val = mnl_attr_get_u32(tb[ETHTOOL_A_LINKSTATE_EXT_DOWN_CNT]);
+		printf("\tLink Down Events: %u\n", val);
+	}
+
 	return MNL_CB_OK;
 }
 
@@ -882,12 +890,16 @@ int debug_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 	return MNL_CB_OK;
 }
 
-static int gset_request(struct nl_socket *nlsk, uint8_t msg_type,
+static int gset_request(struct nl_context *nlctx, uint8_t msg_type,
 			uint16_t hdr_attr, mnl_cb_t cb)
 {
+	struct nl_socket *nlsk = nlctx->ethnl_socket;
+	u32 flags;
 	int ret;
 
-	ret = nlsock_prep_get_request(nlsk, msg_type, hdr_attr, 0);
+	flags = get_stats_flag(nlctx, msg_type, hdr_attr);
+
+	ret = nlsock_prep_get_request(nlsk, msg_type, hdr_attr, flags);
 	if (ret < 0)
 		return ret;
 	return nlsock_send_get_request(nlsk, cb);
@@ -896,7 +908,6 @@ static int gset_request(struct nl_socket *nlsk, uint8_t msg_type,
 int nl_gset(struct cmd_context *ctx)
 {
 	struct nl_context *nlctx = ctx->nlctx;
-	struct nl_socket *nlsk = nlctx->ethnl_socket;
 	int ret;
 
 	if (netlink_cmd_check(ctx, ETHTOOL_MSG_LINKMODES_GET, true) ||
@@ -908,27 +919,27 @@ int nl_gset(struct cmd_context *ctx)
 
 	nlctx->suppress_nlerr = 1;
 
-	ret = gset_request(nlsk, ETHTOOL_MSG_LINKMODES_GET,
+	ret = gset_request(nlctx, ETHTOOL_MSG_LINKMODES_GET,
 			   ETHTOOL_A_LINKMODES_HEADER, linkmodes_reply_cb);
 	if (ret == -ENODEV)
 		return ret;
 
-	ret = gset_request(nlsk, ETHTOOL_MSG_LINKINFO_GET,
+	ret = gset_request(nlctx, ETHTOOL_MSG_LINKINFO_GET,
 			   ETHTOOL_A_LINKINFO_HEADER, linkinfo_reply_cb);
 	if (ret == -ENODEV)
 		return ret;
 
-	ret = gset_request(nlsk, ETHTOOL_MSG_WOL_GET, ETHTOOL_A_WOL_HEADER,
+	ret = gset_request(nlctx, ETHTOOL_MSG_WOL_GET, ETHTOOL_A_WOL_HEADER,
 			   wol_reply_cb);
 	if (ret == -ENODEV)
 		return ret;
 
-	ret = gset_request(nlsk, ETHTOOL_MSG_DEBUG_GET, ETHTOOL_A_DEBUG_HEADER,
+	ret = gset_request(nlctx, ETHTOOL_MSG_DEBUG_GET, ETHTOOL_A_DEBUG_HEADER,
 			   debug_reply_cb);
 	if (ret == -ENODEV)
 		return ret;
 
-	ret = gset_request(nlsk, ETHTOOL_MSG_LINKSTATE_GET,
+	ret = gset_request(nlctx, ETHTOOL_MSG_LINKSTATE_GET,
 			   ETHTOOL_A_LINKSTATE_HEADER, linkstate_reply_cb);
 	if (ret == -ENODEV)
 		return ret;
-- 
2.38.1


             reply	other threads:[~2022-11-30  1:37 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-30  1:37 Jakub Kicinski [this message]
2022-12-04 17:10 ` [PATCH ethtool-next] linkstate: report the number of hard link flaps 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=20221130013736.90875-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.