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 PHC | |
Open Source and information security mailing list archives
| ||
|
Date: Fri, 9 Dec 2022 19:16:10 -0700 From: Max Georgiev <glipus@...il.com> To: Michal Kubecek <mkubecek@...e.cz> Cc: netdev@...r.kernel.org, Jakub Kicinski <kuba@...nel.org> Subject: [PATCH ethtool] JSON output support for Netlink implementation of --show-coalesce option JSON output support for Netlink implementation of --show-coalesce option Add --json support for Netlink implementation of --show-coalesce option No changes for non-JSON output for this feature. Example output without --json: $ sudo ./ethtool --show-coalesce enp9s0u2u1u2 Coalesce parameters for enp9s0u2u1u2: Adaptive RX: n/a TX: n/a stats-block-usecs: n/a sample-interval: n/a pkt-rate-low: n/a pkt-rate-high: n/a rx-usecs: 15000 rx-frames: n/a rx-usecs-irq: n/a rx-frames-irq: n/a tx-usecs: 0 tx-frames: n/a tx-usecs-irq: n/a tx-frames-irq: n/a rx-usecs-low: n/a rx-frame-low: n/a tx-usecs-low: n/a tx-frame-low: n/a rx-usecs-high: n/a rx-frame-high: n/a tx-usecs-high: n/a tx-frame-high: n/a CQE mode RX: n/a TX: n/a Same output with --json: $ sudo ./ethtool --json --show-coalesce enp9s0u2u1u2 [ { "ifname": "enp9s0u2u1u2", "rx-usecs: ": 15000, "tx-usecs: ": 0 } ] Suggested-by: Jakub Kicinski <kuba@...nel.org> Signed-off-by: Maxim Georgiev <glipus@...il.com> --- ethtool.c | 1 + netlink/coalesce.c | 27 ++++++++++++++++++--------- netlink/netlink.h | 19 +++++++++++++++---- 3 files changed, 34 insertions(+), 13 deletions(-) diff --git a/ethtool.c b/ethtool.c index 3207e49..3b8412c 100644 --- a/ethtool.c +++ b/ethtool.c @@ -5694,6 +5694,7 @@ static const struct option args[] = { }, { .opts = "-c|--show-coalesce", + .json = true, .func = do_gcoalesce, .nlfunc = nl_gcoalesce, .help = "Show coalesce options" diff --git a/netlink/coalesce.c b/netlink/coalesce.c index 15037c2..f003a5c 100644 --- a/netlink/coalesce.c +++ b/netlink/coalesce.c @@ -33,9 +33,12 @@ int coalesce_reply_cb(const struct nlmsghdr *nlhdr, void *data) if (!dev_ok(nlctx)) return err_ret; - if (silent) + open_json_object(NULL); + + if (silent && !is_json_context()) putchar('\n'); - printf("Coalesce parameters for %s:\n", nlctx->devname); + print_string(PRINT_ANY, "ifname", "Coalesce parameters for %s:\n", + nlctx->devname); show_bool("rx", "Adaptive RX: %s ", tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_RX]); show_bool("tx", "TX: %s\n", tb[ETHTOOL_A_COALESCE_USE_ADAPTIVE_TX]); @@ -45,31 +48,33 @@ int coalesce_reply_cb(const struct nlmsghdr *nlhdr, void *data) "sample-interval: "); show_u32(tb[ETHTOOL_A_COALESCE_PKT_RATE_LOW], "pkt-rate-low: "); show_u32(tb[ETHTOOL_A_COALESCE_PKT_RATE_HIGH], "pkt-rate-high: "); - putchar('\n'); + show_cr(); show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS], "rx-usecs: "); show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES], "rx-frames: "); show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS_IRQ], "rx-usecs-irq: "); show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_IRQ], "rx-frames-irq: "); - putchar('\n'); + show_cr(); show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS], "tx-usecs: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES], "tx-frames: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS_IRQ], "tx-usecs-irq: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_IRQ], "tx-frames-irq: "); - putchar('\n'); + show_cr(); show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS_LOW], "rx-usecs-low: "); show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_LOW], "rx-frame-low: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS_LOW], "tx-usecs-low: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_LOW], "tx-frame-low: "); - putchar('\n'); + show_cr(); show_u32(tb[ETHTOOL_A_COALESCE_RX_USECS_HIGH], "rx-usecs-high: "); show_u32(tb[ETHTOOL_A_COALESCE_RX_MAX_FRAMES_HIGH], "rx-frame-high: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_USECS_HIGH], "tx-usecs-high: "); show_u32(tb[ETHTOOL_A_COALESCE_TX_MAX_FRAMES_HIGH], "tx-frame-high: "); - putchar('\n'); + show_cr(); show_bool("rx", "CQE mode RX: %s ", tb[ETHTOOL_A_COALESCE_USE_CQE_MODE_RX]); show_bool("tx", "TX: %s\n", tb[ETHTOOL_A_COALESCE_USE_CQE_MODE_TX]); - putchar('\n'); + show_cr(); + + close_json_object(); return MNL_CB_OK; } @@ -92,7 +97,11 @@ int nl_gcoalesce(struct cmd_context *ctx) ETHTOOL_A_COALESCE_HEADER, 0); if (ret < 0) return ret; - return nlsock_send_get_request(nlsk, coalesce_reply_cb); + + new_json_obj(ctx->json); + ret = nlsock_send_get_request(nlsk, coalesce_reply_cb); + delete_json_obj(); + return ret; } /* COALESCE_SET */ diff --git a/netlink/netlink.h b/netlink/netlink.h index f43c1bf..3af104b 100644 --- a/netlink/netlink.h +++ b/netlink/netlink.h @@ -102,10 +102,15 @@ int dump_link_modes(struct nl_context *nlctx, const struct nlattr *bitset, static inline void show_u32(const struct nlattr *attr, const char *label) { - if (attr) - printf("%s%u\n", label, mnl_attr_get_u32(attr)); - else - printf("%sn/a\n", label); + if (is_json_context()) { + if (attr) + print_uint(PRINT_JSON, label, NULL, mnl_attr_get_u32(attr)); + } else { + if (attr) + printf("%s%u\n", label, mnl_attr_get_u32(attr)); + else + printf("%sn/a\n", label); + } } static inline const char *u8_to_bool(const uint8_t *val) @@ -132,6 +137,12 @@ static inline void show_bool(const char *key, const char *fmt, show_bool_val(key, fmt, attr ? mnl_attr_get_payload(attr) : NULL); } +static inline void show_cr(void) +{ + if (!is_json_context()) + putchar('\n'); +} + /* misc */ static inline void copy_devname(char *dst, const char *src) -- 2.38.1
Powered by blists - more mailing lists