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: <20210813171938.1127891-4-kuba@kernel.org>
Date:   Fri, 13 Aug 2021 10:19:38 -0700
From:   Jakub Kicinski <kuba@...nel.org>
To:     mkubecek@...e.cz, andrew@...n.ch
Cc:     netdev@...r.kernel.org, dcavalca@...com, filbranden@...com,
        michel@...com, Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH ethtool 3/3] ethtool: return error if command does not support --json

The --json switch is currently best effort, which is similar
to how other networking utilities treat it. Change to returning
an error if selected command does not support --json.

ethtool is more complex than other utilities because the JSON
support depends on both user space and kernel version. Older
kernel make ethtool use the IOCTL and none of the IOCTL handlers
support JSON.

The current behavior is counter-productive when trying to query
statistics - user has to check (1) if stats (-I) are supported,
(2) if json is supported (--json) and then (3) if underlying
device populates the statistic. Making --json fail if not supported
allows (1) and (2) to both be taken care of with simple check
of ethtool's exit code.

Link: https://pagure.io/centos-sig-hyperscale/package-bugs/issue/6
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
 ethtool.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/ethtool.c b/ethtool.c
index 9e02fe4f09a5..bd6242ed383e 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -5619,6 +5619,7 @@ static int show_usage(struct cmd_context *ctx);
 struct option {
 	const char	*opts;
 	bool		no_dev;
+	bool		json;
 	int		(*func)(struct cmd_context *);
 	nl_chk_t	nlchk;
 	nl_func_t	nlfunc;
@@ -5655,6 +5656,7 @@ static const struct option args[] = {
 	},
 	{
 		.opts	= "-a|--show-pause",
+		.json	= true,
 		.func	= do_gpause,
 		.nlfunc	= nl_gpause,
 		.help	= "Show pause options"
@@ -5779,6 +5781,7 @@ static const struct option args[] = {
 	},
 	{
 		.opts	= "-S|--statistics",
+		.json	= true,
 		.func	= do_gnicstats,
 		.nlchk	= nl_gstats_chk,
 		.nlfunc	= nl_gstats,
@@ -5990,6 +5993,7 @@ static const struct option args[] = {
 	},
 	{
 		.opts	= "--show-fec",
+		.json	= true,
 		.func	= do_gfec,
 		.nlfunc	= nl_gfec,
 		.help	= "Show FEC settings",
@@ -6010,11 +6014,13 @@ static const struct option args[] = {
 	},
 	{
 		.opts	= "--cable-test",
+		.json	= true,
 		.nlfunc	= nl_cable_test,
 		.help	= "Perform a cable test",
 	},
 	{
 		.opts	= "--cable-test-tdr",
+		.json	= true,
 		.nlfunc	= nl_cable_test_tdr,
 		.help	= "Print cable test time domain reflectrometery data",
 		.xhelp	= "		[ first N ]\n"
@@ -6361,10 +6367,15 @@ int main(int argc, char **argp)
 		if (!ctx.devname)
 			exit_bad_args();
 	}
+	if (ctx.json && !args[k].json)
+		exit_bad_args();
 	ctx.argc = argc;
 	ctx.argp = argp;
 	netlink_run_handler(&ctx, args[k].nlchk, args[k].nlfunc, !args[k].func);
 
+	if (ctx.json) /* no IOCTL command supports JSON output */
+		exit_bad_args();
+
 	ret = ioctl_init(&ctx, args[k].no_dev);
 	if (ret)
 		return ret;
-- 
2.31.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ