X-Git-Url: http://git.onelab.eu/?p=libnl.git;a=blobdiff_plain;f=src%2Ff_link.c;fp=src%2Ff_link.c;h=3c1cb935978e3a2fa26da7cae4dd33428ab24f64;hp=0000000000000000000000000000000000000000;hb=4cee2ecb3b8afa0637e6f5fe4c57985a4bc740ff;hpb=2df2fbe518d5a221ce6e3ee88a3fb23fb1b94b27 diff --git a/src/f_link.c b/src/f_link.c new file mode 100644 index 0000000..3c1cb93 --- /dev/null +++ b/src/f_link.c @@ -0,0 +1,106 @@ +/* + * src/f_link.c Link Filter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation version 2.1 + * of the License. + * + * Copyright (c) 2003-2006 Thomas Graf + */ + +#include + +static void get_filter(struct rtnl_link *l, int ac, char **av, int idx, + struct nl_cache *cache) +{ + while (ac > idx) { + if (!strcasecmp(av[idx], "dev")) { + if (ac > ++idx) { + int ifindex = rtnl_link_name2i(cache, av[idx++]); + if (ifindex == RTNL_LINK_NOT_FOUND) + goto err_notfound; + rtnl_link_set_ifindex(l, ifindex); + } + } else if (!strcasecmp(av[idx], "mtu")) { + if (ac > ++idx) + rtnl_link_set_mtu(l, strtoul(av[idx++], NULL, 0)); + } else if (!strcasecmp(av[idx], "txqlen")) { + if (ac > ++idx) + rtnl_link_set_txqlen(l, strtoul(av[idx++], NULL, 0)); + } else if (!strcasecmp(av[idx], "weight")) { + if (ac > ++idx) + rtnl_link_set_weight(l, strtoul(av[idx++], NULL, 0)); + } else if (!strcasecmp(av[idx], "link")) { + if (ac > ++idx) { + int ifindex = rtnl_link_name2i(cache, av[idx++]); + if (ifindex == RTNL_LINK_NOT_FOUND) + goto err_notfound; + rtnl_link_set_link(l, ifindex); + } + } else if (!strcasecmp(av[idx], "master")) { + if (ac > ++idx) { + int ifindex = rtnl_link_name2i(cache, av[idx++]); + if (ifindex == RTNL_LINK_NOT_FOUND) + goto err_notfound; + rtnl_link_set_master(l, ifindex); + } + } else if (!strcasecmp(av[idx], "qdisc")) { + if (ac > ++idx) + rtnl_link_set_qdisc(l, av[idx++]); + } else if (!strcasecmp(av[idx], "name")) { + if (ac > ++idx) + rtnl_link_set_name(l, av[idx++]); + } else if (!strcasecmp(av[idx], "addr")) { + if (ac > ++idx) { + struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC); + if (a == NULL) + goto err; + rtnl_link_set_addr(l, a); + nl_addr_put(a); + } + } else if (!strcasecmp(av[idx], "broadcast")) { + if (ac > ++idx) { + struct nl_addr *a = nl_addr_parse(av[idx++], AF_UNSPEC); + if (a == NULL) + goto err; + rtnl_link_set_broadcast(l, a); + nl_addr_put(a); + } + } +#define MFLAG(STR, FLAG) \ + else if (!strcasecmp(av[idx], STR)) { \ + rtnl_link_set_flags(l, FLAG); idx++; } +#define MNOFLAG(STR, FLAG) \ + else if (!strcasecmp(av[idx], STR)) { \ + rtnl_link_unset_flags(l, FLAG); idx++; } + + MFLAG("up", IFF_UP) + MNOFLAG("down", IFF_UP) + MFLAG("noarp", IFF_NOARP) + MNOFLAG("arp", IFF_NOARP) + MFLAG("promisc", IFF_PROMISC) + MNOFLAG("nopromisc", IFF_PROMISC) + MFLAG("dynamic", IFF_DYNAMIC) + MNOFLAG("nodynamic", IFF_DYNAMIC) + MFLAG("multicast", IFF_MULTICAST) + MNOFLAG("nomulticast", IFF_MULTICAST) + MFLAG("allmulticast", IFF_ALLMULTI) + MNOFLAG("noallmulticast", IFF_ALLMULTI) +#undef MFLAG +#undef MNOFLAG + else { + fprintf(stderr, "What is '%s'?\n", av[idx]); + exit(1); + } + } + + return; + +err_notfound: + fprintf(stderr, "Unknown link %s\n", av[idx-1]); + exit(1); +err: + fprintf(stderr, "%s\n", nl_geterror()); + exit(1); +}