aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/iproute.c
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/iproute.c
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/iproute.c')
-rw-r--r--networking/libiproute/iproute.c93
1 files changed, 46 insertions, 47 deletions
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 */