From: Takanori Hirano Date: Fri, 9 Feb 2024 14:22:50 +0000 (+0000) Subject: tc: Support json option in tc-fw. X-Git-Tag: v6.8.0~16 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=49a8b895adb4c6f737ce25448a80006251b03a9e;p=thirdparty%2Fiproute2.git 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 Signed-off-by: Stephen Hemminger --- diff --git a/tc/f_fw.c b/tc/f_fw.c index 38bec492..fe99cd42 100644 --- a/tc/f_fw.c +++ b/tc/f_fw.c @@ -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;