netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jakub Kicinski <kuba@kernel.org>
To: mkubecek@suse.cz
Cc: netdev@vger.kernel.org, Jakub Kicinski <kuba@kernel.org>
Subject: [PATCH ethtool-next] channels: support json output
Date: Tue, 29 Apr 2025 08:03:32 -0700	[thread overview]
Message-ID: <20250429150332.2592930-1-kuba@kernel.org> (raw)

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@kernel.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


             reply	other threads:[~2025-04-29 15:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-29 15:03 Jakub Kicinski [this message]
2025-04-29 20:30 ` [PATCH ethtool-next] channels: support json output patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250429150332.2592930-1-kuba@kernel.org \
    --to=kuba@kernel.org \
    --cc=mkubecek@suse.cz \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).