[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <46f0124e315d12e972cee154d76a279dac6b1bb9.1581892124.git.mkubecek@suse.cz>
Date: Sun, 16 Feb 2020 23:47:46 +0100 (CET)
From: Michal Kubecek <mkubecek@...e.cz>
To: John Linville <linville@...driver.com>, netdev@...r.kernel.org
Cc: Andrew Lunn <andrew@...n.ch>,
Florian Fainelli <f.fainelli@...il.com>
Subject: [PATCH ethtool 15/19] netlink: support getting wake-on-lan and
debugging settings
Finish "ethtool <dev>" command implementation by adding support for
wake-on-lan (ETHTOOL_MSG_WOL_GET) and debugging (ETHTOOL_MSG_DEBUG_GET,
currently only msglevel) settings.
Register the callbacks also with monitor so that "ethtool --monitor" can
display corresponding notifications.
Signed-off-by: Michal Kubecek <mkubecek@...e.cz>
---
netlink/monitor.c | 16 +++++++
netlink/netlink.h | 2 +
netlink/settings.c | 111 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 129 insertions(+)
diff --git a/netlink/monitor.c b/netlink/monitor.c
index e8fdcd2b93ef..5fce6b64c08c 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -23,6 +23,14 @@ static struct {
.cmd = ETHTOOL_MSG_LINKINFO_NTF,
.cb = linkinfo_reply_cb,
},
+ {
+ .cmd = ETHTOOL_MSG_WOL_NTF,
+ .cb = wol_reply_cb,
+ },
+ {
+ .cmd = ETHTOOL_MSG_DEBUG_NTF,
+ .cb = debug_reply_cb,
+ },
};
static void clear_filter(struct nl_context *nlctx)
@@ -86,6 +94,14 @@ static struct monitor_option monitor_opts[] = {
.pattern = "-s|--change",
.cmd = ETHTOOL_MSG_LINKMODES_NTF,
},
+ {
+ .pattern = "-s|--change",
+ .cmd = ETHTOOL_MSG_WOL_NTF,
+ },
+ {
+ .pattern = "-s|--change",
+ .cmd = ETHTOOL_MSG_DEBUG_NTF,
+ },
};
static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/netlink.h b/netlink/netlink.h
index 790d0802b925..5e1d00ed9ce8 100644
--- a/netlink/netlink.h
+++ b/netlink/netlink.h
@@ -48,6 +48,8 @@ int get_dev_info(const struct nlattr *nest, int *ifindex, char *ifname);
int linkmodes_reply_cb(const struct nlmsghdr *nlhdr, void *data);
int linkinfo_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data);
+int debug_reply_cb(const struct nlmsghdr *nlhdr, void *data);
static inline void copy_devname(char *dst, const char *src)
{
diff --git a/netlink/settings.c b/netlink/settings.c
index 24b7a4495961..fed121471d0f 100644
--- a/netlink/settings.c
+++ b/netlink/settings.c
@@ -605,6 +605,101 @@ int linkstate_reply_cb(const struct nlmsghdr *nlhdr, void *data)
return MNL_CB_OK;
}
+void wol_modes_cb(unsigned int idx, const char *name, bool val, void *data)
+{
+ struct ethtool_wolinfo *wol = data;
+
+ if (idx >= 32)
+ return;
+ wol->supported |= (1U << idx);
+ if (val)
+ wol->wolopts |= (1U << idx);
+}
+
+int wol_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHTOOL_A_WOL_MAX + 1] = {};
+ DECLARE_ATTR_TB_INFO(tb);
+ struct nl_context *nlctx = data;
+ struct ethtool_wolinfo wol = {};
+ int ret;
+
+ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+ if (ret < 0)
+ return ret;
+ nlctx->devname = get_dev_name(tb[ETHTOOL_A_WOL_HEADER]);
+ if (!dev_ok(nlctx))
+ return MNL_CB_OK;
+
+ if (tb[ETHTOOL_A_WOL_MODES])
+ walk_bitset(tb[ETHTOOL_A_WOL_MODES], NULL, wol_modes_cb, &wol);
+ if (tb[ETHTOOL_A_WOL_SOPASS]) {
+ unsigned int len;
+
+ len = mnl_attr_get_payload_len(tb[ETHTOOL_A_WOL_SOPASS]);
+ if (len != SOPASS_MAX)
+ fprintf(stderr, "invalid SecureOn password length %u (should be %u)\n",
+ len, SOPASS_MAX);
+ else
+ memcpy(wol.sopass,
+ mnl_attr_get_payload(tb[ETHTOOL_A_WOL_SOPASS]),
+ SOPASS_MAX);
+ }
+ dump_wol(&wol);
+
+ return MNL_CB_OK;
+}
+
+void msgmask_cb(unsigned int idx, const char *name, bool val, void *data)
+{
+ u32 *msg_mask = data;
+
+ if (idx >= 32)
+ return;
+ if (val)
+ *msg_mask |= (1U << idx);
+}
+
+void msgmask_cb2(unsigned int idx, const char *name, bool val, void *data)
+{
+ if (val)
+ printf(" %s", name);
+}
+
+int debug_reply_cb(const struct nlmsghdr *nlhdr, void *data)
+{
+ const struct nlattr *tb[ETHTOOL_A_DEBUG_MAX + 1] = {};
+ DECLARE_ATTR_TB_INFO(tb);
+ const struct stringset *msgmask_strings;
+ struct nl_context *nlctx = data;
+ u32 msg_mask = 0;
+ int ret;
+
+ ret = mnl_attr_parse(nlhdr, GENL_HDRLEN, attr_cb, &tb_info);
+ if (ret < 0)
+ return ret;
+ nlctx->devname = get_dev_name(tb[ETHTOOL_A_DEBUG_HEADER]);
+ if (!dev_ok(nlctx))
+ return MNL_CB_OK;
+
+ if (!tb[ETHTOOL_A_DEBUG_MSGMASK])
+ return MNL_CB_OK;
+ ret = netlink_init_ethnl2_socket(nlctx);
+ if (ret < 0)
+ return MNL_CB_OK;
+ msgmask_strings = global_stringset(ETH_SS_MSG_CLASSES,
+ nlctx->ethnl2_socket);
+ walk_bitset(tb[ETHTOOL_A_DEBUG_MSGMASK], NULL, msgmask_cb, &msg_mask);
+ printf(" Current message level: 0x%08x (%u)\n"
+ " ",
+ msg_mask, msg_mask);
+ walk_bitset(tb[ETHTOOL_A_DEBUG_MSGMASK], msgmask_strings, msgmask_cb2,
+ NULL);
+ fputc('\n', stdout);
+
+ return MNL_CB_OK;
+}
+
int nl_gset(struct cmd_context *ctx)
{
struct nl_context *nlctx = ctx->nlctx;
@@ -635,6 +730,22 @@ int nl_gset(struct cmd_context *ctx)
if (ret < 0)
goto err;
+ ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_WOL_GET,
+ ETHTOOL_A_WOL_HEADER, 0);
+ if (ret < 0)
+ goto err;
+ ret = nlsock_send_get_request(nlsk, wol_reply_cb);
+ if (ret < 0)
+ goto err;
+
+ ret = nlsock_prep_get_request(nlsk, ETHTOOL_MSG_DEBUG_GET,
+ ETHTOOL_A_DEBUG_HEADER, 0);
+ if (ret < 0)
+ goto err;
+ ret = nlsock_send_get_request(nlsk, debug_reply_cb);
+ if (ret < 0)
+ goto err;
+
return 0;
err:
return 75;
--
2.25.0
Powered by blists - more mailing lists