diff mbox series

[iproute2] u32: fix json formatting of flowid

Message ID 20221013153240.108340-1-stephen@networkplumber.org (mailing list archive)
State Accepted
Delegated to: Stephen Hemminger
Headers show
Series [iproute2] u32: fix json formatting of flowid | expand

Checks

Context Check Description
netdev/tree_selection success Not a local patch

Commit Message

Stephen Hemminger Oct. 13, 2022, 3:32 p.m. UTC
The code to print json was not done for the flow id.
This would lead to incorrect JSON format output.

Reported-by: Christian Pössinger <christian@poessinger.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 tc/f_u32.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

Comments

Christian Pössinger Oct. 13, 2022, 5:22 p.m. UTC | #1
Hi Stephen,

I can confirm this fix working!

You may include 
Tested-by: Christian Pössinger <christian@poessinger.com>

Thanks,
Christian

-----Original Message-----
From: Stephen Hemminger <stephen@networkplumber.org> 
Sent: Thursday, 13 October 2022 17:33
To: netdev@vger.kernel.org
Cc: Stephen Hemminger <stephen@networkplumber.org>; Christian Pössinger <christian@poessinger.com>
Subject: [PATCH iproute2] u32: fix json formatting of flowid

The code to print json was not done for the flow id.
This would lead to incorrect JSON format output.

Reported-by: Christian Pössinger <christian@poessinger.com>
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 tc/f_u32.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/tc/f_u32.c b/tc/f_u32.c
index d787eb915603..e4e0ab121c57 100644
--- a/tc/f_u32.c
+++ b/tc/f_u32.c
@@ -1275,12 +1275,14 @@ static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
 		fprintf(stderr, "divisor and hash missing ");
 	}
 	if (tb[TCA_U32_CLASSID]) {
+		__u32 classid = rta_getattr_u32(tb[TCA_U32_CLASSID]);
 		SPRINT_BUF(b1);
-		fprintf(f, "%sflowid %s ",
-			!sel || !(sel->flags & TC_U32_TERMINAL) ? "*" : "",
-			sprint_tc_classid(rta_getattr_u32(tb[TCA_U32_CLASSID]),
-					  b1));
-	} else if (sel && sel->flags & TC_U32_TERMINAL) {
+		if (sel && (sel->flags & TC_U32_TERMINAL))
+			print_string(PRINT_FP, NULL, "*", NULL);
+
+		print_string(PRINT_ANY, "flowid", "flowid %s ",
+			     sprint_tc_classid(classid, b1));
+	} else if (sel && (sel->flags & TC_U32_TERMINAL)) {
 		print_string(PRINT_FP, NULL, "terminal flowid ", NULL);
 	}
 	if (tb[TCA_U32_LINK]) {
diff mbox series

Patch

diff --git a/tc/f_u32.c b/tc/f_u32.c
index d787eb915603..e4e0ab121c57 100644
--- a/tc/f_u32.c
+++ b/tc/f_u32.c
@@ -1275,12 +1275,14 @@  static int u32_print_opt(struct filter_util *qu, FILE *f, struct rtattr *opt,
 		fprintf(stderr, "divisor and hash missing ");
 	}
 	if (tb[TCA_U32_CLASSID]) {
+		__u32 classid = rta_getattr_u32(tb[TCA_U32_CLASSID]);
 		SPRINT_BUF(b1);
-		fprintf(f, "%sflowid %s ",
-			!sel || !(sel->flags & TC_U32_TERMINAL) ? "*" : "",
-			sprint_tc_classid(rta_getattr_u32(tb[TCA_U32_CLASSID]),
-					  b1));
-	} else if (sel && sel->flags & TC_U32_TERMINAL) {
+		if (sel && (sel->flags & TC_U32_TERMINAL))
+			print_string(PRINT_FP, NULL, "*", NULL);
+
+		print_string(PRINT_ANY, "flowid", "flowid %s ",
+			     sprint_tc_classid(classid, b1));
+	} else if (sel && (sel->flags & TC_U32_TERMINAL)) {
 		print_string(PRINT_FP, NULL, "terminal flowid ", NULL);
 	}
 	if (tb[TCA_U32_LINK]) {