@@ -333,8 +333,10 @@ int print_class(struct nlmsghdr *n, void *arg)
return -1;
}
+ open_json_object(NULL);
+
if (n->nlmsg_type == RTM_DELTCLASS)
- fprintf(fp, "deleted ");
+ print_bool(PRINT_ANY, "deleted", "deleted ", true);
abuf[0] = 0;
if (t->tcm_handle) {
@@ -343,42 +345,47 @@ int print_class(struct nlmsghdr *n, void *arg)
else
print_tc_classid(abuf, sizeof(abuf), t->tcm_handle);
}
- fprintf(fp, "class %s %s ", rta_getattr_str(tb[TCA_KIND]), abuf);
+
+ print_string(PRINT_ANY, "kind", "class %s ", rta_getattr_str(tb[TCA_KIND]));
+ print_string(PRINT_ANY, "classid", "%s ", abuf);
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)
- fprintf(fp, "root ");
+ print_bool(PRINT_ANY, "root", "root ", true);
else {
if (filter_qdisc)
print_tc_classid(abuf, sizeof(abuf), TC_H_MIN(t->tcm_parent));
else
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)
- fprintf(fp, "leaf %x: ", t->tcm_info>>16);
+ print_uint(PRINT_ANY, "leaf", "leaf %x: ", t->tcm_info>>16);
q = get_qdisc_kind(RTA_DATA(tb[TCA_KIND]));
if (tb[TCA_OPTIONS]) {
+ open_json_object("options");
if (q && q->print_copt)
q->print_copt(q, fp, tb[TCA_OPTIONS]);
else
- fprintf(fp, "[cannot parse class parameters]");
+ print_string(PRINT_FP, NULL, "[cannot parse class parameters]", NULL);
+ close_json_object();
}
- fprintf(fp, "\n");
+ print_string(PRINT_FP, NULL, "\n", NULL);
if (show_stats) {
struct rtattr *xstats = NULL;
if (tb[TCA_STATS] || tb[TCA_STATS2]) {
print_tcstats_attr(fp, tb, " ", &xstats);
- fprintf(fp, "\n");
+ print_string(PRINT_FP, NULL, "\n", NULL);
}
if (q && (xstats || tb[TCA_XSTATS]) && q->print_xstats) {
q->print_xstats(q, fp, xstats ? : tb[TCA_XSTATS]);
- fprintf(fp, "\n");
+ print_string(PRINT_FP, NULL, "\n", NULL);
}
}
+ close_json_object();
fflush(fp);
return 0;
}
@@ -450,10 +457,12 @@ static int tc_class_list(int argc, char **argv)
return 1;
}
+ new_json_obj(json);
if (rtnl_dump_filter(&rth, print_class, stdout) < 0) {
fprintf(stderr, "Dump terminated\n");
return 1;
}
+ delete_json_obj();
if (show_graph)
graph_cls_show(stdout, &buf[0], &root_cls_list, 0);