|
|
74a1de |
From 04b921c03a4680931df6660b88444f2478fb585c Mon Sep 17 00:00:00 2001
|
|
|
74a1de |
Message-Id: <04b921c03a4680931df6660b88444f2478fb585c.1628790091.git.aclaudi@redhat.com>
|
|
|
74a1de |
In-Reply-To: <650694eb0120722499207078f965442ef7343bb1.1628790091.git.aclaudi@redhat.com>
|
|
|
74a1de |
References: <650694eb0120722499207078f965442ef7343bb1.1628790091.git.aclaudi@redhat.com>
|
|
|
74a1de |
From: Andrea Claudi <aclaudi@redhat.com>
|
|
|
74a1de |
Date: Wed, 11 Aug 2021 12:55:14 +0200
|
|
|
74a1de |
Subject: [PATCH] police: Add support for json output
|
|
|
74a1de |
|
|
|
74a1de |
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1981393
|
|
|
74a1de |
Upstream Status: iproute2.git commit 0d5cf51e
|
|
|
74a1de |
|
|
|
74a1de |
commit 0d5cf51e0d6c7bfdc51754381b85367b5f8e254a
|
|
|
74a1de |
Author: Roi Dayan <roid@nvidia.com>
|
|
|
74a1de |
Date: Mon Jun 7 09:44:08 2021 +0300
|
|
|
74a1de |
|
|
|
74a1de |
police: Add support for json output
|
|
|
74a1de |
|
|
|
74a1de |
Change to use the print wrappers instead of fprintf().
|
|
|
74a1de |
|
|
|
74a1de |
This is example output of the options part before this commit:
|
|
|
74a1de |
|
|
|
74a1de |
"options": {
|
|
|
74a1de |
"handle": 1,
|
|
|
74a1de |
"in_hw": true,
|
|
|
74a1de |
"actions": [ {
|
|
|
74a1de |
"order": 1 police 0x2 ,
|
|
|
74a1de |
"control_action": {
|
|
|
74a1de |
"type": "drop"
|
|
|
74a1de |
},
|
|
|
74a1de |
"control_action": {
|
|
|
74a1de |
"type": "continue"
|
|
|
74a1de |
}overhead 0b linklayer unspec
|
|
|
74a1de |
ref 1 bind 1
|
|
|
74a1de |
,
|
|
|
74a1de |
"used_hw_stats": [ "delayed" ]
|
|
|
74a1de |
} ]
|
|
|
74a1de |
}
|
|
|
74a1de |
|
|
|
74a1de |
This is the output of the same dump with this commit:
|
|
|
74a1de |
|
|
|
74a1de |
"options": {
|
|
|
74a1de |
"handle": 1,
|
|
|
74a1de |
"in_hw": true,
|
|
|
74a1de |
"actions": [ {
|
|
|
74a1de |
"order": 1,
|
|
|
74a1de |
"kind": "police",
|
|
|
74a1de |
"index": 2,
|
|
|
74a1de |
"control_action": {
|
|
|
74a1de |
"type": "drop"
|
|
|
74a1de |
},
|
|
|
74a1de |
"control_action": {
|
|
|
74a1de |
"type": "continue"
|
|
|
74a1de |
},
|
|
|
74a1de |
"overhead": 0,
|
|
|
74a1de |
"linklayer": "unspec",
|
|
|
74a1de |
"ref": 1,
|
|
|
74a1de |
"bind": 1,
|
|
|
74a1de |
"used_hw_stats": [ "delayed" ]
|
|
|
74a1de |
} ]
|
|
|
74a1de |
}
|
|
|
74a1de |
|
|
|
74a1de |
Signed-off-by: Roi Dayan <roid@nvidia.com>
|
|
|
74a1de |
Reviewed-by: Paul Blakey <paulb@nvidia.com>
|
|
|
74a1de |
Signed-off-by: David Ahern <dsahern@kernel.org>
|
|
|
74a1de |
|
|
|
74a1de |
Signed-off-by: Andrea Claudi <aclaudi@redhat.com>
|
|
|
74a1de |
---
|
|
|
74a1de |
tc/m_police.c | 30 +++++++++++++++++-------------
|
|
|
74a1de |
1 file changed, 17 insertions(+), 13 deletions(-)
|
|
|
74a1de |
|
|
|
74a1de |
diff --git a/tc/m_police.c b/tc/m_police.c
|
|
|
74a1de |
index 9ef0e40b..2594c089 100644
|
|
|
74a1de |
--- a/tc/m_police.c
|
|
|
74a1de |
+++ b/tc/m_police.c
|
|
|
74a1de |
@@ -278,18 +278,19 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
|
|
|
74a1de |
__u64 rate64, prate64;
|
|
|
74a1de |
__u64 pps64, ppsburst64;
|
|
|
74a1de |
|
|
|
74a1de |
+ print_string(PRINT_ANY, "kind", "%s", "police");
|
|
|
74a1de |
if (arg == NULL)
|
|
|
74a1de |
return 0;
|
|
|
74a1de |
|
|
|
74a1de |
parse_rtattr_nested(tb, TCA_POLICE_MAX, arg);
|
|
|
74a1de |
|
|
|
74a1de |
if (tb[TCA_POLICE_TBF] == NULL) {
|
|
|
74a1de |
- fprintf(f, "[NULL police tbf]");
|
|
|
74a1de |
- return 0;
|
|
|
74a1de |
+ fprintf(stderr, "[NULL police tbf]");
|
|
|
74a1de |
+ return -1;
|
|
|
74a1de |
}
|
|
|
74a1de |
#ifndef STOOPID_8BYTE
|
|
|
74a1de |
if (RTA_PAYLOAD(tb[TCA_POLICE_TBF]) < sizeof(*p)) {
|
|
|
74a1de |
- fprintf(f, "[truncated police tbf]");
|
|
|
74a1de |
+ fprintf(stderr, "[truncated police tbf]");
|
|
|
74a1de |
return -1;
|
|
|
74a1de |
}
|
|
|
74a1de |
#endif
|
|
|
74a1de |
@@ -300,13 +301,13 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
|
|
|
74a1de |
RTA_PAYLOAD(tb[TCA_POLICE_RATE64]) >= sizeof(rate64))
|
|
|
74a1de |
rate64 = rta_getattr_u64(tb[TCA_POLICE_RATE64]);
|
|
|
74a1de |
|
|
|
74a1de |
- fprintf(f, " police 0x%x ", p->index);
|
|
|
74a1de |
+ print_uint(PRINT_ANY, "index", "\t index %u ", p->index);
|
|
|
74a1de |
tc_print_rate(PRINT_FP, NULL, "rate %s ", rate64);
|
|
|
74a1de |
buffer = tc_calc_xmitsize(rate64, p->burst);
|
|
|
74a1de |
print_size(PRINT_FP, NULL, "burst %s ", buffer);
|
|
|
74a1de |
print_size(PRINT_FP, NULL, "mtu %s ", p->mtu);
|
|
|
74a1de |
if (show_raw)
|
|
|
74a1de |
- fprintf(f, "[%08x] ", p->burst);
|
|
|
74a1de |
+ print_hex(PRINT_FP, NULL, "[%08x] ", p->burst);
|
|
|
74a1de |
|
|
|
74a1de |
prate64 = p->peakrate.rate;
|
|
|
74a1de |
if (tb[TCA_POLICE_PEAKRATE64] &&
|
|
|
74a1de |
@@ -327,8 +328,8 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
|
|
|
74a1de |
pps64 = rta_getattr_u64(tb[TCA_POLICE_PKTRATE64]);
|
|
|
74a1de |
ppsburst64 = rta_getattr_u64(tb[TCA_POLICE_PKTBURST64]);
|
|
|
74a1de |
ppsburst64 = tc_calc_xmitsize(pps64, ppsburst64);
|
|
|
74a1de |
- fprintf(f, "pkts_rate %llu ", pps64);
|
|
|
74a1de |
- fprintf(f, "pkts_burst %llu ", ppsburst64);
|
|
|
74a1de |
+ print_u64(PRINT_ANY, "pkts_rate", "pkts_rate %llu ", pps64);
|
|
|
74a1de |
+ print_u64(PRINT_ANY, "pkts_burst", "pkts_burst %llu ", ppsburst64);
|
|
|
74a1de |
}
|
|
|
74a1de |
|
|
|
74a1de |
print_action_control(f, "action ", p->action, "");
|
|
|
74a1de |
@@ -337,14 +338,17 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
|
|
|
74a1de |
__u32 action = rta_getattr_u32(tb[TCA_POLICE_RESULT]);
|
|
|
74a1de |
|
|
|
74a1de |
print_action_control(f, "/", action, " ");
|
|
|
74a1de |
- } else
|
|
|
74a1de |
- fprintf(f, " ");
|
|
|
74a1de |
+ } else {
|
|
|
74a1de |
+ print_string(PRINT_FP, NULL, " ", NULL);
|
|
|
74a1de |
+ }
|
|
|
74a1de |
|
|
|
74a1de |
- fprintf(f, "overhead %ub ", p->rate.overhead);
|
|
|
74a1de |
+ print_uint(PRINT_ANY, "overhead", "overhead %u ", p->rate.overhead);
|
|
|
74a1de |
linklayer = (p->rate.linklayer & TC_LINKLAYER_MASK);
|
|
|
74a1de |
if (linklayer > TC_LINKLAYER_ETHERNET || show_details)
|
|
|
74a1de |
- fprintf(f, "linklayer %s ", sprint_linklayer(linklayer, b2));
|
|
|
74a1de |
- fprintf(f, "\n\tref %d bind %d", p->refcnt, p->bindcnt);
|
|
|
74a1de |
+ print_string(PRINT_ANY, "linklayer", "linklayer %s ",
|
|
|
74a1de |
+ sprint_linklayer(linklayer, b2));
|
|
|
74a1de |
+ print_int(PRINT_ANY, "ref", "ref %d ", p->refcnt);
|
|
|
74a1de |
+ print_int(PRINT_ANY, "bind", "bind %d ", p->bindcnt);
|
|
|
74a1de |
if (show_stats) {
|
|
|
74a1de |
if (tb[TCA_POLICE_TM]) {
|
|
|
74a1de |
struct tcf_t *tm = RTA_DATA(tb[TCA_POLICE_TM]);
|
|
|
74a1de |
@@ -352,7 +356,7 @@ static int print_police(struct action_util *a, FILE *f, struct rtattr *arg)
|
|
|
74a1de |
print_tm(f, tm);
|
|
|
74a1de |
}
|
|
|
74a1de |
}
|
|
|
74a1de |
- fprintf(f, "\n");
|
|
|
74a1de |
+ print_nl();
|
|
|
74a1de |
|
|
|
74a1de |
|
|
|
74a1de |
return 0;
|
|
|
74a1de |
--
|
|
|
74a1de |
2.31.1
|
|
|
74a1de |
|