aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-07-24 15:54:42 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-07-24 15:54:42 +0000
commit990d0f63eeb502c8762076e5c5499196e09cba55 (patch)
tree30a2091a8159b1694d65f9952e2aba2667d7dc11 /networking/libiproute
parentbcb66ec22e82f6b1ab93f3aec917269393a5b464 (diff)
downloadbusybox-w32-990d0f63eeb502c8762076e5c5499196e09cba55.tar.gz
busybox-w32-990d0f63eeb502c8762076e5c5499196e09cba55.tar.bz2
busybox-w32-990d0f63eeb502c8762076e5c5499196e09cba55.zip
Replace index_in_[sub]str_array with index_in_[sub]strings,
which scans thru "abc\0def\0123\0\0" type strings. Saves 250 bytes. text data bss dec hex filename 781266 1328 11844 794438 c1f46 busybox_old 781010 1328 11844 794182 c1e46 busybox_unstripped
Diffstat (limited to 'networking/libiproute')
-rw-r--r--networking/libiproute/ip_parse_common_args.c10
-rw-r--r--networking/libiproute/ipaddress.c30
-rw-r--r--networking/libiproute/iplink.c20
-rw-r--r--networking/libiproute/iproute.c93
-rw-r--r--networking/libiproute/iprule.c24
-rw-r--r--networking/libiproute/iptunnel.c41
-rw-r--r--networking/libiproute/rtm_map.c14
7 files changed, 114 insertions, 118 deletions
diff --git a/networking/libiproute/ip_parse_common_args.c b/networking/libiproute/ip_parse_common_args.c
index 2d597ea3a..0e429a06f 100644
--- a/networking/libiproute/ip_parse_common_args.c
+++ b/networking/libiproute/ip_parse_common_args.c
@@ -26,9 +26,9 @@ void ip_parse_common_args(int *argcp, char ***argvp)
26{ 26{
27 int argc = *argcp; 27 int argc = *argcp;
28 char **argv = *argvp; 28 char **argv = *argvp;
29 static const char * const ip_common_commands[] = 29 static const char ip_common_commands[] =
30 {"-family", "inet", "inet6", "link", 30 "-family\0""inet\0""inet6\0""link\0"
31 "-4", "-6", "-0", "-oneline", 0}; 31 "-4\0""-6\0""-0\0""-oneline\0";
32 enum { 32 enum {
33 ARG_family = 1, 33 ARG_family = 1,
34 ARG_inet, 34 ARG_inet,
@@ -53,13 +53,13 @@ void ip_parse_common_args(int *argcp, char ***argvp)
53 break; 53 break;
54 if (opt[1] == '-') 54 if (opt[1] == '-')
55 opt++; 55 opt++;
56 arg = index_in_str_array(ip_common_commands, opt) + 1; 56 arg = index_in_strings(ip_common_commands, opt) + 1;
57 if (arg == ARG_family) { 57 if (arg == ARG_family) {
58 argc--; 58 argc--;
59 argv++; 59 argv++;
60 if (!argv[1]) 60 if (!argv[1])
61 bb_show_usage(); 61 bb_show_usage();
62 arg = index_in_str_array(ip_common_commands, argv[1]) + 1; 62 arg = index_in_strings(ip_common_commands, argv[1]) + 1;
63 if (arg == ARG_inet) 63 if (arg == ARG_inet)
64 preferred_family = AF_INET; 64 preferred_family = AF_INET;
65 else if (arg == ARG_inet6) 65 else if (arg == ARG_inet6)
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index 955a9d933..8874fdb0a 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -412,7 +412,7 @@ static void ipaddr_reset_filter(int _oneline)
412/* Return value becomes exitcode. It's okay to not return at all */ 412/* Return value becomes exitcode. It's okay to not return at all */
413int ipaddr_list_or_flush(int argc, char **argv, int flush) 413int ipaddr_list_or_flush(int argc, char **argv, int flush)
414{ 414{
415 static const char *const option[] = { "to", "scope", "up", "label", "dev", 0 }; 415 static const char option[] = "to\0""scope\0""up\0""label\0""dev\0";
416 416
417 struct nlmsg_list *linfo = NULL; 417 struct nlmsg_list *linfo = NULL;
418 struct nlmsg_list *ainfo = NULL; 418 struct nlmsg_list *ainfo = NULL;
@@ -437,7 +437,7 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
437 } 437 }
438 438
439 while (argc > 0) { 439 while (argc > 0) {
440 const int option_num = index_in_str_array(option, *argv); 440 const int option_num = index_in_strings(option, *argv);
441 switch (option_num) { 441 switch (option_num) {
442 case 0: /* to */ 442 case 0: /* to */
443 NEXT_ARG(); 443 NEXT_ARG();
@@ -599,18 +599,17 @@ static int default_scope(inet_prefix *lcl)
599/* Return value becomes exitcode. It's okay to not return at all */ 599/* Return value becomes exitcode. It's okay to not return at all */
600static int ipaddr_modify(int cmd, int argc, char **argv) 600static int ipaddr_modify(int cmd, int argc, char **argv)
601{ 601{
602 static const char *const option[] = { 602 static const char option[] =
603 "peer", "remote", "broadcast", "brd", 603 "peer\0""remote\0""broadcast\0""brd\0"
604 "anycast", "scope", "dev", "label", "local", 0 604 "anycast\0""scope\0""dev\0""label\0""local\0";
605 };
606 struct rtnl_handle rth; 605 struct rtnl_handle rth;
607 struct { 606 struct {
608 struct nlmsghdr n; 607 struct nlmsghdr n;
609 struct ifaddrmsg ifa; 608 struct ifaddrmsg ifa;
610 char buf[256]; 609 char buf[256];
611 } req; 610 } req;
612 char *d = NULL; 611 char *d = NULL;
613 char *l = NULL; 612 char *l = NULL;
614 inet_prefix lcl; 613 inet_prefix lcl;
615 inet_prefix peer; 614 inet_prefix peer;
616 int local_len = 0; 615 int local_len = 0;
@@ -627,7 +626,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
627 req.ifa.ifa_family = preferred_family; 626 req.ifa.ifa_family = preferred_family;
628 627
629 while (argc > 0) { 628 while (argc > 0) {
630 const int option_num = index_in_str_array(option, *argv); 629 const int option_num = index_in_strings(option, *argv);
631 switch (option_num) { 630 switch (option_num) {
632 case 0: /* peer */ 631 case 0: /* peer */
633 case 1: /* remote */ 632 case 1: /* remote */
@@ -769,14 +768,13 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
769/* Return value becomes exitcode. It's okay to not return at all */ 768/* Return value becomes exitcode. It's okay to not return at all */
770int do_ipaddr(int argc, char **argv) 769int do_ipaddr(int argc, char **argv)
771{ 770{
772 static const char *const commands[] = { 771 static const char commands[] =
773 "add", "delete", "list", "show", "lst", "flush", 0 772 "add\0""delete\0""list\0""show\0""lst\0""flush\0";
774 };
775 773
776 int command_num = 2; /* default command is list */ 774 int command_num = 2; /* default command is list */
777 775
778 if (*argv) { 776 if (*argv) {
779 command_num = index_in_substr_array(commands, *argv); 777 command_num = index_in_substrings(commands, *argv);
780 } 778 }
781 if (command_num < 0 || command_num > 5) 779 if (command_num < 0 || command_num > 5)
782 bb_error_msg_and_die("unknown command %s", *argv); 780 bb_error_msg_and_die("unknown command %s", *argv);
diff --git a/networking/libiproute/iplink.c b/networking/libiproute/iplink.c
index 3d3ea2a23..69ce84e49 100644
--- a/networking/libiproute/iplink.c
+++ b/networking/libiproute/iplink.c
@@ -171,16 +171,15 @@ static int do_set(int argc, char **argv)
171 struct ifreq ifr0, ifr1; 171 struct ifreq ifr0, ifr1;
172 char *newname = NULL; 172 char *newname = NULL;
173 int htype, halen; 173 int htype, halen;
174 static const char * const keywords[] = { 174 static const char keywords[] =
175 "up", "down", "name", "mtu", "multicast", "arp", "addr", "dev", 175 "up\0""down\0""name\0""mtu\0""multicast\0""arp\0""addr\0""dev\0"
176 "on", "off", NULL 176 "on\0""off\0";
177 };
178 enum { ARG_up = 1, ARG_down, ARG_name, ARG_mtu, ARG_multicast, ARG_arp, 177 enum { ARG_up = 1, ARG_down, ARG_name, ARG_mtu, ARG_multicast, ARG_arp,
179 ARG_addr, ARG_dev, PARM_on, PARM_off }; 178 ARG_addr, ARG_dev, PARM_on, PARM_off };
180 smalluint key; 179 smalluint key;
181 180
182 while (argc > 0) { 181 while (argc > 0) {
183 key = index_in_str_array(keywords, *argv) + 1; 182 key = index_in_strings(keywords, *argv) + 1;
184 if (key == ARG_up) { 183 if (key == ARG_up) {
185 mask |= IFF_UP; 184 mask |= IFF_UP;
186 flags |= IFF_UP; 185 flags |= IFF_UP;
@@ -199,7 +198,7 @@ static int do_set(int argc, char **argv)
199 } else if (key == ARG_multicast) { 198 } else if (key == ARG_multicast) {
200 NEXT_ARG(); 199 NEXT_ARG();
201 mask |= IFF_MULTICAST; 200 mask |= IFF_MULTICAST;
202 key = index_in_str_array(keywords, *argv) + 1; 201 key = index_in_strings(keywords, *argv) + 1;
203 if (key == PARM_on) { 202 if (key == PARM_on) {
204 flags |= IFF_MULTICAST; 203 flags |= IFF_MULTICAST;
205 } else if (key == PARM_off) { 204 } else if (key == PARM_off) {
@@ -209,7 +208,7 @@ static int do_set(int argc, char **argv)
209 } else if (key == ARG_arp) { 208 } else if (key == ARG_arp) {
210 NEXT_ARG(); 209 NEXT_ARG();
211 mask |= IFF_NOARP; 210 mask |= IFF_NOARP;
212 key = index_in_str_array(keywords, *argv) + 1; 211 key = index_in_strings(keywords, *argv) + 1;
213 if (key == PARM_on) { 212 if (key == PARM_on) {
214 flags &= ~IFF_NOARP; 213 flags &= ~IFF_NOARP;
215 } else if (key == PARM_off) { 214 } else if (key == PARM_off) {
@@ -276,13 +275,12 @@ static int ipaddr_list_link(int argc, char **argv)
276/* Return value becomes exitcode. It's okay to not return at all */ 275/* Return value becomes exitcode. It's okay to not return at all */
277int do_iplink(int argc, char **argv) 276int do_iplink(int argc, char **argv)
278{ 277{
279 static const char * const keywords[] = { 278 static const char keywords[] =
280 "set", "show", "lst", "list", NULL 279 "set\0""show\0""lst\0""list\0";
281 };
282 smalluint key; 280 smalluint key;
283 if (argc <= 0) 281 if (argc <= 0)
284 return ipaddr_list_link(0, NULL); 282 return ipaddr_list_link(0, NULL);
285 key = index_in_substr_array(keywords, *argv) + 1; 283 key = index_in_substrings(keywords, *argv) + 1;
286 if (key == 0) 284 if (key == 0)
287 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); 285 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
288 argc--; argv++; 286 argc--; argv++;
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c
index 75e52939c..0d171c785 100644
--- a/networking/libiproute/iproute.c
+++ b/networking/libiproute/iproute.c
@@ -294,6 +294,25 @@ static int print_route(struct sockaddr_nl *who ATTRIBUTE_UNUSED,
294/* Return value becomes exitcode. It's okay to not return at all */ 294/* Return value becomes exitcode. It's okay to not return at all */
295static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) 295static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
296{ 296{
297 static const char keywords[] =
298 "src\0""via\0""mtu\0""lock\0""protocol\0"USE_FEATURE_IP_RULE("table\0")
299 "dev\0""oif\0""to\0";
300 enum {
301 ARG_src,
302 ARG_via,
303 ARG_mtu, PARM_lock,
304 ARG_protocol,
305USE_FEATURE_IP_RULE(ARG_table,)
306 ARG_dev,
307 ARG_oif,
308 ARG_to
309 };
310 enum {
311 gw_ok = 1 << 0,
312 dst_ok = 1 << 1,
313 proto_ok = 1 << 2,
314 type_ok = 1 << 3
315 };
297 struct rtnl_handle rth; 316 struct rtnl_handle rth;
298 struct { 317 struct {
299 struct nlmsghdr n; 318 struct nlmsghdr n;
@@ -304,22 +323,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv)
304 struct rtattr * mxrta = (void*)mxbuf; 323 struct rtattr * mxrta = (void*)mxbuf;
305 unsigned mxlock = 0; 324 unsigned mxlock = 0;
306 char *d = NULL; 325 char *d = NULL;
307 enum { gw_ok = 1<<0, dst_ok = 1<<1, proto_ok = 1<<2, type_ok = 1<<3};
308 smalluint ok = 0; 326 smalluint ok = 0;
309 static const char * const keywords[] = {
310 "src", "via", "mtu", "lock", "protocol", USE_FEATURE_IP_RULE("table",)
311 "dev", "oif", "to", NULL
312 };
313 enum {
314 ARG_src,
315 ARG_via,
316 ARG_mtu, PARM_lock,
317 ARG_protocol,
318USE_FEATURE_IP_RULE(ARG_table,)
319 ARG_dev,
320 ARG_oif,
321 ARG_to
322 };
323 int arg; 327 int arg;
324 328
325 memset(&req, 0, sizeof(req)); 329 memset(&req, 0, sizeof(req));
@@ -341,7 +345,7 @@ USE_FEATURE_IP_RULE(ARG_table,)
341 mxrta->rta_len = RTA_LENGTH(0); 345 mxrta->rta_len = RTA_LENGTH(0);
342 346
343 while (argc > 0) { 347 while (argc > 0) {
344 arg = index_in_substr_array(keywords, *argv); 348 arg = index_in_substrings(keywords, *argv);
345 if (arg == ARG_src) { 349 if (arg == ARG_src) {
346 inet_prefix addr; 350 inet_prefix addr;
347 NEXT_ARG(); 351 NEXT_ARG();
@@ -361,7 +365,7 @@ USE_FEATURE_IP_RULE(ARG_table,)
361 } else if (arg == ARG_mtu) { 365 } else if (arg == ARG_mtu) {
362 unsigned mtu; 366 unsigned mtu;
363 NEXT_ARG(); 367 NEXT_ARG();
364 if (index_in_str_array(keywords, *argv) == PARM_lock) { 368 if (index_in_strings(keywords, *argv) == PARM_lock) {
365 mxlock |= (1<<RTAX_MTU); 369 mxlock |= (1<<RTAX_MTU);
366 NEXT_ARG(); 370 NEXT_ARG();
367 } 371 }
@@ -513,10 +517,9 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
513 struct rtnl_handle rth; 517 struct rtnl_handle rth;
514 char *id = NULL; 518 char *id = NULL;
515 char *od = NULL; 519 char *od = NULL;
516 static const char * const keywords[] = { 520 static const char keywords[] =
517 "protocol", "all", "dev", "oif", "iif", "via", "table", "cache",/*all,*/ 521 "protocol\0""all\0""dev\0""oif\0""iif\0""via\0""table\0""cache\0" /*all*/
518 "from", "root", "match", "exact", "to", /*root,match,exact*/ NULL 522 "from\0""root\0""match\0""exact\0""to\0"/*root match exact*/;
519 };
520 enum { 523 enum {
521 ARG_proto, PARM_all, 524 ARG_proto, PARM_all,
522 ARG_dev, 525 ARG_dev,
@@ -535,13 +538,13 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
535 bb_error_msg_and_die(bb_msg_requires_arg, "\"ip route flush\""); 538 bb_error_msg_and_die(bb_msg_requires_arg, "\"ip route flush\"");
536 539
537 while (argc > 0) { 540 while (argc > 0) {
538 arg = index_in_substr_array(keywords, *argv); 541 arg = index_in_substrings(keywords, *argv);
539 if (arg == ARG_proto) { 542 if (arg == ARG_proto) {
540 uint32_t prot = 0; 543 uint32_t prot = 0;
541 NEXT_ARG(); 544 NEXT_ARG();
542 filter.protocolmask = -1; 545 filter.protocolmask = -1;
543 if (rtnl_rtprot_a2n(&prot, *argv)) { 546 if (rtnl_rtprot_a2n(&prot, *argv)) {
544 if (index_in_str_array(keywords, *argv) != PARM_all) 547 if (index_in_strings(keywords, *argv) != PARM_all)
545 invarg(*argv, "protocol"); 548 invarg(*argv, "protocol");
546 prot = 0; 549 prot = 0;
547 filter.protocolmask = 0; 550 filter.protocolmask = 0;
@@ -558,7 +561,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
558 get_prefix(&filter.rvia, *argv, do_ipv6); 561 get_prefix(&filter.rvia, *argv, do_ipv6);
559 } else if (arg == ARG_table) { 562 } else if (arg == ARG_table) {
560 NEXT_ARG(); 563 NEXT_ARG();
561 parm = index_in_substr_array(keywords, *argv); 564 parm = index_in_substrings(keywords, *argv);
562 if (parm == PARM_cache) 565 if (parm == PARM_cache)
563 filter.tb = -1; 566 filter.tb = -1;
564 else if (parm == PARM_all) 567 else if (parm == PARM_all)
@@ -567,7 +570,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
567 invarg(*argv, "table"); 570 invarg(*argv, "table");
568 } else if (arg == ARG_from) { 571 } else if (arg == ARG_from) {
569 NEXT_ARG(); 572 NEXT_ARG();
570 parm = index_in_substr_array(keywords, *argv); 573 parm = index_in_substrings(keywords, *argv);
571 if (parm == PARM_root) { 574 if (parm == PARM_root) {
572 NEXT_ARG(); 575 NEXT_ARG();
573 get_prefix(&filter.rsrc, *argv, do_ipv6); 576 get_prefix(&filter.rsrc, *argv, do_ipv6);
@@ -584,7 +587,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
584 /* parm = arg; // would be more plausible, we reuse arg here */ 587 /* parm = arg; // would be more plausible, we reuse arg here */
585 if (arg == ARG_to) { 588 if (arg == ARG_to) {
586 NEXT_ARG(); 589 NEXT_ARG();
587 arg = index_in_substr_array(keywords, *argv); 590 arg = index_in_substrings(keywords, *argv);
588 } 591 }
589 if (arg == PARM_root) { 592 if (arg == PARM_root) {
590 NEXT_ARG(); 593 NEXT_ARG();
@@ -645,9 +648,8 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
645 xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); 648 xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE);
646 filter.flushed = 0; 649 filter.flushed = 0;
647 xrtnl_dump_filter(&rth, print_route, stdout); 650 xrtnl_dump_filter(&rth, print_route, stdout);
648 if (filter.flushed == 0) { 651 if (filter.flushed == 0)
649 return 0; 652 return 0;
650 }
651 if (flush_update()) 653 if (flush_update())
652 return 1; 654 return 1;
653 } 655 }
@@ -655,10 +657,8 @@ static int iproute_list_or_flush(int argc, char **argv, int flush)
655 657
656 if (filter.tb != -1) { 658 if (filter.tb != -1) {
657 xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); 659 xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE);
658 } else { 660 } else if (rtnl_rtcache_request(&rth, do_ipv6) < 0) {
659 if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { 661 bb_perror_msg_and_die("cannot send dump request");
660 bb_perror_msg_and_die("cannot send dump request");
661 }
662 } 662 }
663 xrtnl_dump_filter(&rth, print_route, stdout); 663 xrtnl_dump_filter(&rth, print_route, stdout);
664 664
@@ -671,16 +671,16 @@ static int iproute_get(int argc, char **argv)
671{ 671{
672 struct rtnl_handle rth; 672 struct rtnl_handle rth;
673 struct { 673 struct {
674 struct nlmsghdr n; 674 struct nlmsghdr n;
675 struct rtmsg r; 675 struct rtmsg r;
676 char buf[1024]; 676 char buf[1024];
677 } req; 677 } req;
678 char *idev = NULL; 678 char *idev = NULL;
679 char *odev = NULL; 679 char *odev = NULL;
680 bool connected = 0; 680 bool connected = 0;
681 bool from_ok = 0; 681 bool from_ok = 0;
682 static const char * const options[] = 682 static const char options[] =
683 { "from", "iif", "oif", "dev", "notify", "connected", "to", 0 }; 683 "from\0""iif\0""oif\0""dev\0""notify\0""connected\0""to\0";
684 684
685 memset(&req, 0, sizeof(req)); 685 memset(&req, 0, sizeof(req));
686 686
@@ -699,7 +699,7 @@ static int iproute_get(int argc, char **argv)
699 req.r.rtm_tos = 0; 699 req.r.rtm_tos = 0;
700 700
701 while (argc > 0) { 701 while (argc > 0) {
702 switch (index_in_str_array(options, *argv)) { 702 switch (index_in_strings(options, *argv)) {
703 case 0: /* from */ 703 case 0: /* from */
704 { 704 {
705 inet_prefix addr; 705 inet_prefix addr;
@@ -824,19 +824,18 @@ static int iproute_get(int argc, char **argv)
824/* Return value becomes exitcode. It's okay to not return at all */ 824/* Return value becomes exitcode. It's okay to not return at all */
825int do_iproute(int argc, char **argv) 825int do_iproute(int argc, char **argv)
826{ 826{
827 static const char * const ip_route_commands[] = { 827 static const char ip_route_commands[] =
828 /*0-3*/ "add", "append", "change", "chg", 828 /*0-3*/ "add\0""append\0""change\0""chg\0"
829 /*4-7*/ "delete", "get", "list", "show", 829 /*4-7*/ "delete\0""get\0""list\0""show\0"
830 /*8..*/ "prepend", "replace", "test", "flush", 0 830 /*8..*/ "prepend\0""replace\0""test\0""flush\0";
831 };
832 int command_num = 6; 831 int command_num = 6;
833 unsigned int flags = 0; 832 unsigned flags = 0;
834 int cmd = RTM_NEWROUTE; 833 int cmd = RTM_NEWROUTE;
835 834
836 /* "Standard" 'ip r a' treats 'a' as 'add', not 'append' */ 835 /* "Standard" 'ip r a' treats 'a' as 'add', not 'append' */
837 /* It probably means that it is using "first match" rule */ 836 /* It probably means that it is using "first match" rule */
838 if (*argv) { 837 if (*argv) {
839 command_num = index_in_substr_array(ip_route_commands, *argv); 838 command_num = index_in_substrings(ip_route_commands, *argv);
840 } 839 }
841 switch (command_num) { 840 switch (command_num) {
842 case 0: /* add */ 841 case 0: /* add */
diff --git a/networking/libiproute/iprule.c b/networking/libiproute/iprule.c
index a62eae1fe..8e2a06f4f 100644
--- a/networking/libiproute/iprule.c
+++ b/networking/libiproute/iprule.c
@@ -187,6 +187,15 @@ static int iprule_list(int argc, char **argv)
187/* Return value becomes exitcode. It's okay to not return at all */ 187/* Return value becomes exitcode. It's okay to not return at all */
188static int iprule_modify(int cmd, int argc, char **argv) 188static int iprule_modify(int cmd, int argc, char **argv)
189{ 189{
190 static const char keywords[] =
191 "from\0""to\0""preference\0""order\0""priority\0"
192 "tos\0""fwmark\0""realms\0""table\0""lookup\0""dev\0"
193 "iif\0""nat\0""map-to\0""type\0""help\0";
194 enum {
195 ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
196 ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup, ARG_dev,
197 ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help
198 };
190 bool table_ok = 0; 199 bool table_ok = 0;
191 struct rtnl_handle rth; 200 struct rtnl_handle rth;
192 struct { 201 struct {
@@ -194,13 +203,6 @@ static int iprule_modify(int cmd, int argc, char **argv)
194 struct rtmsg r; 203 struct rtmsg r;
195 char buf[1024]; 204 char buf[1024];
196 } req; 205 } req;
197 static const char * const keywords[] =
198 { "from", "to", "preference", "order", "priority", "tos", "fwmark",
199 "realms", "table", "lookup", "dev", "iif", "nat", "map-to", "type",
200 "help", NULL};
201 enum { ARG_from = 1, ARG_to, ARG_preference, ARG_order, ARG_priority,
202 ARG_tos, ARG_fwmark, ARG_realms, ARG_table, ARG_lookup, ARG_dev,
203 ARG_iif, ARG_nat, ARG_map_to, ARG_type, ARG_help };
204 smalluint key; 206 smalluint key;
205 207
206 memset(&req, 0, sizeof(req)); 208 memset(&req, 0, sizeof(req));
@@ -220,7 +222,7 @@ static int iprule_modify(int cmd, int argc, char **argv)
220 } 222 }
221 223
222 while (argc > 0) { 224 while (argc > 0) {
223 key = index_in_substr_array(keywords, *argv) + 1; 225 key = index_in_substrings(keywords, *argv) + 1;
224 if (key == 0) /* no match found in keywords array, bail out. */ 226 if (key == 0) /* no match found in keywords array, bail out. */
225 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); 227 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
226 if (key == ARG_from) { 228 if (key == ARG_from) {
@@ -311,14 +313,14 @@ static int iprule_modify(int cmd, int argc, char **argv)
311/* Return value becomes exitcode. It's okay to not return at all */ 313/* Return value becomes exitcode. It's okay to not return at all */
312int do_iprule(int argc, char **argv) 314int do_iprule(int argc, char **argv)
313{ 315{
314 static const char * const ip_rule_commands[] = 316 static const char ip_rule_commands[] =
315 {"add", "delete", "list", "show", 0}; 317 "add\0""delete\0""list\0""show\0";
316 int cmd = 2; /* list */ 318 int cmd = 2; /* list */
317 319
318 if (argc < 1) 320 if (argc < 1)
319 return iprule_list(0, NULL); 321 return iprule_list(0, NULL);
320 if (*argv) 322 if (*argv)
321 cmd = index_in_substr_array(ip_rule_commands, *argv); 323 cmd = index_in_substrings(ip_rule_commands, *argv);
322 324
323 switch (cmd) { 325 switch (cmd) {
324 case 0: /* add */ 326 case 0: /* add */
diff --git a/networking/libiproute/iptunnel.c b/networking/libiproute/iptunnel.c
index 90d0e1186..a2933879c 100644
--- a/networking/libiproute/iptunnel.c
+++ b/networking/libiproute/iptunnel.c
@@ -128,16 +128,13 @@ static int do_del_ioctl(const char *basedev, struct ip_tunnel_parm *p)
128/* Dies on error */ 128/* Dies on error */
129static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p) 129static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
130{ 130{
131 int count = 0; 131 static const char keywords[] =
132 char medium[IFNAMSIZ]; 132 "mode\0""ipip\0""ip/ip\0""gre\0""gre/ip\0""sit\0""ipv6/ip\0"
133 static const char * const keywords[] = { 133 "key\0""ikey\0""okey\0""seq\0""iseq\0""oseq\0"
134 "mode", "ipip", "ip/ip", "gre", "gre/ip", "sit", "ipv6/ip", 134 "csum\0""icsum\0""ocsum\0""nopmtudisc\0""pmtudisc\0"
135 "key", "ikey", "okey", "seq", "iseq", "oseq", 135 "remote\0""any\0""local\0""dev\0"
136 "csum", "icsum", "ocsum", "nopmtudisc", "pmtudisc", 136 "ttl\0""inherit\0""tos\0""dsfield\0"
137 "remote", "any", "local", "dev", 137 "name\0";
138 "ttl", "inherit", "tos", "dsfield",
139 "name", NULL
140 };
141 enum { 138 enum {
142 ARG_mode, ARG_ipip, ARG_ip_ip, ARG_gre, ARG_gre_ip, ARG_sit, ARG_ip6_ip, 139 ARG_mode, ARG_ipip, ARG_ip_ip, ARG_gre, ARG_gre_ip, ARG_sit, ARG_ip6_ip,
143 ARG_key, ARG_ikey, ARG_okey, ARG_seq, ARG_iseq, ARG_oseq, 140 ARG_key, ARG_ikey, ARG_okey, ARG_seq, ARG_iseq, ARG_oseq,
@@ -146,22 +143,25 @@ static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
146 ARG_ttl, ARG_inherit, ARG_tos, ARG_dsfield, 143 ARG_ttl, ARG_inherit, ARG_tos, ARG_dsfield,
147 ARG_name 144 ARG_name
148 }; 145 };
146 int count = 0;
147 char medium[IFNAMSIZ];
149 int key; 148 int key;
149
150 memset(p, 0, sizeof(*p)); 150 memset(p, 0, sizeof(*p));
151 memset(&medium, 0, sizeof(medium)); 151 memset(&medium, 0, sizeof(medium));
152 152
153 p->iph.version = 4; 153 p->iph.version = 4;
154 p->iph.ihl = 5; 154 p->iph.ihl = 5;
155#ifndef IP_DF 155#ifndef IP_DF
156#define IP_DF 0x4000 /* Flag: "Don't Fragment" */ 156#define IP_DF 0x4000 /* Flag: "Don't Fragment" */
157#endif 157#endif
158 p->iph.frag_off = htons(IP_DF); 158 p->iph.frag_off = htons(IP_DF);
159 159
160 while (argc > 0) { 160 while (argc > 0) {
161 key = index_in_str_array(keywords, *argv); 161 key = index_in_strings(keywords, *argv);
162 if (key == ARG_mode) { 162 if (key == ARG_mode) {
163 NEXT_ARG(); 163 NEXT_ARG();
164 key = index_in_str_array(keywords, *argv); 164 key = index_in_strings(keywords, *argv);
165 if (key == ARG_ipip || 165 if (key == ARG_ipip ||
166 key == ARG_ip_ip) { 166 key == ARG_ip_ip) {
167 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) { 167 if (p->iph.protocol && p->iph.protocol != IPPROTO_IPIP) {
@@ -240,12 +240,12 @@ static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
240 p->iph.frag_off = htons(IP_DF); 240 p->iph.frag_off = htons(IP_DF);
241 } else if (key == ARG_remote) { 241 } else if (key == ARG_remote) {
242 NEXT_ARG(); 242 NEXT_ARG();
243 key = index_in_str_array(keywords, *argv); 243 key = index_in_strings(keywords, *argv);
244 if (key == ARG_any) 244 if (key == ARG_any)
245 p->iph.daddr = get_addr32(*argv); 245 p->iph.daddr = get_addr32(*argv);
246 } else if (key == ARG_local) { 246 } else if (key == ARG_local) {
247 NEXT_ARG(); 247 NEXT_ARG();
248 key = index_in_str_array(keywords, *argv); 248 key = index_in_strings(keywords, *argv);
249 if (key == ARG_any) 249 if (key == ARG_any)
250 p->iph.saddr = get_addr32(*argv); 250 p->iph.saddr = get_addr32(*argv);
251 } else if (key == ARG_dev) { 251 } else if (key == ARG_dev) {
@@ -254,7 +254,7 @@ static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
254 } else if (key == ARG_ttl) { 254 } else if (key == ARG_ttl) {
255 unsigned uval; 255 unsigned uval;
256 NEXT_ARG(); 256 NEXT_ARG();
257 key = index_in_str_array(keywords, *argv); 257 key = index_in_strings(keywords, *argv);
258 if (key != ARG_inherit) { 258 if (key != ARG_inherit) {
259 if (get_unsigned(&uval, *argv, 0)) 259 if (get_unsigned(&uval, *argv, 0))
260 invarg(*argv, "TTL"); 260 invarg(*argv, "TTL");
@@ -266,7 +266,7 @@ static void parse_args(int argc, char **argv, int cmd, struct ip_tunnel_parm *p)
266 key == ARG_dsfield) { 266 key == ARG_dsfield) {
267 uint32_t uval; 267 uint32_t uval;
268 NEXT_ARG(); 268 NEXT_ARG();
269 key = index_in_str_array(keywords, *argv); 269 key = index_in_strings(keywords, *argv);
270 if (key != ARG_inherit) { 270 if (key != ARG_inherit) {
271 if (rtnl_dsfield_a2n(&uval, *argv)) 271 if (rtnl_dsfield_a2n(&uval, *argv))
272 invarg(*argv, "TOS"); 272 invarg(*argv, "TOS");
@@ -519,14 +519,13 @@ static int do_show(int argc, char **argv)
519/* Return value becomes exitcode. It's okay to not return at all */ 519/* Return value becomes exitcode. It's okay to not return at all */
520int do_iptunnel(int argc, char **argv) 520int do_iptunnel(int argc, char **argv)
521{ 521{
522 static const char *const keywords[] = { 522 static const char keywords[] =
523 "add", "change", "delete", "show", "list", "lst", NULL 523 "add\0""change\0""delete\0""show\0""list\0""lst\0";
524 };
525 enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst }; 524 enum { ARG_add = 0, ARG_change, ARG_del, ARG_show, ARG_list, ARG_lst };
526 int key; 525 int key;
527 526
528 if (argc) { 527 if (argc) {
529 key = index_in_substr_array(keywords, *argv); 528 key = index_in_substrings(keywords, *argv);
530 if (key < 0) 529 if (key < 0)
531 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name); 530 bb_error_msg_and_die(bb_msg_invalid_arg, *argv, applet_name);
532 --argc; 531 --argc;
diff --git a/networking/libiproute/rtm_map.c b/networking/libiproute/rtm_map.c
index 593017bf1..96b2d1791 100644
--- a/networking/libiproute/rtm_map.c
+++ b/networking/libiproute/rtm_map.c
@@ -51,16 +51,16 @@ 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[] = { 54 static const char keywords[] =
55 "local", "nat", "broadcast", "brd", "anycast", 55 "local\0""nat\0""broadcast\0""brd\0""anycast\0"
56 "multicast", "prohibit", "unreachable", "blackhole", 56 "multicast\0""prohibit\0""unreachable\0""blackhole\0"
57 "xresolve", "unicast", "throw", NULL 57 "xresolve\0""unicast\0""throw\0";
58 }; 58 enum {
59 enum { ARG_local = 1, ARG_nat, ARG_broadcast, ARG_brd, ARG_anycast, 59 ARG_local = 1, ARG_nat, ARG_broadcast, ARG_brd, ARG_anycast,
60 ARG_multicast, ARG_prohibit, ARG_unreachable, ARG_blackhole, 60 ARG_multicast, ARG_prohibit, ARG_unreachable, ARG_blackhole,
61 ARG_xresolve, ARG_unicast, ARG_throw 61 ARG_xresolve, ARG_unicast, ARG_throw
62 }; 62 };
63 const smalluint key = index_in_substr_array(keywords, arg) + 1; 63 const smalluint key = index_in_substrings(keywords, arg) + 1;
64 char *end; 64 char *end;
65 unsigned long res; 65 unsigned long res;
66 66