This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / f_neigh.c
1 /*
2  * src/f_neigh.c        Neighbour 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_neigh *n, int ac, char **av, int idx,
13                        struct nl_cache *cache)
14 {
15         struct nl_cache *lc = nl_cache_mngt_require("route/link");
16         
17         while (ac > idx) {
18                 if (!strcasecmp(av[idx], "dev")) {
19                         if (ac > ++idx) {
20                                 int ifindex = rtnl_link_name2i(lc, av[idx++]);
21                                 if (ifindex == RTNL_LINK_NOT_FOUND)
22                                         goto err_notfound;
23                                 rtnl_neigh_set_ifindex(n, ifindex);
24                         }
25                 } else if (!strcasecmp(av[idx], "dst")) {
26                         if (ac > ++idx) {
27                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
28                                 if (a == NULL)
29                                         goto err;
30                                 rtnl_neigh_set_dst(n, a);
31                                 nl_addr_put(a);
32                         }
33                 } else if (!strcasecmp(av[idx], "lladdr")) {
34                         if (ac > ++idx) {
35                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
36                                 if (a == NULL)
37                                         goto err;
38                                 rtnl_neigh_set_lladdr(n, a);
39                                 nl_addr_put(a);
40                         }
41                 }
42         }
43
44         return;
45 err_notfound:
46         fprintf(stderr, "Unable to find interface %s\n", av[idx-1]);
47         exit(1);
48 err:
49         fprintf(stderr, "%s\n", nl_geterror());
50         exit(1);
51 }