12 #include <netlink/cli/utils.h>
13 #include <netlink/cli/link.h>
14 #include <netlink/cli/qdisc.h>
15 #include <netlink/cli/class.h>
16 #include <linux/pkt_sched.h>
18 static struct nl_sock *sock;
19 static struct nl_cache *qdisc_cache, *class_cache;
25 static void print_qdisc(
struct nl_object *,
void *);
26 static void print_tc_childs(
struct rtnl_tc *,
void *);
28 static void print_usage(
void)
31 "Usage: nl-tctree-list [OPTION]...\n"
34 " -f, --format=TYPE Output format { brief | details | stats }\n"
35 " -h, --help Show this help\n"
36 " -v, --version Show versioning information\n"
41 static void print_class(
struct nl_object *obj,
void *arg)
43 struct rtnl_qdisc *leaf;
44 struct rtnl_class *
class = (struct rtnl_class *) obj;
45 struct nl_cache *cls_cache;
53 print_qdisc((
struct nl_object *) leaf, arg + 2);
55 print_tc_childs(
TC_CAST(
class), arg + 2);
65 static void print_tc_childs(
struct rtnl_tc *tc,
void *arg)
67 struct rtnl_class *filter;
69 filter = nl_cli_class_alloc();
76 rtnl_class_put(filter);
79 static void print_qdisc(
struct nl_object *obj,
void *arg)
81 struct rtnl_qdisc *qdisc = (
struct rtnl_qdisc *) obj;
82 struct nl_cache *cls_cache;
88 print_tc_childs(
TC_CAST(qdisc), arg + 2);
98 static void print_link(
struct nl_object *obj,
void *arg)
101 struct rtnl_qdisc *qdisc;
112 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
113 rtnl_qdisc_put(qdisc);
118 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
119 rtnl_qdisc_put(qdisc);
124 print_qdisc((
struct nl_object *) qdisc, (
void *) 2);
125 rtnl_qdisc_put(qdisc);
131 int main(
int argc,
char *argv[])
133 struct nl_cache *link_cache;
135 sock = nl_cli_alloc_socket();
136 nl_cli_connect(sock, NETLINK_ROUTE);
137 link_cache = nl_cli_link_alloc_cache(sock);
138 qdisc_cache = nl_cli_qdisc_alloc_cache(sock);
140 params.
dp_fd = stdout;
144 static struct option long_opts[] = {
145 {
"format", 1, 0,
'f' },
146 {
"help", 0, 0,
'h' },
147 {
"version", 0, 0,
'v' },
151 c = getopt_long(argc, argv,
"f:hv", long_opts, &optidx);
156 case 'f': params.
dp_type = nl_cli_parse_dumptype(optarg);
break;
157 case 'h': print_usage();
break;
158 case 'v': nl_cli_print_version();
break;