]> git.ipfire.org Git - thirdparty/iproute2.git/commitdiff
tc: Support json option in tc-fw.
authorTakanori Hirano <me@hrntknr.net>
Fri, 9 Feb 2024 14:22:50 +0000 (14:22 +0000)
committerStephen Hemminger <stephen@networkplumber.org>
Sat, 10 Feb 2024 17:48:55 +0000 (09:48 -0800)
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>
tc/f_fw.c

index 38bec492b49a7b688a5cf0e1c7b2a9bba5c9b046..fe99cd42eb6cceb91c29966b66bf29325b629fbe 100644 (file)
--- 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;