[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <0106018d8e3feccb-51048e17-d81c-4a1b-97cb-bc3809ad3eca-000000@ap-northeast-1.amazonses.com>
Date: Fri, 9 Feb 2024 14:22:50 +0000
From: Takanori Hirano <me@...tknr.net>
To: netdev@...r.kernel.org
Cc: stephen@...workplumber.org, Takanori Hirano <me@...tknr.net>
Subject: [PATCH iproute2] 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@...tknr.net>
---
tc/f_fw.c | 22 +++++++++++++++-------
1 file changed, 15 insertions(+), 7 deletions(-)
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;
--
2.34.1
Powered by blists - more mailing lists