This commit was generated by cvs2svn to compensate for changes in r786,
[libnl.git] / src / f_link.c
1 /*
2  * src/f_link.c         Link 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 #include <linux/if.h>
13
14 static void get_filter(struct rtnl_link *l, int ac, char **av, int idx,
15                        struct nl_cache *cache)
16 {
17         while (ac > idx) {
18                 if (!strcasecmp(av[idx], "dev")) {
19                         if (ac > ++idx) {
20                                 int ifindex = rtnl_link_name2i(cache, av[idx++]);
21                                 if (ifindex == RTNL_LINK_NOT_FOUND)
22                                         goto err_notfound;
23                                 rtnl_link_set_ifindex(l, ifindex);
24                         }
25                 } else if (!strcasecmp(av[idx], "mtu")) {
26                         if (ac > ++idx)
27                                 rtnl_link_set_mtu(l, strtoul(av[idx++], NULL, 0));
28                 } else if (!strcasecmp(av[idx], "txqlen")) {
29                         if (ac > ++idx)
30                                 rtnl_link_set_txqlen(l, strtoul(av[idx++], NULL, 0));
31                 } else if (!strcasecmp(av[idx], "weight")) {
32                         if (ac > ++idx)
33                                 rtnl_link_set_weight(l, strtoul(av[idx++], NULL, 0));
34                 } else if (!strcasecmp(av[idx], "link")) {
35                         if (ac > ++idx) {
36                                 int ifindex = rtnl_link_name2i(cache, av[idx++]);
37                                 if (ifindex == RTNL_LINK_NOT_FOUND)
38                                         goto err_notfound;
39                                 rtnl_link_set_link(l, ifindex);
40                         }
41                 } else if (!strcasecmp(av[idx], "master")) {
42                         if (ac > ++idx) {
43                                 int ifindex = rtnl_link_name2i(cache, av[idx++]);
44                                 if (ifindex == RTNL_LINK_NOT_FOUND)
45                                         goto err_notfound;
46                                 rtnl_link_set_master(l, ifindex);
47                         }
48                 } else if (!strcasecmp(av[idx], "qdisc")) {
49                         if (ac > ++idx)
50                                 rtnl_link_set_qdisc(l, av[idx++]);
51                 } else if (!strcasecmp(av[idx], "name")) {
52                         if (ac > ++idx)
53                                 rtnl_link_set_name(l, av[idx++]);
54                 } else if (!strcasecmp(av[idx], "addr")) {
55                         if (ac > ++idx) {
56                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
57                                 if (a == NULL)
58                                         goto err;
59                                 rtnl_link_set_addr(l, a);
60                                 nl_addr_put(a);
61                         }
62                 } else if (!strcasecmp(av[idx], "broadcast")) {
63                         if (ac > ++idx) {
64                                 struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC);
65                                 if (a == NULL)
66                                         goto err;
67                                 rtnl_link_set_broadcast(l, a);
68                                 nl_addr_put(a);
69                         }
70                 }
71 #define MFLAG(STR, FLAG) \
72         else if (!strcasecmp(av[idx], STR)) { \
73                 rtnl_link_set_flags(l, FLAG); idx++; }
74 #define MNOFLAG(STR, FLAG) \
75         else if (!strcasecmp(av[idx], STR)) { \
76                 rtnl_link_unset_flags(l, FLAG); idx++; }
77
78                 MFLAG("up", IFF_UP)
79                 MNOFLAG("down", IFF_UP)
80                 MFLAG("noarp", IFF_NOARP)
81                 MNOFLAG("arp", IFF_NOARP)
82                 MFLAG("promisc", IFF_PROMISC)
83                 MNOFLAG("nopromisc", IFF_PROMISC)
84                 MFLAG("dynamic", IFF_DYNAMIC)
85                 MNOFLAG("nodynamic", IFF_DYNAMIC)
86                 MFLAG("multicast", IFF_MULTICAST)
87                 MNOFLAG("nomulticast", IFF_MULTICAST)
88                 MFLAG("allmulticast", IFF_ALLMULTI)
89                 MNOFLAG("noallmulticast", IFF_ALLMULTI)
90 #undef MFLAG
91 #undef MNOFLAG
92                 else {
93                         fprintf(stderr, "What is '%s'?\n", av[idx]);
94                         exit(1);
95                 }
96         }
97
98         return;
99
100 err_notfound:
101         fprintf(stderr, "Unknown link %s\n", av[idx-1]);
102         exit(1);
103 err:
104         fprintf(stderr, "%s\n", nl_geterror());
105         exit(1);
106 }