1 /* vi: set sw=4 ts=4: */
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version
8 * 2 of the License, or (at your option) any later version.
10 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
18 const char *rtnl_rtntype_n2a(int id, char *buf, int len)
46 snprintf(buf, len, "%d", id);
52 int rtnl_rtntype_a2n(int *id, char *arg)
54 static const char * const keywords[] = {
55 "local", "nat", "broadcast", "brd", "anycast",
56 "multicast", "prohibit", "unreachable", "blackhole",
57 "xresolve", "unicast", "throw", NULL
59 enum { ARG_local = 1, ARG_nat, ARG_broadcast, ARG_brd, ARG_anycast,
60 ARG_multicast, ARG_prohibit, ARG_unreachable, ARG_blackhole,
61 ARG_xresolve, ARG_unicast, ARG_throw
63 const smalluint key = index_in_substr_array(keywords, arg) + 1;
69 else if (key == ARG_nat)
71 else if (key == ARG_broadcast || key == ARG_brd)
73 else if (key == ARG_anycast)
75 else if (key == ARG_multicast)
77 else if (key == ARG_prohibit)
79 else if (key == ARG_unreachable)
80 res = RTN_UNREACHABLE;
81 else if (key == ARG_blackhole)
83 else if (key == ARG_xresolve)
85 else if (key == ARG_unicast)
87 else if (key == ARG_throw)
90 res = strtoul(arg, &end, 0);
91 if (!end || end == arg || *end || res > 255)
98 int get_rt_realms(uint32_t *realms, char *arg)
101 char *p = strchr(arg, '/');
106 if (rtnl_rtrealm_a2n(realms, arg)) {
114 if (*arg && rtnl_rtrealm_a2n(&realm, arg))