resetting manifest requested domain to floor
[platform/upstream/libnl1.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], "dst")) {
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_dst(r, a);
30                                 nl_addr_put(a);
31                         }
32                 } else if (!strcasecmp(av[idx], "via")) {
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_gateway(r, a);
38                                 nl_addr_put(a);
39                         }
40                 } else if (!strcasecmp(av[idx], "from")) {
41                         if (ac > ++idx) {
42                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
43                                 if (!a)
44                                         goto err;
45                                 rtnl_route_set_src(r, a);
46                                 nl_addr_put(a);
47                         }
48                 } else if (!strcasecmp(av[idx], "tos")) {
49                         if (ac > ++idx)
50                                 rtnl_route_set_tos(r, strtoul(av[idx++], NULL, 0));
51                 } else if (!strcasecmp(av[idx], "prio")) {
52                         if (ac > ++idx)
53                                 rtnl_route_set_prio(r, strtoul(av[idx++], NULL, 0));
54                 } else if (!strcasecmp(av[idx], "scope")) {
55                         if (ac > ++idx)
56                                 rtnl_route_set_scope(r, rtnl_str2scope(av[idx++]));
57                 } else if (!strcasecmp(av[idx], "dev")) {
58                         if (ac > ++idx) {
59                                 int ifindex = rtnl_link_name2i(link_cache, av[idx++]);
60                                 if (ifindex == RTNL_LINK_NOT_FOUND)
61                                         goto err_notfound;
62                                 rtnl_route_set_oif(r, ifindex);
63                         }
64                 } else if (!strcasecmp(av[idx], "table")) {
65                         if (ac > ++idx)
66                                 rtnl_route_set_table(r, strtoul(av[idx++], NULL, 0));
67                 } else {
68                         fprintf(stderr, "What is '%s'?\n", av[idx]);
69                         exit(1);
70                 }
71         }
72
73         return;
74
75 err_notfound:
76         fprintf(stderr, "Unable to find device \"%s\"\n", av[idx-1]);
77         exit(1);
78 err:
79         fprintf(stderr, "%s\n", nl_geterror());
80         exit(1);
81 }