public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Stephen Hemminger <stephen@networkplumber.org>
To: "Christian Pössinger" <christian@poessinger.com>
Cc: netdev@vger.kernel.org, Stephen Hemminger <stephen@networkplumber.org>
Subject: [PATCH iproute2] tc/basic: fix json output filter
Date: Thu,  1 Dec 2022 07:34:50 -0800	[thread overview]
Message-ID: <20221201153450.30481-1-stephen@networkplumber.org> (raw)
In-Reply-To: <e1fa5169db254301bc3b5b766c2df76a@poessinger.com>

The flowid and handle in basic were not using JSON routines to print.
 To reproduce the issue:

 $ tc qdisc add dev eth1 handle ffff: ingress
 $ tc filter add dev eth1 parent ffff: prio 20 protocol all u32 match ip dport 22 \
     0xffff action police conform-exceed drop/ok rate 100000 burst 15k flowid ffff:1

 $ tc filter add dev eth1 parent ffff: prio 255 protocol all basic action police \
     conform-exceed drop/ok rate 100000 burst 15k flowid ffff:3

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

diff --git a/tc/f_basic.c b/tc/f_basic.c
index 9a60758e803e..9055370e90b9 100644
--- a/tc/f_basic.c
+++ b/tc/f_basic.c
@@ -119,19 +119,22 @@ static int basic_print_opt(struct filter_util *qu, FILE *f,
 	parse_rtattr_nested(tb, TCA_BASIC_MAX, opt);
 
 	if (handle)
-		fprintf(f, "handle 0x%x ", handle);
+		print_hex(PRINT_ANY, "handle",
+			  "handle 0x%x ", handle);
 
 	if (tb[TCA_BASIC_CLASSID]) {
+		uint32_t classid = rta_getattr_u32(tb[TCA_BASIC_CLASSID]);
 		SPRINT_BUF(b1);
-		fprintf(f, "flowid %s ",
-			sprint_tc_classid(rta_getattr_u32(tb[TCA_BASIC_CLASSID]), b1));
+
+		print_string(PRINT_ANY, "flowid", "flowid %s ",
+			     sprint_tc_classid(classid, b1));
 	}
 
 	if (tb[TCA_BASIC_EMATCHES])
 		print_ematch(f, tb[TCA_BASIC_EMATCHES]);
 
 	if (tb[TCA_BASIC_POLICE]) {
-		fprintf(f, "\n");
+		print_nl();
 		tc_print_police(f, tb[TCA_BASIC_POLICE]);
 	}
 
-- 
2.35.1


      parent reply	other threads:[~2022-12-01 15:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 17:46 iproute2/tc invalid JSON in v6.0.0-42-g49c63bc7 for "tc filter" Christian Pössinger
2022-11-19 18:56 ` Cong Wang
2022-12-01 15:34 ` Stephen Hemminger [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20221201153450.30481-1-stephen@networkplumber.org \
    --to=stephen@networkplumber.org \
    --cc=christian@poessinger.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox