tc: more JSON fixes
Subsystems (2)
cover tc: more JSON fixes
Some more places in TC where JSON output is missing or could be corrupted. And some things found while reviewing tc-simple man page.
Stephen Hemminger (5):
tc: support JSON for legacy stats
pedit: log errors to stderr
skbmod: support json in print
simple: support json output
tc-simple.8: take Jamal's prompt off examples
man/man8/tc-simple.8 | 12 ++++++------ tc/m_pedit.c | 6 +++--- tc/m_simple.c | 8 +++++--- tc/m_skbmod.c | 37 +++++++++++++++++++++---------------- tc/tc_util.c | 28 +++++++++++++++------------- 5 files changed, 50 insertions(+), 41 deletions(-)
Signature · 1 line
2.43.0
PATCH 1/5 tc: support JSON for legacy stats
The extended stats already supported JSON output, add to the legacy stats as well.
--- tc/tc_util.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-)
tc/tc_util.c +15 -13
@@ -804,28 +804,30 @@ void print_tcstats_attr(FILE *fp, struct rtattr *tb[], const char *prefix,memcpy (&st,RTA_DATA (tb[TCA_STATS ]),MIN (RTA_PAYLOAD (tb[TCA_STATS ]),sizeof (st))); -fprintf (fp, -"%sSent %llu bytes %u pkts (dropped %u, overlimits %u) " , - prefix, (unsigned long long )st.bytes, - st.packets, st.drops, st.overlimits); +print_string (PRINT_FP ,NULL ,"%s" , prefix); +print_lluint (PRINT_ANY ,"bytes" ,"Sent %llu bytes" , + (unsigned long long )st.bytes); +print_uint (PRINT_ANY ,"packets" ," %u pkts" , st.packets); +print_uint (PRINT_ANY ,"dropped" ," (dropped %u," , st.drops); +print_uint (PRINT_ANY ,"overlimits" ," overlimits %u) " , st.overlimits);if (st.bps || st.pps || st.qlen || st.backlog) { -fprintf (fp,"\n%s" , prefix); +print_nl (); +print_string (PRINT_FP ,NULL ,"%s" , prefix); +if (st.bps || st.pps) { -fprintf (fp,"rate " ); +print_string (PRINT_FP ,NULL ,"rate " ,NULL );if (st.bps) -tc_print_rate (PRINT_FP ,NULL ,"%s " , - st.bps); +tc_print_rate (PRINT_ANY ,"rate" ,"%s " , st.bps);if (st.pps) -fprintf (fp,"%upps " , st.pps); +print_uint (PRINT_ANY ,"pps" ,"%upps " , st.pps); }if (st.qlen || st.backlog) { -fprintf (fp,"backlog " ); +print_string (PRINT_FP ,NULL ,"backlog " ,NULL );if (st.backlog) -print_size (PRINT_FP ,NULL ,"%s " , - st.backlog); +print_size (PRINT_ANY ,"backlog" ,"%s " , st.backlog);if (st.qlen) -fprintf (fp,"%up " , st.qlen); +print_uint (PRINT_ANY ,"qlen" ,"%up " , st.qlen); } } }
Signature · 1 line
2.43.0
PATCH 2/5 pedit: log errors to stderr
In reply to Stephen HemmingerThe errors should bo to stderr, not to stdout.
--- tc/m_pedit.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
tc/m_pedit.c +3 -3
@@ -771,20 +771,20 @@ static int print_pedit(struct action_util *au, FILE *f, struct rtattr *arg) sel =RTA_DATA (tb[TCA_PEDIT_PARMS_EX ]);if (!tb[TCA_PEDIT_KEYS_EX ]) { -fprintf (f,"Netlink error\n" ); +fprintf (stderr,"Netlink error\n" );return -1 ; } keys_ex =calloc (sel->nkeys,sizeof (*keys_ex));if (!keys_ex) { -fprintf (f,"Out of memory\n" ); +fprintf (stderr,"Out of memory\n" );return -1 ; } err =pedit_keys_ex_getattr (tb[TCA_PEDIT_KEYS_EX ], keys_ex, sel->nkeys);if (err) { -fprintf (f,"Netlink error\n" ); +fprintf (stderr,"Netlink error\n" );free (keys_ex);return -1 ;
Signature · 1 line
2.43.0
PATCH 3/5 skbmod: support json in print
In reply to Stephen HemmingerThis tc action never got jsonized.
--- tc/m_skbmod.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-)
tc/m_skbmod.c +21 -16
@@ -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 ; }
Signature · 1 line
2.43.0
PATCH 4/5 simple: support json output
In reply to Stephen HemmingerLast action that never got JSON support.
--- tc/m_simple.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
tc/m_simple.c +5 -3
@@ -179,9 +179,11 @@ static int print_simple(struct action_util *au, FILE *f, struct rtattr *arg) simpdata =RTA_DATA (tb[TCA_DEF_DATA ]); -fprintf (f,"Simple <%s>\n" , simpdata); -fprintf (f,"\t index %u ref %d bind %d" , sel->index, - sel->refcnt, sel->bindcnt); +print_string (PRINT_ANY ,"simple" ,"Simple <%s>" , simpdata); +print_nl (); +print_uint (PRINT_ANY ,"index" ,"\t index %u " , sel->index); +print_int (PRINT_ANY ,"ref" ,"ref %d " , sel->refcnt); +print_int (PRINT_ANY ,"bind" ,"bind %d" , sel->bindcnt);if (show_stats) {if (tb[TCA_DEF_TM ]) {
Signature · 1 line
2.43.0
PATCH 5/5 tc-simple.8: take Jamal's prompt off examples
In reply to Stephen HemmingerThe examples on tc-simple man page had extra stuff in the prompt which is not necessary.
--- man/man8/tc-simple.8 | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
man/man8/tc-simple.8 +6 -6
@@ -55,11 +55,11 @@ grep the logs to see the logged message display stats again and observe increment by 1 .EX - hadi@noma1:$ tc qdisc add dev eth0 ingress - hadi@noma1:$tc filter add dev eth0 parent ffff: protocol ip prio 5 \\ + $ tc qdisc add dev eth0 ingress + $ tc filter add dev eth0 parent ffff: protocol ip prio 5 \\ u32 match ip protocol 1 0xff flowid 1:1 action simple sdata "Incoming ICMP" - hadi@noma1:$ sudo tc -s filter ls dev eth0 parent ffff: + $ sudo tc -s filter ls dev eth0 parent ffff: filter protocol ip pref 5 u32 filter protocol ip pref 5 u32 fh 800: ht divisor 1 filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
@@ -71,7 +71,7 @@ display stats again and observe increment by 1 backlog 0b 0p requeues 0 - hadi@noma1$ ping -c 1 www.google.ca + $ ping -c 1 www.google.ca PING www.google.ca (74.125.225.120) 56(84) bytes of data. 64 bytes from ord08s08-in-f24.1e100.net (74.125.225.120): icmp_req=1 ttl=53 time=31.3 ms
@@ -79,10 +79,10 @@ display stats again and observe increment by 1 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 31.316/31.316/31.316/0.000 ms - hadi@noma1$ dmesg | grep simple + $ dmesg | grep simple [135354.473951] simple: Incoming ICMP_1 - hadi@noma1$ sudo tc/tc -s filter ls dev eth0 parent ffff: + $ sudo tc/tc -s filter ls dev eth0 parent ffff: filter protocol ip pref 5 u32 filter protocol ip pref 5 u32 fh 800: ht divisor 1 filter protocol ip pref 5 u32 fh 800::800 order 2048 key ht 800 bkt 0 flowid 1:1
Signature · 1 line
2.43.0
Quoted 3 lines · Stephen Hemminger
Some more places in TC where JSON output is missing or could be corrupted. And some things found while reviewing tc-simple man page.
The series mixes the fixes with new features like json support. It makes sense to split fixes and new features
Quoted 15 lines
Stephen Hemminger (5):
tc: support JSON for legacy stats
pedit: log errors to stderr
skbmod: support json in print
simple: support json output
tc-simple.8: take Jamal's prompt off examplesman/man8/tc-simple.8 | 12 ++++++------ tc/m_pedit.c | 6 +++--- tc/m_simple.c | 8 +++++--- tc/m_skbmod.c | 37 +++++++++++++++++++++---------------- tc/tc_util.c | 28 +++++++++++++++------------- 5 files changed, 50 insertions(+), 41 deletions(-)
Quoted 23 lines · On Wed, 13 Mar 2024 14:08:27 +0300 Denis Kirjanov <[email protected]> wrote:
Quoted 3 lines · Stephen Hemminger
Some more places in TC where JSON output is missing or could be corrupted. And some things found while reviewing tc-simple man page.
The series mixes the fixes with new features like json support. It makes sense to split fixes and new features
Quoted 15 lines
Stephen Hemminger (5):
tc: support JSON for legacy stats
pedit: log errors to stderr
skbmod: support json in print
simple: support json output
tc-simple.8: take Jamal's prompt off examplesman/man8/tc-simple.8 | 12 ++++++------ tc/m_pedit.c | 6 +++--- tc/m_simple.c | 8 +++++--- tc/m_skbmod.c | 37 +++++++++++++++++++++---------------- tc/tc_util.c | 28 +++++++++++++++------------- 5 files changed, 50 insertions(+), 41 deletions(-)
Not supporting JSON is a bug at this point
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Hello:
This series was applied to iproute2/iproute2.git (main) by Stephen Hemminger <[email protected]>:
Quoted 4 lines · On Tue, 12 Mar 2024 15:53:27 -0700 you wrote:
Some more places in TC where JSON output is missing or could be corrupted. And some things found while reviewing tc-simple man page.
Quoted 8 lines
Stephen Hemminger (5):
tc: support JSON for legacy stats
pedit: log errors to stderr
skbmod: support json in print
simple: support json output
tc-simple.8: take Jamal's prompt off examples[...]
Here is the summary with links:
- [iproute2,1/5] tc: support JSON for legacy stats
https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=fc4226d2475a - [iproute2,2/5] pedit: log errors to stderr https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=ba52b3d4dd4f - [iproute2,3/5] skbmod: support json in print https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=af0ddbfa51f9 - [iproute2,4/5] simple: support json output https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=69d55c213da8 - [iproute2,5/5] tc-simple.8: take Jamal's prompt off examples https://git.kernel.org/pub/scm/network/iproute2/iproute2.git/commit/?id=11740815bfe6
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html