channels: support json output
Subsystems (2)
Jakub Kicinski
maintainerPATCH 1/1 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 <[email protected]>
--- ethtool.c | 1 + netlink/channels.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-)
ethtool.c +1 -0
@@ -6046,6 +6046,7 @@ static const struct option args[] = { }, { .opts = "-l|--show-channels", + .json = true, .func = do_gchannels, .nlfunc = nl_gchannels, .help = "Query Channels"
netlink/channels.c +13 -5
@@ -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 */
Signature · 1 line
2.49.0
This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:
Hello:
This patch was applied to ethtool/ethtool.git (master) by Michal Kubecek <[email protected]>:
Quoted 29 lines · On Tue, 29 Apr 2025 08:03:32 -0700 you wrote:
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 } ]
Quoted 1 line
[...]
Here is the summary with links:
- [ethtool-next] channels: support json output
https://git.kernel.org/pub/scm/network/ethtool/ethtool.git/commit/?id=64226907d0d6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html