netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH iproute2] tc: Support json option in tc-fw.
@ 2024-02-09 14:22 Takanori Hirano
  2024-02-09 16:37 ` Stephen Hemminger
  2024-02-10 17:50 ` [PATCH iproute2] tc: Support json option in tc-fw patchwork-bot+netdevbpf
  0 siblings, 2 replies; 17+ messages in thread
From: Takanori Hirano @ 2024-02-09 14:22 UTC (permalink / raw)
  To: netdev; +Cc: stephen, Takanori Hirano

Fix json corruption when using the "-json" option in cases where tc-fw is set.

Signed-off-by: Takanori Hirano <me@hrntknr.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


^ permalink raw reply related	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2024-02-19 18:20 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-09 14:22 [PATCH iproute2] tc: Support json option in tc-fw Takanori Hirano
2024-02-09 16:37 ` Stephen Hemminger
2024-02-10 10:02   ` Takanori Hirano
2024-02-10 10:08   ` [PATCH iproute2 v2] tc: Add support json option in filter Takanori Hirano
2024-02-10 17:18     ` Stephen Hemminger
2024-02-10 17:21     ` Stephen Hemminger
2024-02-11  0:56       ` Takanori Hirano
2024-02-11  0:59       ` [PATCH] tc: Support json option in tc-cgroup, tc-flow and tc-route Takanori Hirano
2024-02-13  4:16         ` Stephen Hemminger
2024-02-13 10:01           ` [PATCH v2] " Takanori Hirano
2024-02-19 18:20             ` patchwork-bot+netdevbpf
2024-02-11  1:27       ` [PATCH] tc: Change of json key: options.handle -> options.fw in tc-fw Takanori Hirano
2024-02-11  1:38       ` [PATCH v2] tc: Change of json format " Takanori Hirano
2024-02-19 18:20         ` patchwork-bot+netdevbpf
2024-02-11  1:00     ` [PATCH iproute2 v2] tc: Add support json option in filter Stephen Hemminger
2024-02-11  1:08       ` Takanori Hirano
2024-02-10 17:50 ` [PATCH iproute2] tc: Support json option in tc-fw patchwork-bot+netdevbpf

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).