This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / f_route.c
1 /*
2  * src/f_route.c        Routes Filter
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 static void get_filter(struct rtnl_route *r, int ac, char **av, int idx,
13                        struct nl_cache *cache, struct nl_cache *link_cache)
14 {
15         while (ac > idx) {
16                 if (!strcasecmp(av[idx], "src")) {
17                         if (ac > ++idx) {
18                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
19                                 if (!a)
20                                         goto err;
21                                 rtnl_route_set_pref_src(r, a);
22                                 nl_addr_put(a);
23                         }
24                 } else if (!strcasecmp(av[idx], "via")) {
25                         if (ac > ++idx) {
26                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
27                                 if (!a)
28                                         goto err;
29                                 rtnl_route_set_gateway(r, a);
30                                 nl_addr_put(a);
31                         }
32                 } else if (!strcasecmp(av[idx], "from")) {
33                         if (ac > ++idx) {
34                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
35                                 if (!a)
36                                         goto err;
37                                 rtnl_route_set_src(r, a);
38                                 nl_addr_put(a);
39                         }
40                 } else if (!strcasecmp(av[idx], "tos")) {
41                         if (ac > ++idx)
42                                 rtnl_route_set_tos(r, strtoul(av[idx++], NULL, 0));
43                 } else if (!strcasecmp(av[idx], "prio")) {
44                         if (ac > ++idx)
45                                 rtnl_route_set_prio(r, strtoul(av[idx++], NULL, 0));
46                 } else if (!strcasecmp(av[idx], "scope")) {
47                         if (ac > ++idx)
48                                 rtnl_route_set_prio(r, rtnl_str2scope(av[idx++]));
49                 } else if (!strcasecmp(av[idx], "dev")) {
50                         if (ac > ++idx) {
51                                 int ifindex = rtnl_link_name2i(link_cache, av[idx++]);
52                                 if (ifindex == RTNL_LINK_NOT_FOUND)
53                                         goto err_notfound;
54                                 rtnl_route_set_oif(r, ifindex);
55                         }
56                 } else if (!strcasecmp(av[idx], "table")) {
57                         if (ac > ++idx)
58                                 rtnl_route_set_table(r, strtoul(av[idx++], NULL, 0));
59                 } else {
60                         fprintf(stderr, "What is '%s'?\n", av[idx]);
61                         exit(1);
62                 }
63         }
64
65         return;
66
67 err_notfound:
68         fprintf(stderr, "Unable to find device \"%s\"\n", av[idx-1]);
69         exit(1);
70 err:
71         fprintf(stderr, "%s\n", nl_geterror());
72         exit(1);
73 }