* [PATCH iproute2-next v3 1/1] police: Add support for json output
@ 2021-06-06 6:22 Roi Dayan
2021-06-07 2:48 ` David Ahern
0 siblings, 1 reply; 3+ messages in thread
From: Roi Dayan @ 2021-06-06 6:22 UTC (permalink / raw)
To: netdev
Cc: Roi Dayan, Paul Blakey, David Ahern, Jamal Hadi Salim, Stephen Hemminger
Change to use the print wrappers instead of fprintf().
This is example output of the options part before this commit:
"options": {
"handle": 1,
"in_hw": true,
"actions": [ {
"order": 1 police 0x2 ,
"control_action": {
"type": "drop"
},
"control_action": {
"type": "continue"
}overhead 0b linklayer unspec
ref 1 bind 1
,
"used_hw_stats": [ "delayed" ]
} ]
}
This is the output of the same dump with this commit:
"options": {
"handle": 1,
"in_hw": true,
"actions": [ {
"order": 1,
"kind": "police",
"index": 2,
"control_action": {
"type": "drop"
},
"control_action": {
"type": "continue"
},
"overhead": 0,
"linklayer": "unspec",
"ref": 1,
"bind": 1,
"used_hw_stats": [ "delayed" ]
} ]
}
Signed-off-by: Roi Dayan <roid@nvidia.com>
Reviewed-by: Paul Blakey <paulb@nvidia.com>
---
Notes:
v2
- fix json output to match correctly the other actions
i.e. output the action name in key 'kind' and unsigned for the index
v3
- print errors to stderr.
- return -1 on null key.
tc/m_police.c | 32 ++++++++++++++++++--------------
1 file changed, 18 insertions(+), 14 deletions(-)
diff --git a/tc/m_police.c b/tc/m_police.c
index 9ef0e40b861b..560a793245c8 100644
--- a/tc/m_police.c
+++ b/tc/m_police.c
@@ -278,18 +278,19 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
__u64 rate64, prate64;
__u64 pps64, ppsburst64;
+ print_string(PRINT_ANY, "kind", "%s", "police");
if (arg == NULL)
return 0;
parse_rtattr_nested(tb, TCA_POLICE_MAX, arg);
- if (tb[TCA_POLICE_TBF] == NULL) {
- fprintf(f, "[NULL police tbf]");
- return 0;
+ if (tb[TCA_POLICE_TBF] == NULL || true) {
+ fprintf(stderr, "[NULL police tbf]");
+ return -1;
}
#ifndef STOOPID_8BYTE
if (RTA_PAYLOAD(tb[TCA_POLICE_TBF]) < sizeof(*p)) {
- fprintf(f, "[truncated police tbf]");
+ fprintf(stderr, "[truncated police tbf]");
return -1;
}
#endif
@@ -300,13 +301,13 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
RTA_PAYLOAD(tb[TCA_POLICE_RATE64]) >= sizeof(rate64))
rate64 = rta_getattr_u64(tb[TCA_POLICE_RATE64]);
- fprintf(f, " police 0x%x ", p->index);
+ print_uint(PRINT_ANY, "index", "\t index %u ", p->index);
tc_print_rate(PRINT_FP, NULL, "rate %s ", rate64);
buffer = tc_calc_xmitsize(rate64, p->burst);
print_size(PRINT_FP, NULL, "burst %s ", buffer);
print_size(PRINT_FP, NULL, "mtu %s ", p->mtu);
if (show_raw)
- fprintf(f, "[%08x] ", p->burst);
+ print_hex(PRINT_FP, NULL, "[%08x] ", p->burst);
prate64 = p->peakrate.rate;
if (tb[TCA_POLICE_PEAKRATE64] &&
@@ -327,8 +328,8 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
pps64 = rta_getattr_u64(tb[TCA_POLICE_PKTRATE64]);
ppsburst64 = rta_getattr_u64(tb[TCA_POLICE_PKTBURST64]);
ppsburst64 = tc_calc_xmitsize(pps64, ppsburst64);
- fprintf(f, "pkts_rate %llu ", pps64);
- fprintf(f, "pkts_burst %llu ", ppsburst64);
+ print_u64(PRINT_ANY, "pkts_rate", "pkts_rate %llu ", pps64);
+ print_u64(PRINT_ANY, "pkts_burst", "pkts_burst %llu ", ppsburst64);
}
print_action_control(f, "action ", p->action, "");
@@ -337,14 +338,17 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
__u32 action = rta_getattr_u32(tb[TCA_POLICE_RESULT]);
print_action_control(f, "/", action, " ");
- } else
- fprintf(f, " ");
+ } else {
+ print_string(PRINT_FP, NULL, " ", NULL);
+ }
- fprintf(f, "overhead %ub ", p->rate.overhead);
+ print_uint(PRINT_ANY, "overhead", "overhead %u ", p->rate.overhead);
linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK);
if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
- fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
- fprintf(f, "\n\tref %d bind %d", p->refcnt, p->bindcnt);
+ print_string(PRINT_ANY, "linklayer", "linklayer %s ",
+ sprint_linklayer(linklayer, b2));
+ print_int(PRINT_ANY, "ref", "ref %d ", p->refcnt);
+ print_int(PRINT_ANY, "bind", "bind %d ", p->bindcnt);
if (show_stats) {
if (tb[TCA_POLICE_TM]) {
struct tcf_t *tm = RTA_DATA(tb[TCA_POLICE_TM]);
@@ -352,7 +356,7 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
print_tm(f, tm);
}
}
- fprintf(f, "\n");
+ print_nl();
return 0;
--
2.26.3
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2-next v3 1/1] police: Add support for json output
2021-06-06 6:22 [PATCH iproute2-next v3 1/1] police: Add support for json output Roi Dayan
@ 2021-06-07 2:48 ` David Ahern
2021-06-07 6:16 ` Roi Dayan
0 siblings, 1 reply; 3+ messages in thread
From: David Ahern @ 2021-06-07 2:48 UTC (permalink / raw)
To: Roi Dayan, netdev
Cc: Paul Blakey, David Ahern, Jamal Hadi Salim, Stephen Hemminger
On 6/6/21 12:22 AM, Roi Dayan wrote:
> diff --git a/tc/m_police.c b/tc/m_police.c
> index 9ef0e40b861b..560a793245c8 100644
> --- a/tc/m_police.c
> +++ b/tc/m_police.c
> @@ -278,18 +278,19 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
> __u64 rate64, prate64;
> __u64 pps64, ppsburst64;
>
> + print_string(PRINT_ANY, "kind", "%s", "police");
> if (arg == NULL)
> return 0;
>
> parse_rtattr_nested(tb, TCA_POLICE_MAX, arg);
>
> - if (tb[TCA_POLICE_TBF] == NULL) {
> - fprintf(f, "[NULL police tbf]");
> - return 0;
> + if (tb[TCA_POLICE_TBF] == NULL || true) {
why '|| true'? leftover from special casing tests?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH iproute2-next v3 1/1] police: Add support for json output
2021-06-07 2:48 ` David Ahern
@ 2021-06-07 6:16 ` Roi Dayan
0 siblings, 0 replies; 3+ messages in thread
From: Roi Dayan @ 2021-06-07 6:16 UTC (permalink / raw)
To: David Ahern, netdev; +Cc: Paul Blakey, Jamal Hadi Salim, Stephen Hemminger
On 2021-06-07 5:48 AM, David Ahern wrote:
> On 6/6/21 12:22 AM, Roi Dayan wrote:
>> diff --git a/tc/m_police.c b/tc/m_police.c
>> index 9ef0e40b861b..560a793245c8 100644
>> --- a/tc/m_police.c
>> +++ b/tc/m_police.c
>> @@ -278,18 +278,19 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
>> __u64 rate64, prate64;
>> __u64 pps64, ppsburst64;
>>
>> + print_string(PRINT_ANY, "kind", "%s", "police");
>> if (arg == NULL)
>> return 0;
>>
>> parse_rtattr_nested(tb, TCA_POLICE_MAX, arg);
>>
>> - if (tb[TCA_POLICE_TBF] == NULL) {
>> - fprintf(f, "[NULL police tbf]");
>> - return 0;
>> + if (tb[TCA_POLICE_TBF] == NULL || true) {
>
> why '|| true'? leftover from special casing tests?
>
>
>
oops debug left over. sorry for that. fixing.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-06-07 6:17 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-06 6:22 [PATCH iproute2-next v3 1/1] police: Add support for json output Roi Dayan
2021-06-07 2:48 ` David Ahern
2021-06-07 6:16 ` Roi Dayan
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.