diff options
author | Takanori Hirano <me@hrntknr.net> | 2024-02-09 14:22:50 +0000 |
---|---|---|
committer | Stephen Hemminger <stephen@networkplumber.org> | 2024-02-10 09:48:55 -0800 |
commit | 49a8b895adb4c6f737ce25448a80006251b03a9e (patch) | |
tree | 6c9180511aa75bb79d4a005441dba565fec27f36 | |
parent | e449400508eff4cb4ac69e3a798a18e7aaa34c1b (diff) | |
download | iproute2-49a8b895adb4c6f737ce25448a80006251b03a9e.tar.gz |
tc: Support json option in tc-fw.
Fix json corruption when using the "-json" option in cases where tc-fw is set.
Signed-off-by: Takanori Hirano <me@hrntknr.net>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
-rw-r--r-- | tc/f_fw.c | 22 |
1 files changed, 15 insertions, 7 deletions
@@ -124,18 +124,25 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (handle || tb[TCA_FW_MASK]) { __u32 mark = 0, mask = 0; + open_json_object("handle"); if (handle) mark = handle; if (tb[TCA_FW_MASK] && - (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) - fprintf(f, "handle 0x%x/0x%x ", mark, mask); - else - fprintf(f, "handle 0x%x ", handle); + (mask = rta_getattr_u32(tb[TCA_FW_MASK])) != 0xFFFFFFFF) { + print_hex(PRINT_ANY, "mark", "handle 0x%x", mark); + print_hex(PRINT_ANY, "mask", "/0x%x ", mask); + } else { + print_hex(PRINT_ANY, "mark", "handle 0x%x ", mark); + print_hex(PRINT_JSON, "mask", NULL, 0xFFFFFFFF); + } + close_json_object(); } if (tb[TCA_FW_CLASSID]) { SPRINT_BUF(b1); - fprintf(f, "classid %s ", sprint_tc_classid(rta_getattr_u32(tb[TCA_FW_CLASSID]), b1)); + print_string(PRINT_ANY, "classid", "classid %s ", + sprint_tc_classid( + rta_getattr_u32(tb[TCA_FW_CLASSID]), b1)); } if (tb[TCA_FW_POLICE]) @@ -143,11 +150,12 @@ static int fw_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt, __u if (tb[TCA_FW_INDEV]) { struct rtattr *idev = tb[TCA_FW_INDEV]; - fprintf(f, "input dev %s ", rta_getattr_str(idev)); + print_string(PRINT_ANY, "indev", "input dev %s ", + rta_getattr_str(idev)); } if (tb[TCA_FW_ACT]) { - fprintf(f, "\n"); + print_string(PRINT_FP, NULL, "\n", ""); tc_print_action(f, tb[TCA_FW_ACT], 0); } return 0; |