aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/rtm_map.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/rtm_map.c')
-rw-r--r--networking/libiproute/rtm_map.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/networking/libiproute/rtm_map.c b/networking/libiproute/rtm_map.c
index 7fad0ecc8..593017bf1 100644
--- a/networking/libiproute/rtm_map.c
+++ b/networking/libiproute/rtm_map.c
@@ -51,31 +51,40 @@ const char *rtnl_rtntype_n2a(int id, char *buf, int len)
51 51
52int rtnl_rtntype_a2n(int *id, char *arg) 52int rtnl_rtntype_a2n(int *id, char *arg)
53{ 53{
54 static const char * const keywords[] = {
55 "local", "nat", "broadcast", "brd", "anycast",
56 "multicast", "prohibit", "unreachable", "blackhole",
57 "xresolve", "unicast", "throw", NULL
58 };
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
62 };
63 const smalluint key = index_in_substr_array(keywords, arg) + 1;
54 char *end; 64 char *end;
55 unsigned long res; 65 unsigned long res;
56 66
57 if (strcmp(arg, "local") == 0) 67 if (key == ARG_local)
58 res = RTN_LOCAL; 68 res = RTN_LOCAL;
59 else if (strcmp(arg, "nat") == 0) 69 else if (key == ARG_nat)
60 res = RTN_NAT; 70 res = RTN_NAT;
61 else if (matches(arg, "broadcast") == 0 || 71 else if (key == ARG_broadcast || key == ARG_brd)
62 strcmp(arg, "brd") == 0)
63 res = RTN_BROADCAST; 72 res = RTN_BROADCAST;
64 else if (matches(arg, "anycast") == 0) 73 else if (key == ARG_anycast)
65 res = RTN_ANYCAST; 74 res = RTN_ANYCAST;
66 else if (matches(arg, "multicast") == 0) 75 else if (key == ARG_multicast)
67 res = RTN_MULTICAST; 76 res = RTN_MULTICAST;
68 else if (matches(arg, "prohibit") == 0) 77 else if (key == ARG_prohibit)
69 res = RTN_PROHIBIT; 78 res = RTN_PROHIBIT;
70 else if (matches(arg, "unreachable") == 0) 79 else if (key == ARG_unreachable)
71 res = RTN_UNREACHABLE; 80 res = RTN_UNREACHABLE;
72 else if (matches(arg, "blackhole") == 0) 81 else if (key == ARG_blackhole)
73 res = RTN_BLACKHOLE; 82 res = RTN_BLACKHOLE;
74 else if (matches(arg, "xresolve") == 0) 83 else if (key == ARG_xresolve)
75 res = RTN_XRESOLVE; 84 res = RTN_XRESOLVE;
76 else if (matches(arg, "unicast") == 0) 85 else if (key == ARG_unicast)
77 res = RTN_UNICAST; 86 res = RTN_UNICAST;
78 else if (strcmp(arg, "throw") == 0) 87 else if (key == ARG_throw)
79 res = RTN_THROW; 88 res = RTN_THROW;
80 else { 89 else {
81 res = strtoul(arg, &end, 0); 90 res = strtoul(arg, &end, 0);