2 * src/nl-tctree-dump.c Dump Traffic Control Tree
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation version 2.1
9 * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
13 #include <linux/pkt_sched.h>
15 static struct nl_handle *nl_handle;
16 static struct nl_cache *qdisc_cache, *class_cache;
17 static struct nl_dump_params dump_params = {
18 .dp_type = NL_DUMP_FULL,
22 static void print_qdisc(struct nl_object *, void *);
24 static void print_class(struct nl_object *obj, void *arg)
26 struct rtnl_qdisc *leaf;
27 struct rtnl_class *class = (struct rtnl_class *) obj;
28 struct nl_cache *cls_cache;
29 uint32_t parent = rtnl_class_get_handle(class);
31 dump_params.dp_prefix = (int) arg;
32 nl_object_dump(obj, &dump_params);
34 leaf = rtnl_class_leaf_qdisc(class, qdisc_cache);
36 print_qdisc((struct nl_object *) leaf, arg + 2);
38 rtnl_class_foreach_child(class, class_cache, &print_class, arg + 2);
40 cls_cache = rtnl_cls_alloc_cache(nl_handle, ifindex, parent);
44 dump_params.dp_prefix = (int) arg + 2;
45 nl_cache_dump(cls_cache, &dump_params);
46 nl_cache_free(cls_cache);
49 static void print_qdisc(struct nl_object *obj, void *arg)
51 struct rtnl_qdisc *qdisc = (struct rtnl_qdisc *) obj;
52 struct nl_cache *cls_cache;
53 uint32_t parent = rtnl_qdisc_get_handle(qdisc);
55 dump_params.dp_prefix = (int) arg;
56 nl_object_dump(obj, &dump_params);
58 rtnl_qdisc_foreach_child(qdisc, class_cache, &print_class, arg + 2);
60 cls_cache = rtnl_cls_alloc_cache(nl_handle, ifindex, parent);
64 dump_params.dp_prefix = (int) arg + 2;
65 nl_cache_dump(cls_cache, &dump_params);
66 nl_cache_free(cls_cache);
69 static void print_link(struct nl_object *obj, void *arg)
71 struct rtnl_link *link = (struct rtnl_link *) obj;
72 struct rtnl_qdisc *qdisc;
74 ifindex = rtnl_link_get_ifindex(link);
75 dump_params.dp_prefix = 0;
76 nl_object_dump(obj, &dump_params);
78 class_cache = rtnl_class_alloc_cache(nl_handle, ifindex);
82 qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, TC_H_ROOT);
84 print_qdisc((struct nl_object *) qdisc, (void *) 2);
85 rtnl_qdisc_put(qdisc);
88 qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, 0);
90 print_qdisc((struct nl_object *) qdisc, (void *) 2);
91 rtnl_qdisc_put(qdisc);
94 qdisc = rtnl_qdisc_get_by_parent(qdisc_cache, ifindex, TC_H_INGRESS);
96 print_qdisc((struct nl_object *) qdisc, (void *) 2);
97 rtnl_qdisc_put(qdisc);
100 nl_cache_free(class_cache);
103 int main(int argc, char *argv[])
105 struct nl_cache *link_cache;
107 if (nltool_init(argc, argv) < 0)
110 dump_params.dp_fd = stdout;
113 if (!strcasecmp(argv[1], "brief"))
114 dump_params.dp_type = NL_DUMP_BRIEF;
115 else if (!strcasecmp(argv[1], "full"))
116 dump_params.dp_type = NL_DUMP_FULL;
117 else if (!strcasecmp(argv[1], "stats"))
118 dump_params.dp_type = NL_DUMP_STATS;
121 nl_handle = nl_handle_alloc_nondefault(nltool_cbset);
125 if (nltool_connect(nl_handle, NETLINK_ROUTE) < 0)
128 link_cache = nltool_alloc_link_cache(nl_handle);
132 qdisc_cache = nltool_alloc_qdisc_cache(nl_handle);
136 nl_cache_foreach(link_cache, &print_link, NULL);
138 nl_cache_free(qdisc_cache);
139 nl_cache_free(link_cache);
142 nl_handle_destroy(nl_handle);