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-next>] [day] [month] [year] [list]
Message-ID: <20250429150332.2592930-1-kuba@kernel.org>
Date: Tue, 29 Apr 2025 08:03:32 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: mkubecek@...e.cz
Cc: netdev@...r.kernel.org,
	Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH ethtool-next] channels: support json output

Make -l | --show-channels support JSON output format.

  # ./ethtool -j -l '*' | jq
  [
    {
      "ifname": "eth0",
      "rx-max": 32,
      "tx-max": 32,
      "combined-max": 32,
      "rx": 0,
      "tx": 0,
      "combined": 20
    },
    {
      "ifname": "veth0",
      "rx-max": 80,
      "tx-max": 80,
      "rx": 1,
      "tx": 1
    },
    {
      "ifname": "veth1",
      "rx-max": 80,
      "tx-max": 80,
      "rx": 1,
      "tx": 1
    }
  ]

Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
 ethtool.c          |  1 +
 netlink/channels.c | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/ethtool.c b/ethtool.c
index 9c8a5428affd..1485b0253253 100644
--- a/ethtool.c
+++ b/ethtool.c
@@ -6046,6 +6046,7 @@ static const struct option args[] = {
 	},
 	{
 		.opts	= "-l|--show-channels",
+		.json	= true,
 		.func	= do_gchannels,
 		.nlfunc	= nl_gchannels,
 		.help	= "Query Channels"
diff --git a/netlink/channels.c b/netlink/channels.c
index 5cae227106d6..b8213d7e3172 100644
--- a/netlink/channels.c
+++ b/netlink/channels.c
@@ -33,22 +33,27 @@ int channels_reply_cb(const struct nlmsghdr *nlhdr, void *data)
 	if (!dev_ok(nlctx))
 		return err_ret;
 
+	open_json_object(NULL);
+
 	if (silent)
-		putchar('\n');
-	printf("Channel parameters for %s:\n", nlctx->devname);
-	printf("Pre-set maximums:\n");
+		show_cr();
+	print_string(PRINT_ANY, "ifname", "Channel parameters for %s:\n",
+		     nlctx->devname);
+	print_string(PRINT_FP, NULL, "Pre-set maximums:\n", NULL);
 	show_u32("rx-max", "RX:\t\t", tb[ETHTOOL_A_CHANNELS_RX_MAX]);
 	show_u32("tx-max", "TX:\t\t", tb[ETHTOOL_A_CHANNELS_TX_MAX]);
 	show_u32("other-max", "Other:\t\t", tb[ETHTOOL_A_CHANNELS_OTHER_MAX]);
 	show_u32("combined-max", "Combined:\t",
 		 tb[ETHTOOL_A_CHANNELS_COMBINED_MAX]);
-	printf("Current hardware settings:\n");
+	print_string(PRINT_FP, NULL, "Current hardware settings:\n", NULL);
 	show_u32("rx", "RX:\t\t", tb[ETHTOOL_A_CHANNELS_RX_COUNT]);
 	show_u32("tx", "TX:\t\t", tb[ETHTOOL_A_CHANNELS_TX_COUNT]);
 	show_u32("other", "Other:\t\t", tb[ETHTOOL_A_CHANNELS_OTHER_COUNT]);
 	show_u32("combined", "Combined:\t",
 		 tb[ETHTOOL_A_CHANNELS_COMBINED_COUNT]);
 
+	close_json_object();
+
 	return MNL_CB_OK;
 }
 
@@ -70,7 +75,10 @@ int nl_gchannels(struct cmd_context *ctx)
 				      ETHTOOL_A_CHANNELS_HEADER, 0);
 	if (ret < 0)
 		return ret;
-	return nlsock_send_get_request(nlsk, channels_reply_cb);
+	new_json_obj(ctx->json);
+	ret = nlsock_send_get_request(nlsk, channels_reply_cb);
+	delete_json_obj();
+	return ret;
 }
 
 /* CHANNELS_SET */
-- 
2.49.0


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ