lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <4be8974cd7e4b23a564ec5f209497401af05cb0c.1532954671.git.mkubecek@suse.cz>
Date:   Mon, 30 Jul 2018 14:57:04 +0200 (CEST)
From:   Michal Kubecek <mkubecek@...e.cz>
To:     netdev@...r.kernel.org
Cc:     linux-kernel@...r.kernel.org,
        "John W. Linville" <linville@...driver.com>
Subject: [RFC PATCH ethtool v2 16/23] netlink: add netlink handler for geee
 (--show-eee)

Implement "ethtool --show-eee <dev>" subcommand using netlink interface
command ETHNL_CMD_GET_PARAMS with ETH_PARAMS_IM_EEE mask.

Signed-off-by: Michal Kubecek <mkubecek@...e.cz>
---
 ethtool.c         |  3 ++-
 netlink/extapi.h  |  1 +
 netlink/monitor.c |  5 ++++
 netlink/params.c  | 66 +++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 1 deletion(-)

diff --git a/ethtool.c b/ethtool.c
index 2bcc1944ba29..1ad0cd10735a 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -4883,6 +4883,7 @@ static int show_usage(struct cmd_context *ctx);
 #define nl_gring	NULL
 #define nl_gpause	NULL
 #define nl_gchannels	NULL
+#define nl_geee		NULL
 #endif
 
 static const struct option {
@@ -5053,7 +5054,7 @@ static const struct option {
 	  "		[ hex on|off ]\n"
 	  "		[ offset N ]\n"
 	  "		[ length N ]\n" },
-	{ "--show-eee", 1, do_geee, NULL,
+	{ "--show-eee", 1, do_geee, nl_geee,
 	  "Show EEE settings"},
 	{ "--set-eee", 1, do_seee, NULL,
 	  "Set EEE settings",
diff --git a/netlink/extapi.h b/netlink/extapi.h
index fc027f62398c..40d708a4cb85 100644
--- a/netlink/extapi.h
+++ b/netlink/extapi.h
@@ -22,6 +22,7 @@ int nl_gcoalesce(struct cmd_context *ctx);
 int nl_gring(struct cmd_context *ctx);
 int nl_gpause(struct cmd_context *ctx);
 int nl_gchannels(struct cmd_context *ctx);
+int nl_geee(struct cmd_context *ctx);
 int nl_monitor(struct cmd_context *ctx);
 
 void monitor_usage();
diff --git a/netlink/monitor.c b/netlink/monitor.c
index 1b277606a78c..799371fdebc2 100644
--- a/netlink/monitor.c
+++ b/netlink/monitor.c
@@ -158,6 +158,11 @@ static struct monitor_option monitor_opts[] = {
 		.cmd		= ETHNL_CMD_SET_PARAMS,
 		.info_mask	= ETH_PARAMS_IM_CHANNELS,
 	},
+	{
+		.pattern	= "--show-eee|--set-eee",
+		.cmd		= ETHNL_CMD_SET_PARAMS,
+		.info_mask	= ETH_PARAMS_IM_EEE,
+	},
 };
 
 static bool pattern_match(const char *s, const char *pattern)
diff --git a/netlink/params.c b/netlink/params.c
index 81547492532f..55138b6fdc83 100644
--- a/netlink/params.c
+++ b/netlink/params.c
@@ -133,6 +133,58 @@ static int show_channels(struct nl_context *nlctx, const struct nlattr *nest)
 	return 0;
 }
 
+static int show_eee(struct nl_context *nlctx, const struct nlattr *nest)
+{
+	const struct nlattr *tb[ETHA_EEE_MAX + 1] = {};
+	DECLARE_ATTR_TB_INFO(tb);
+	bool active, enabled, tx_lpi_enabled;
+	int ret;
+
+	if (!nest)
+		return -EOPNOTSUPP;
+	ret = mnl_attr_parse_nested(nest, attr_cb, &tb_info);
+	if (ret < 0)
+		return ret;
+	if (!tb[ETHA_EEE_LINK_MODES] || !tb[ETHA_EEE_PEER_MODES] ||
+	    !tb[ETHA_EEE_ACTIVE] || !tb[ETHA_EEE_ENABLED] ||
+	    !tb[ETHA_EEE_TX_LPI_ENABLED] || !tb[ETHA_EEE_TX_LPI_TIMER])
+		return -EFAULT;
+
+
+	active = mnl_attr_get_u8(tb[ETHA_EEE_ACTIVE]);
+	enabled = mnl_attr_get_u8(tb[ETHA_EEE_ENABLED]);
+	tx_lpi_enabled = mnl_attr_get_u8(tb[ETHA_EEE_TX_LPI_ENABLED]);
+
+	printf("EEE Settings for %s:\n", nlctx->devname);
+	printf("\tEEE status: ");
+	if (bitset_is_empty(tb[ETHA_EEE_LINK_MODES], true, &ret)) {
+		printf("not supported\n");
+		return 0;
+	}
+	if (!enabled)
+		printf("disabled\n");
+	else
+		printf("enabled - %s\n", active ? "active" : "inactive");
+	printf("\tTx LPI: ");
+	if (tx_lpi_enabled)
+		printf("%u (us)\n",
+		       mnl_attr_get_u32(tb[ETHA_EEE_TX_LPI_TIMER]));
+	else
+		printf("disabled\n");
+
+	ret = dump_link_modes(tb[ETHA_EEE_LINK_MODES], true, LM_CLASS_REAL,
+			      "Supported EEE link modes:  ", NULL, "\n",
+			      "Not reported");
+	ret = dump_link_modes(tb[ETHA_EEE_LINK_MODES], false, LM_CLASS_REAL,
+			      "Advertised EEE link modes:  ", NULL, "\n",
+			      "Not reported");
+	ret = dump_link_modes(tb[ETHA_EEE_PEER_MODES], false, LM_CLASS_REAL,
+			      "Link partner advertised EEE link modes:  ", NULL,
+			      "\n", "Not reported");
+
+	return 0;
+}
+
 int params_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 {
 	const struct nlattr *tb[ETHA_PARAMS_MAX + 1] = {};
@@ -183,6 +235,15 @@ int params_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 			return MNL_CB_ERROR;
 		}
 	}
+	if (mask_ok(nlctx, ETH_PARAMS_IM_EEE)) {
+		ret = show_eee(nlctx, tb[ETHA_PARAMS_EEE]);
+		if ((ret < 0) && show_only(nlctx, ETH_PARAMS_IM_EEE)) {
+			nlctx->exit_code = 1;
+			errno = -ret;
+			perror("Cannot get device EEE settings");
+			return MNL_CB_ERROR;
+		}
+	}
 
 	return MNL_CB_OK;
 }
@@ -219,3 +280,8 @@ int nl_gchannels(struct cmd_context *ctx)
 {
 	return params_request(ctx, ETH_PARAMS_IM_CHANNELS);
 }
+
+int nl_geee(struct cmd_context *ctx)
+{
+	return params_request(ctx, ETH_PARAMS_IM_EEE);
+}
-- 
2.18.0

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ