[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20200630092412.11432-4-amitc@mellanox.com>
Date: Tue, 30 Jun 2020 12:24:12 +0300
From: Amit Cohen <amitc@...lanox.com>
To: netdev@...r.kernel.org
Cc: mkubecek@...e.cz, davem@...emloft.net, o.rempel@...gutronix.de,
andrew@...n.ch, f.fainelli@...il.com, jacob.e.keller@...el.com,
mlxsw@...lanox.com, Amit Cohen <amitc@...lanox.com>
Subject: [PATCH ethtool 3/3] netlink: settings: expand linkstate_reply_cb() to support link extended state
Print extended state in addition to link state.
In case that extended state is not provided, print state only.
If extended substate is provided in addition to the extended state,
print it also.
Signed-off-by: Amit Cohen <amitc@...lanox.com>
---
netlink/settings.c | 59 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 56 insertions(+), 3 deletions(-)
diff --git a/netlink/settings.c b/netlink/settings.c
index 35ba2f5..a4d1908 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -604,6 +604,57 @@ int linkinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data)
return MNL_CB_OK;
}
+int linkstate_link_ext_substate_print(const struct nlattr *tb[],
+ struct nl_context *nlctx, uint8_t link_val,
+ uint8_t link_ext_state_val,
+ const char *link_ext_state_str)
+{
+ uint8_t link_ext_substate_val;
+ const char *link_ext_substate_str;
+
+ if (!tb[ETHTOOL_A_LINKSTATE_EXT_SUBSTATE])
+ return -ENODATA;
+
+ link_ext_substate_val = mnl_attr_get_u8(tb[ETHTOOL_A_LINKSTATE_EXT_SUBSTATE]);
+
+ link_ext_substate_str = link_ext_substate_get(link_ext_state_val, link_ext_substate_val);
+ if (!link_ext_substate_str)
+ return -ENODATA;
+
+ print_banner(nlctx);
+ printf("\tLink detected: %s (%s, %s)\n", link_val ? "yes" : "no",
+ link_ext_state_str, link_ext_substate_str);
+
+ return 0;
+}
+
+int linkstate_link_ext_state_print(const struct nlattr *tb[],
+ struct nl_context *nlctx, uint8_t link_val)
+{
+ uint8_t link_ext_state_val;
+ const char *link_ext_state_str;
+ int ret;
+
+ if (!tb[ETHTOOL_A_LINKSTATE_EXT_STATE])
+ return -ENODATA;
+
+ link_ext_state_val = mnl_attr_get_u8(tb[ETHTOOL_A_LINKSTATE_EXT_STATE]);
+
+ link_ext_state_str = link_ext_state_get(link_ext_state_val);
+ if (!link_ext_state_str)
+ return -ENODATA;
+
+ ret = linkstate_link_ext_substate_print(tb, nlctx, link_val, link_ext_state_val,
+ link_ext_state_str);
+ if (ret < 0) {
+ print_banner(nlctx);
+ printf("\tLink detected: %s (%s)\n", link_val ? "yes" : "no",
+ link_ext_state_str);
+ }
+
+ return 0;
+}
+
int linkstate_reply_cb(const struct nlmsghdr *nlhdr, void *data)
{
const struct nlattr *tb[ETHTOOL_A_LINKSTATE_MAX + 1] = {};
@@ -622,9 +673,11 @@ int linkstate_reply_cb(const struct nlmsghdr *nlhdr, void *data)
if (tb[ETHTOOL_A_LINKSTATE_LINK]) {
uint8_t val = mnl_attr_get_u8(tb[ETHTOOL_A_LINKSTATE_LINK]);
-
- print_banner(nlctx);
- printf("\tLink detected: %s\n", val ? "yes" : "no");
+ ret = linkstate_link_ext_state_print(tb, nlctx, val);
+ if (ret < 0) {
+ print_banner(nlctx);
+ printf("\tLink detected: %s\n", val ? "yes" : "no");
+ }
}
if (tb[ETHTOOL_A_LINKSTATE_SQI]) {
--
2.20.1
Powered by blists - more mailing lists