diff mbox series

[iproute2,3/5] skbmod: support json in print

Message ID 20240312225456.87937-4-stephen@networkplumber.org (mailing list archive)
State Accepted
Commit af0ddbfa51f92fcf53c56b5ab82093cf8eb13f6b
Delegated to: Stephen Hemminger
Headers show
Series tc: more JSON fixes | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger March 12, 2024, 10:53 p.m. UTC
This tc action never got jsonized.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 tc/m_skbmod.c | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
diff mbox series

Patch

diff --git a/tc/m_skbmod.c b/tc/m_skbmod.c
index b1c8d00dfe47..87de59cf60bb 100644
--- a/tc/m_skbmod.c
+++ b/tc/m_skbmod.c
@@ -177,43 +177,48 @@  static int print_skbmod(struct action_util *au, FILE *f, struct rtattr *arg)
 
 	p = RTA_DATA(tb[TCA_SKBMOD_PARMS]);
 
-	fprintf(f, "skbmod ");
+	print_string(PRINT_FP, NULL, "skbmod ", NULL);
 	print_action_control(f, "", p->action, " ");
 
 	if (tb[TCA_SKBMOD_ETYPE]) {
 		skbmod_etype = rta_getattr_u16(tb[TCA_SKBMOD_ETYPE]);
 		has_optional = 1;
-		fprintf(f, "set etype 0x%X ", skbmod_etype);
+		print_0xhex(PRINT_ANY, "etype", "set etype 0x%X ", skbmod_etype);
 	}
 
 	if (has_optional)
-		fprintf(f, "\n\t ");
+		print_string(PRINT_FP, NULL, "%s\t ", _SL_);
 
 	if (tb[TCA_SKBMOD_DMAC]) {
 		has_optional = 1;
-		fprintf(f, "set dmac %s ",
-			ll_addr_n2a(RTA_DATA(tb[TCA_SKBMOD_DMAC]),
-				    RTA_PAYLOAD(tb[TCA_SKBMOD_DMAC]), 0, b1,
-				    sizeof(b1)));
+		print_color_string(PRINT_ANY, COLOR_MAC, "dmac",
+				   "set dmac %s ",
+				   ll_addr_n2a(RTA_DATA(tb[TCA_SKBMOD_DMAC]),
+					       RTA_PAYLOAD(tb[TCA_SKBMOD_DMAC]), 0, b1,
+					       sizeof(b1)));
 
 	}
 
 	if (tb[TCA_SKBMOD_SMAC]) {
 		has_optional = 1;
-		fprintf(f, "set smac %s ",
-			ll_addr_n2a(RTA_DATA(tb[TCA_SKBMOD_SMAC]),
-				    RTA_PAYLOAD(tb[TCA_SKBMOD_SMAC]), 0, b2,
-				    sizeof(b2)));
+		print_color_string(PRINT_ANY, COLOR_MAC, "smac",
+				   "set smac %s ",
+				   ll_addr_n2a(RTA_DATA(tb[TCA_SKBMOD_SMAC]),
+					       RTA_PAYLOAD(tb[TCA_SKBMOD_SMAC]), 0, b2,
+					       sizeof(b2)));
 	}
 
 	if (p->flags & SKBMOD_F_SWAPMAC)
-		fprintf(f, "swap mac ");
+		print_null(PRINT_ANY, "swapmac", "swap mac ", NULL);
 
 	if (p->flags & SKBMOD_F_ECN)
-		fprintf(f, "ecn ");
+		print_null(PRINT_ANY, "ecn", "ecn ", NULL);
+
+	print_nl();
+	print_uint(PRINT_ANY, "index", "\t index %u ", p->index);
+	print_int(PRINT_ANY, "ref", "ref %d ", p->refcnt);
+	print_int(PRINT_ANY, "bind", "bind %d", p->bindcnt);
 
-	fprintf(f, "\n\t index %u ref %d bind %d", p->index, p->refcnt,
-		p->bindcnt);
 	if (show_stats) {
 		if (tb[TCA_SKBMOD_TM]) {
 			struct tcf_t *tm = RTA_DATA(tb[TCA_SKBMOD_TM]);
@@ -222,7 +227,7 @@  static int print_skbmod(struct action_util *au, FILE *f, struct rtattr *arg)
 		}
 	}
 
-	fprintf(f, "\n");
+	print_string(PRINT_FP, NULL, "\n", NULL);
 
 	return 0;
 }