This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / nl-qdisc-dump.c
1 /*
2  * src/nl-qdisc-dump.c     Dump qdisc attributes
3  *
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
7  *      of the License.
8  *
9  * Copyright (c) 2003-2006 Thomas Graf <tgraf@suug.ch>
10  */
11
12 #include "utils.h"
13
14 static void print_usage(void)
15 {
16         printf(
17 "Usage: nl-qdisc-dump <mode>\n"
18 "  mode := { brief | detailed | stats | xml }\n");
19         exit(1);
20 }
21
22 int main(int argc, char *argv[])
23 {
24         struct nl_handle *nlh;
25         struct nl_cache *link_cache, *qdisc_cache;
26         struct rtnl_qdisc *qdisc;
27         struct nl_dump_params params = {
28                 .dp_fd = stdout,
29                 .dp_type = NL_DUMP_BRIEF
30         };
31         int err = 1;
32
33         if (nltool_init(argc, argv) < 0)
34                 return -1;
35
36         if (argc < 2 || !strcmp(argv[1], "-h"))
37                 print_usage();
38
39         params.dp_type = nltool_parse_dumptype(argv[1]);
40         if (params.dp_type < 0)
41                 return -1;
42
43         nlh = nl_handle_alloc_nondefault(nltool_cbset);
44         if (!nlh)
45                 return -1;
46
47         qdisc = rtnl_qdisc_alloc();
48         if (!qdisc)
49                 goto errout_no_put;
50
51         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
52                 goto errout;
53
54         link_cache = nltool_alloc_link_cache(nlh);
55         if (!link_cache)
56                 goto errout;
57
58         qdisc_cache = nltool_alloc_qdisc_cache(nlh);
59         if (!qdisc_cache)
60                 goto errout_link_cache;
61
62         nl_cache_dump_filter(qdisc_cache, &params, (struct nl_object *) qdisc);
63         nl_cache_free(qdisc_cache);
64         err = 0;
65
66 errout_link_cache:
67         nl_cache_free(link_cache);
68 errout:
69         rtnl_qdisc_put(qdisc);
70 errout_no_put:
71         nl_close(nlh);
72         nl_handle_destroy(nlh);
73         return err;
74 }