_PRINT_FUNC(tv, const struct timeval *)
#undef _PRINT_FUNC
+void print_hexstring(const char *key, const char *fmt,
+ const __u8 *data, unsigned int len);
+
#define _PRINT_NAME_VALUE_FUNC(type_name, type, format_char) \
void print_##type_name##_name_value(const char *name, type value) \
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]) {
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"
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);
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 ");
return ret;
}
+/* Print binary data as a hex string. The buffer is sized to the input,
+ * so keys of any length are printed in full rather than truncated.
+ */
+void print_hexstring(const char *key, const char *fmt,
+ const __u8 *data, unsigned int len)
+{
+ int blen = 2 * len + 1;
+ char buf[blen];
+
+ print_string(PRINT_ANY, key, fmt,
+ hexstring_n2a(data, len, buf, blen));
+}
+
/*
* value's type is bool. When using this function in FP context you can't pass
* a value to it, you will need to use "is_json_context()" to have different
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]) {
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]) {
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_);