diff options
author | Thomas Graf <tgraf@suug.ch> | 2007-09-14 23:28:01 (GMT) |
---|---|---|
committer | Thomas Graf <tgraf@suug.ch> | 2007-09-14 23:28:01 (GMT) |
commit | 44d362409d5469aed47d19e7908d19bd194493a4 (patch) | |
tree | 5d1e739a4566f3af796273e5c3f78ca53d234df6 /src/f_link.c | |
download | libnl-44d362409d5469aed47d19e7908d19bd194493a4.zip libnl-44d362409d5469aed47d19e7908d19bd194493a4.tar.gz libnl-44d362409d5469aed47d19e7908d19bd194493a4.tar.bz2 |
Initial import
Diffstat (limited to 'src/f_link.c')
-rw-r--r-- | src/f_link.c | 106 |
1 files changed, 106 insertions, 0 deletions
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 <tgraf@suug.ch> + */ + +#include <linux/if.h> + +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); +} |