* iproute2/tc invalid JSON in v6.0.0-42-g49c63bc7 for "tc filter"
@ 2022-11-16 17:46 Christian Pössinger
2022-11-19 18:56 ` Cong Wang
2022-12-01 15:34 ` [PATCH iproute2] tc/basic: fix json output filter Stephen Hemminger
0 siblings, 2 replies; 3+ messages in thread
From: Christian Pössinger @ 2022-11-16 17:46 UTC (permalink / raw)
To: 'netdev@vger.kernel.org'
Dear Maintainers,
using revision v6.0.0-42-g49c63bc7 I noticed an invalid JSON output when invoking tc -json filter.
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
$ tc -detail -json filter show dev eth1 ingress
[{"parent":"ffff:","protocol":"all","pref":20,"kind":"u32","chain":0},{"parent":"ffff:","protocol":"all","pref":20,"kind":"u32","chain":0,
"options":{"fh":"800:","ht_divisor":1}},{"parent":"ffff:","protocol":"all","pref":20,"kind":"u32","chain":0,"options":{"fh":"800::800",
"order":2048,"key_ht":"800","bkt":"0","flowid":"ffff:1","not_in_hw":true,"match":{"value":"16","mask":"ffff","offmask":"","off":20},
"actions":[{"order":1,"kind":"police","index":1,"control_action":{"type":"drop"},"overhead":0,"linklayer":"ethernet","ref":1,"bind":1}]}},
{"parent":"ffff:","protocol":"all","pref":255,"kind":"basic","chain":0},{"parent":"ffff:","protocol":"all","pref":255,"kind":"basic","chain":0,
"options":{handle 0x1 flowid ffff:3 "actions":[{"order":1,"kind":"police","index":2,"control_action":{"type":"drop"},"overhead":0,"linklayer":"ethernet","ref":1,"bind":1}]}}]
>>> json.loads(tmp)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 698 (char 697)
This actually contains invalid JSON here
... "options":{handle 0x1 flowid ffff:3 "actions":[{"order" ...
It should actually read:
... "options":{"handle":"0x1","flowid":"ffff:3","actions":[{"order" ...
If you can point me to the location which could be responsible for this issue, I am happy to submit a fix to the net tree.
Thanks in advance,
Christian Poessinger
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: iproute2/tc invalid JSON in v6.0.0-42-g49c63bc7 for "tc filter"
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 ` [PATCH iproute2] tc/basic: fix json output filter Stephen Hemminger
1 sibling, 0 replies; 3+ messages in thread
From: Cong Wang @ 2022-11-19 18:56 UTC (permalink / raw)
To: Christian Pössinger; +Cc: 'netdev@vger.kernel.org'
On Wed, Nov 16, 2022 at 05:46:09PM +0000, Christian Pössinger wrote:
> Dear Maintainers,
>
> using revision v6.0.0-42-g49c63bc7 I noticed an invalid JSON output when invoking tc -json filter.
>
> 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
>
>
> $ tc -detail -json filter show dev eth1 ingress
> [{"parent":"ffff:","protocol":"all","pref":20,"kind":"u32","chain":0},{"parent":"ffff:","protocol":"all","pref":20,"kind":"u32","chain":0,
> "options":{"fh":"800:","ht_divisor":1}},{"parent":"ffff:","protocol":"all","pref":20,"kind":"u32","chain":0,"options":{"fh":"800::800",
> "order":2048,"key_ht":"800","bkt":"0","flowid":"ffff:1","not_in_hw":true,"match":{"value":"16","mask":"ffff","offmask":"","off":20},
> "actions":[{"order":1,"kind":"police","index":1,"control_action":{"type":"drop"},"overhead":0,"linklayer":"ethernet","ref":1,"bind":1}]}},
> {"parent":"ffff:","protocol":"all","pref":255,"kind":"basic","chain":0},{"parent":"ffff:","protocol":"all","pref":255,"kind":"basic","chain":0,
> "options":{handle 0x1 flowid ffff:3 "actions":[{"order":1,"kind":"police","index":2,"control_action":{"type":"drop"},"overhead":0,"linklayer":"ethernet","ref":1,"bind":1}]}}]
>
>
> >>> json.loads(tmp)
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "/usr/lib/python3.9/json/__init__.py", line 346, in loads
> return _default_decoder.decode(s)
> File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
> obj, end = self.raw_decode(s, idx=_w(s, 0).end())
> File "/usr/lib/python3.9/json/decoder.py", line 353, in raw_decode
> obj, end = self.scan_once(s, idx)
> json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 698 (char 697)
>
> This actually contains invalid JSON here
>
> ... "options":{handle 0x1 flowid ffff:3 "actions":[{"order" ...
>
> It should actually read:
>
> ... "options":{"handle":"0x1","flowid":"ffff:3","actions":[{"order" ...
>
> If you can point me to the location which could be responsible for this issue, I am happy to submit a fix to the net tree.
Please take a look at tc/f_basic.c, I don't see it supports JSON as it
still uses fprintf() to print those fields. It should be converted to
print_hex() etc..
Thanks.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH iproute2] tc/basic: fix json output filter
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
1 sibling, 0 replies; 3+ messages in thread
From: Stephen Hemminger @ 2022-12-01 15:34 UTC (permalink / raw)
To: Christian Pössinger; +Cc: netdev, Stephen Hemminger
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-12-01 15:35 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [PATCH iproute2] tc/basic: fix json output filter Stephen Hemminger
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).