This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / nl-rule-dump.c
1 /*
2  * src/nl-rule-dump.c     Dump rule 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-rule-dump <mode> [<filter>]\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, *rule_cache;
26         struct rtnl_rule *rule;
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         nlh = nl_handle_alloc_nondefault(nltool_cbset);
40         if (!nlh)
41                 return -1;
42
43         rule = rtnl_rule_alloc();
44         if (!rule)
45                 goto errout;
46
47         if (nltool_connect(nlh, NETLINK_ROUTE) < 0)
48                 goto errout_free;
49
50         link_cache = nltool_alloc_link_cache(nlh);
51         if (!link_cache)
52                 goto errout_close;
53
54         rule_cache = nltool_alloc_rule_cache(nlh);
55         if (!rule_cache)
56                 goto errout_link_cache;
57
58         params.dp_type = nltool_parse_dumptype(argv[1]);
59         if (params.dp_type < 0)
60                 goto errout_rule_cache;
61
62         //get_filter(route, argc, argv, 2, route_cache);
63
64         nl_cache_dump_filter(rule_cache, &params, (struct nl_object *) rule);
65
66         err = 0;
67
68 errout_rule_cache:
69         nl_cache_free(rule_cache);
70 errout_link_cache:
71         nl_cache_free(link_cache);
72 errout_close:
73         nl_close(nlh);
74 errout_free:
75         nl_object_put((struct nl_object *) rule);
76 errout:
77         return err;
78 }