[PATCH iproute2 2/3] ip, tc: print hex attributes with print_hexstring
From: Stephen Hemminger <stephen@networkplumber.org>
Date: 2026-07-23 19:15:20
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
Convert the callers that dump a binary attribute straight to output over to print_hexstring(). This drops the per-site scratch buffer and, for phys_port_id and phys_switch_id, fixes truncation of keys wider than 31 bytes: a 32-byte netdevsim switch id previously printed only 62 of its 64 hex characters because it did not fit SPRINT_BUF. No change to output for keys that already fit. Signed-off-by: Stephen Hemminger <stephen@networkplumber.org> --- ip/ipaddress.c | 19 ++++++------------- ip/ipmacsec.c | 7 ++----- lib/bpf_legacy.c | 6 ++---- tc/f_bpf.c | 8 +++----- tc/m_action.c | 9 +++------ tc/m_bpf.c | 9 +++------ 6 files changed, 19 insertions(+), 39 deletions(-)
diff --git a/ip/ipaddress.c b/ip/ipaddress.c
index 6017bc83..7e4cb77c 100644
--- a/ip/ipaddress.c
+++ b/ip/ipaddress.c@@ -1263,22 +1263,15 @@ int print_linkinfo(struct nlmsghdr *n, void *arg) rta_getattr_str(tb[IFLA_PHYS_PORT_NAME])); if (tb[IFLA_PHYS_PORT_ID]) { - print_string(PRINT_ANY, - "phys_port_id", - "portid %s ", - hexstring_n2a( - RTA_DATA(tb[IFLA_PHYS_PORT_ID]), - RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID]), - b1, sizeof(b1))); + print_hexstring("phys_port_id", "portid %s ", + RTA_DATA(tb[IFLA_PHYS_PORT_ID]), + RTA_PAYLOAD(tb[IFLA_PHYS_PORT_ID])); } if (tb[IFLA_PHYS_SWITCH_ID]) { - print_string(PRINT_ANY, - "phys_switch_id", - "switchid %s ", - hexstring_n2a(RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]), - RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID]), - b1, sizeof(b1))); + print_hexstring("phys_switch_id", "switchid %s ", + RTA_DATA(tb[IFLA_PHYS_SWITCH_ID]), + RTA_PAYLOAD(tb[IFLA_PHYS_SWITCH_ID])); } if (tb[IFLA_PARENT_DEV_BUS_NAME]) {
diff --git a/ip/ipmacsec.c b/ip/ipmacsec.c
index fc4c8631..1864ffd3 100644
--- a/ip/ipmacsec.c
+++ b/ip/ipmacsec.c@@ -661,11 +661,8 @@ static void print_flag(struct rtattr *attrs[], const char *desc, static void print_key(struct rtattr *key) { - SPRINT_BUF(keyid); - - print_string(PRINT_ANY, "key", " key %s\n", - hexstring_n2a(RTA_DATA(key), RTA_PAYLOAD(key), - keyid, sizeof(keyid))); + print_hexstring("key", " key %s\n", + RTA_DATA(key), RTA_PAYLOAD(key)); } #define CIPHER_NAME_GCM_AES_128 "GCM-AES-128"
diff --git a/lib/bpf_legacy.c b/lib/bpf_legacy.c
index 50ca82c1..9d5fcf5f 100644
--- a/lib/bpf_legacy.c
+++ b/lib/bpf_legacy.c@@ -176,7 +176,6 @@ int bpf_dump_prog_info(FILE *f, uint32_t id) struct bpf_prog_info info = {}; uint32_t len = sizeof(info); int fd, ret, dump_ok = 0; - SPRINT_BUF(tmp); open_json_object("prog"); print_uint(PRINT_ANY, "id", "id %u ", id);
@@ -190,9 +189,8 @@ int bpf_dump_prog_info(FILE *f, uint32_t id) int jited = !!info.jited_prog_len; print_string(PRINT_ANY, "name", "name %s ", info.name); - print_string(PRINT_ANY, "tag", "tag %s ", - hexstring_n2a(info.tag, sizeof(info.tag), - tmp, sizeof(tmp))); + print_hexstring("tag", "tag %s ", + info.tag, sizeof(info.tag)); print_uint(PRINT_JSON, "jited", NULL, jited); if (jited && !is_json_context()) fprintf(f, "jited ");
diff --git a/tc/f_bpf.c b/tc/f_bpf.c
index 6dd75445..50fe01ca 100644
--- a/tc/f_bpf.c
+++ b/tc/f_bpf.c@@ -241,11 +241,9 @@ static int bpf_print_opt(const struct filter_util *qu, FILE *f, if (tb[TCA_BPF_ID]) dump_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_BPF_ID])); if (!dump_ok && tb[TCA_BPF_TAG]) { - SPRINT_BUF(b); - - print_string(PRINT_ANY, "tag", "tag %s ", - hexstring_n2a(RTA_DATA(tb[TCA_BPF_TAG]), - RTA_PAYLOAD(tb[TCA_BPF_TAG]), b, sizeof(b))); + print_hexstring("tag", "tag %s ", + RTA_DATA(tb[TCA_BPF_TAG]), + RTA_PAYLOAD(tb[TCA_BPF_TAG])); } if (tb[TCA_BPF_POLICE]) {
diff --git a/tc/m_action.c b/tc/m_action.c
index 6f79fdae..bbc8e6a6 100644
--- a/tc/m_action.c
+++ b/tc/m_action.c@@ -401,12 +401,9 @@ static int tc_print_one_action(FILE *f, struct rtattr *arg, bool bind) print_nl(); } if (tb[TCA_ACT_COOKIE]) { - int strsz = RTA_PAYLOAD(tb[TCA_ACT_COOKIE]); - char b1[strsz * 2 + 1]; - - print_string(PRINT_ANY, "cookie", "\tcookie %s", - hexstring_n2a(RTA_DATA(tb[TCA_ACT_COOKIE]), - strsz, b1, sizeof(b1))); + print_hexstring("cookie", "\tcookie %s", + RTA_DATA(tb[TCA_ACT_COOKIE]), + RTA_PAYLOAD(tb[TCA_ACT_COOKIE])); print_nl(); } if (tb[TCA_ACT_FLAGS] || tb[TCA_ACT_IN_HW_COUNT]) {
diff --git a/tc/m_bpf.c b/tc/m_bpf.c
index a5de7da1..83b21b57 100644
--- a/tc/m_bpf.c
+++ b/tc/m_bpf.c@@ -183,12 +183,9 @@ static int bpf_print_opt(const struct action_util *au, FILE *f, struct rtattr *a d_ok = bpf_dump_prog_info(f, rta_getattr_u32(tb[TCA_ACT_BPF_ID])); if (!d_ok && tb[TCA_ACT_BPF_TAG]) { - SPRINT_BUF(b); - - print_string(PRINT_ANY, "tag", "tag %s ", - hexstring_n2a(RTA_DATA(tb[TCA_ACT_BPF_TAG]), - RTA_PAYLOAD(tb[TCA_ACT_BPF_TAG]), - b, sizeof(b))); + print_hexstring("tag", "tag %s ", + RTA_DATA(tb[TCA_ACT_BPF_TAG]), + RTA_PAYLOAD(tb[TCA_ACT_BPF_TAG])); } print_action_control("default-action ", parm->action, _SL_);
--
2.53.0