tc: jsonify qdisc core
Add json output to qdisc core. Signed-off-by: Jiri Pirko <jiri@mellanox.com>
This commit is contained in:
parent
81051c60c2
commit
c91d262f41
5
tc/tc.c
5
tc/tc.c
|
|
@ -41,6 +41,7 @@ int batch_mode;
|
||||||
int use_iec;
|
int use_iec;
|
||||||
int force;
|
int force;
|
||||||
bool use_names;
|
bool use_names;
|
||||||
|
int json;
|
||||||
|
|
||||||
static char *conf_file;
|
static char *conf_file;
|
||||||
|
|
||||||
|
|
@ -189,7 +190,7 @@ static void usage(void)
|
||||||
" tc [-force] -batch filename\n"
|
" tc [-force] -batch filename\n"
|
||||||
"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
|
"where OBJECT := { qdisc | class | filter | action | monitor | exec }\n"
|
||||||
" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n"
|
" OPTIONS := { -s[tatistics] | -d[etails] | -r[aw] | -p[retty] | -b[atch] [filename] | -n[etns] name |\n"
|
||||||
" -nm | -nam[es] | { -cf | -conf } path }\n");
|
" -nm | -nam[es] | { -cf | -conf } path } | -j[son]\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int do_cmd(int argc, char **argv)
|
static int do_cmd(int argc, char **argv)
|
||||||
|
|
@ -312,6 +313,8 @@ int main(int argc, char **argv)
|
||||||
} else if (matches(argv[1], "-tshort") == 0) {
|
} else if (matches(argv[1], "-tshort") == 0) {
|
||||||
++timestamp;
|
++timestamp;
|
||||||
++timestamp_short;
|
++timestamp_short;
|
||||||
|
} else if (matches(argv[1], "-json") == 0) {
|
||||||
|
++json;
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
|
fprintf(stderr, "Option \"%s\" is unknown, try \"tc -help\".\n", argv[1]);
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
||||||
|
|
@ -227,39 +227,44 @@ int print_qdisc(const struct sockaddr_nl *who,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open_json_object(NULL);
|
||||||
|
|
||||||
if (n->nlmsg_type == RTM_DELQDISC)
|
if (n->nlmsg_type == RTM_DELQDISC)
|
||||||
fprintf(fp, "deleted ");
|
print_bool(PRINT_ANY, "deleted", "deleted ", true);
|
||||||
|
|
||||||
if (n->nlmsg_type == RTM_NEWQDISC &&
|
if (n->nlmsg_type == RTM_NEWQDISC &&
|
||||||
(n->nlmsg_flags & NLM_F_CREATE) &&
|
(n->nlmsg_flags & NLM_F_CREATE) &&
|
||||||
(n->nlmsg_flags & NLM_F_REPLACE))
|
(n->nlmsg_flags & NLM_F_REPLACE))
|
||||||
fprintf(fp, "replaced ");
|
print_bool(PRINT_ANY, "replaced", "replaced ", true);
|
||||||
|
|
||||||
if (n->nlmsg_type == RTM_NEWQDISC &&
|
if (n->nlmsg_type == RTM_NEWQDISC &&
|
||||||
(n->nlmsg_flags & NLM_F_CREATE) &&
|
(n->nlmsg_flags & NLM_F_CREATE) &&
|
||||||
(n->nlmsg_flags & NLM_F_EXCL))
|
(n->nlmsg_flags & NLM_F_EXCL))
|
||||||
fprintf(fp, "added ");
|
print_bool(PRINT_ANY, "added", "added ", true);
|
||||||
|
|
||||||
if (show_raw)
|
print_string(PRINT_ANY, "kind", "qdisc %s",
|
||||||
fprintf(fp, "qdisc %s %x:[%08x] ",
|
rta_getattr_str(tb[TCA_KIND]));
|
||||||
rta_getattr_str(tb[TCA_KIND]),
|
sprintf(abuf, "%x:", t->tcm_handle >> 16);
|
||||||
t->tcm_handle >> 16, t->tcm_handle);
|
print_string(PRINT_ANY, "handle", " %s", abuf);
|
||||||
else
|
if (show_raw) {
|
||||||
fprintf(fp, "qdisc %s %x: ", rta_getattr_str(tb[TCA_KIND]),
|
sprintf(abuf, "[%08x]", t->tcm_handle);
|
||||||
t->tcm_handle >> 16);
|
print_string(PRINT_FP, NULL, "%s", abuf);
|
||||||
|
}
|
||||||
|
print_string(PRINT_FP, NULL, " ", NULL);
|
||||||
|
|
||||||
if (filter_ifindex == 0)
|
if (filter_ifindex == 0)
|
||||||
fprintf(fp, "dev %s ", ll_index_to_name(t->tcm_ifindex));
|
print_string(PRINT_ANY, "dev", "dev %s ",
|
||||||
|
ll_index_to_name(t->tcm_ifindex));
|
||||||
|
|
||||||
if (t->tcm_parent == TC_H_ROOT)
|
if (t->tcm_parent == TC_H_ROOT)
|
||||||
fprintf(fp, "root ");
|
print_bool(PRINT_ANY, "root", "root ", true);
|
||||||
else if (t->tcm_parent) {
|
else if (t->tcm_parent) {
|
||||||
print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
|
print_tc_classid(abuf, sizeof(abuf), t->tcm_parent);
|
||||||
fprintf(fp, "parent %s ", abuf);
|
print_string(PRINT_ANY, "parent", "parent %s ", abuf);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (t->tcm_info != 1)
|
if (t->tcm_info != 1)
|
||||||
fprintf(fp, "refcnt %d ", t->tcm_info);
|
print_uint(PRINT_ANY, "refcnt", "refcnt %u ", t->tcm_info);
|
||||||
|
|
||||||
/* pfifo_fast is generic enough to warrant the hardcoding --JHS */
|
/* pfifo_fast is generic enough to warrant the hardcoding --JHS */
|
||||||
if (strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND])) == 0)
|
if (strcmp("pfifo_fast", RTA_DATA(tb[TCA_KIND])) == 0)
|
||||||
|
|
@ -267,17 +272,21 @@ int print_qdisc(const struct sockaddr_nl *who,
|
||||||
else
|
else
|
||||||
q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]));
|
q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]));
|
||||||
|
|
||||||
|
open_json_object("options");
|
||||||
if (tb[TCA_OPTIONS]) {
|
if (tb[TCA_OPTIONS]) {
|
||||||
if (q)
|
if (q)
|
||||||
q->print_qopt(q, fp, tb[TCA_OPTIONS]);
|
q->print_qopt(q, fp, tb[TCA_OPTIONS]);
|
||||||
else
|
else
|
||||||
fprintf(fp, "[cannot parse qdisc parameters]");
|
print_string(PRINT_FP, NULL,
|
||||||
|
"[cannot parse qdisc parameters]", NULL);
|
||||||
}
|
}
|
||||||
fprintf(fp, "\n");
|
close_json_object();
|
||||||
|
|
||||||
|
print_string(PRINT_FP, NULL, "\n", NULL);
|
||||||
|
|
||||||
if (show_details && tb[TCA_STAB]) {
|
if (show_details && tb[TCA_STAB]) {
|
||||||
print_size_table(fp, " ", tb[TCA_STAB]);
|
print_size_table(fp, " ", tb[TCA_STAB]);
|
||||||
fprintf(fp, "\n");
|
print_string(PRINT_FP, NULL, "\n", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (show_stats) {
|
if (show_stats) {
|
||||||
|
|
@ -285,14 +294,15 @@ int print_qdisc(const struct sockaddr_nl *who,
|
||||||
|
|
||||||
if (tb[TCA_STATS] || tb[TCA_STATS2] || tb[TCA_XSTATS]) {
|
if (tb[TCA_STATS] || tb[TCA_STATS2] || tb[TCA_XSTATS]) {
|
||||||
print_tcstats_attr(fp, tb, " ", &xstats);
|
print_tcstats_attr(fp, tb, " ", &xstats);
|
||||||
fprintf(fp, "\n");
|
print_string(PRINT_FP, NULL, "\n", NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (q && xstats && q->print_xstats) {
|
if (q && xstats && q->print_xstats) {
|
||||||
q->print_xstats(q, fp, xstats);
|
q->print_xstats(q, fp, xstats);
|
||||||
fprintf(fp, "\n");
|
print_string(PRINT_FP, NULL, "\n", NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
close_json_object();
|
||||||
fflush(fp);
|
fflush(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -360,10 +370,12 @@ static int tc_qdisc_list(int argc, char **argv)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
new_json_obj(json);
|
||||||
if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
|
if (rtnl_dump_filter(&rth, print_qdisc, stdout) < 0) {
|
||||||
fprintf(stderr, "Dump terminated\n");
|
fprintf(stderr, "Dump terminated\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
delete_json_obj();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include <linux/gen_stats.h>
|
#include <linux/gen_stats.h>
|
||||||
|
|
||||||
#include "tc_core.h"
|
#include "tc_core.h"
|
||||||
|
#include "json_print.h"
|
||||||
|
|
||||||
/* This is the deprecated multiqueue interface */
|
/* This is the deprecated multiqueue interface */
|
||||||
#ifndef TCA_PRIO_MAX
|
#ifndef TCA_PRIO_MAX
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue