aboutsummaryrefslogtreecommitdiff
path: root/networking/libiproute/ipaddress.c
diff options
context:
space:
mode:
Diffstat (limited to 'networking/libiproute/ipaddress.c')
-rw-r--r--networking/libiproute/ipaddress.c51
1 files changed, 23 insertions, 28 deletions
diff --git a/networking/libiproute/ipaddress.c b/networking/libiproute/ipaddress.c
index b25981900..044538aca 100644
--- a/networking/libiproute/ipaddress.c
+++ b/networking/libiproute/ipaddress.c
@@ -410,7 +410,7 @@ static void ipaddr_reset_filter(int _oneline)
410} 410}
411 411
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(char **argv, int flush)
414{ 414{
415 static const char option[] ALIGN1 = "to\0""scope\0""up\0""label\0""dev\0"; 415 static const char option[] ALIGN1 = "to\0""scope\0""up\0""label\0""dev\0";
416 416
@@ -428,7 +428,7 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
428 filter.family = preferred_family; 428 filter.family = preferred_family;
429 429
430 if (flush) { 430 if (flush) {
431 if (argc <= 0) { 431 if (!*argv) {
432 bb_error_msg_and_die(bb_msg_requires_arg, "flush"); 432 bb_error_msg_and_die(bb_msg_requires_arg, "flush");
433 } 433 }
434 if (filter.family == AF_PACKET) { 434 if (filter.family == AF_PACKET) {
@@ -436,7 +436,7 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
436 } 436 }
437 } 437 }
438 438
439 while (argc > 0) { 439 while (*argv) {
440 const int option_num = index_in_strings(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 */
@@ -477,7 +477,6 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
477 filter_dev = *argv; 477 filter_dev = *argv;
478 } 478 }
479 argv++; 479 argv++;
480 argc--;
481 } 480 }
482 481
483 xrtnl_open(&rth); 482 xrtnl_open(&rth);
@@ -517,26 +516,26 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
517 516
518 if (filter.family && filter.family != AF_PACKET) { 517 if (filter.family && filter.family != AF_PACKET) {
519 struct nlmsg_list **lp; 518 struct nlmsg_list **lp;
520 lp=&linfo; 519 lp = &linfo;
521 520
522 if (filter.oneline) 521 if (filter.oneline)
523 no_link = 1; 522 no_link = 1;
524 523
525 while ((l=*lp)!=NULL) { 524 while ((l = *lp) != NULL) {
526 int ok = 0; 525 int ok = 0;
527 struct ifinfomsg *ifi = NLMSG_DATA(&l->h); 526 struct ifinfomsg *ifi = NLMSG_DATA(&l->h);
528 struct nlmsg_list *a; 527 struct nlmsg_list *a;
529 528
530 for (a=ainfo; a; a=a->next) { 529 for (a = ainfo; a; a = a->next) {
531 struct nlmsghdr *n = &a->h; 530 struct nlmsghdr *n = &a->h;
532 struct ifaddrmsg *ifa = NLMSG_DATA(n); 531 struct ifaddrmsg *ifa = NLMSG_DATA(n);
533 532
534 if (ifa->ifa_index != ifi->ifi_index || 533 if (ifa->ifa_index != ifi->ifi_index ||
535 (filter.family && filter.family != ifa->ifa_family)) 534 (filter.family && filter.family != ifa->ifa_family))
536 continue; 535 continue;
537 if ((filter.scope^ifa->ifa_scope)&filter.scopemask) 536 if ((filter.scope ^ ifa->ifa_scope) & filter.scopemask)
538 continue; 537 continue;
539 if ((filter.flags^ifa->ifa_flags)&filter.flagmask) 538 if ((filter.flags ^ ifa->ifa_flags) & filter.flagmask)
540 continue; 539 continue;
541 if (filter.pfx.family || filter.label) { 540 if (filter.pfx.family || filter.label) {
542 struct rtattr *tb[IFA_MAX+1]; 541 struct rtattr *tb[IFA_MAX+1];
@@ -581,7 +580,6 @@ int ipaddr_list_or_flush(int argc, char **argv, int flush)
581 if (filter.family != AF_PACKET) 580 if (filter.family != AF_PACKET)
582 print_selected_addrinfo(ifi->ifi_index, ainfo, stdout); 581 print_selected_addrinfo(ifi->ifi_index, ainfo, stdout);
583 } 582 }
584 fflush(stdout); /* why? */
585 } 583 }
586 584
587 return 0; 585 return 0;
@@ -597,7 +595,7 @@ static int default_scope(inet_prefix *lcl)
597} 595}
598 596
599/* Return value becomes exitcode. It's okay to not return at all */ 597/* Return value becomes exitcode. It's okay to not return at all */
600static int ipaddr_modify(int cmd, int argc, char **argv) 598static int ipaddr_modify(int cmd, char **argv)
601{ 599{
602 static const char option[] ALIGN1 = 600 static const char option[] ALIGN1 =
603 "peer\0""remote\0""broadcast\0""brd\0" 601 "peer\0""remote\0""broadcast\0""brd\0"
@@ -625,7 +623,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
625 req.n.nlmsg_type = cmd; 623 req.n.nlmsg_type = cmd;
626 req.ifa.ifa_family = preferred_family; 624 req.ifa.ifa_family = preferred_family;
627 625
628 while (argc > 0) { 626 while (*argv) {
629 const int option_num = index_in_strings(option, *argv); 627 const int option_num = index_in_strings(option, *argv);
630 switch (option_num) { 628 switch (option_num) {
631 case 0: /* peer */ 629 case 0: /* peer */
@@ -653,8 +651,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
653 } 651 }
654 if (LONE_CHAR(*argv, '+')) { 652 if (LONE_CHAR(*argv, '+')) {
655 brd_len = -1; 653 brd_len = -1;
656 } 654 } else if (LONE_DASH(*argv)) {
657 else if (LONE_DASH(*argv)) {
658 brd_len = -2; 655 brd_len = -2;
659 } else { 656 } else {
660 get_addr(&addr, *argv, req.ifa.ifa_family); 657 get_addr(&addr, *argv, req.ifa.ifa_family);
@@ -713,12 +710,11 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
713 addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen); 710 addattr_l(&req.n, sizeof(req), IFA_LOCAL, &lcl.data, lcl.bytelen);
714 local_len = lcl.bytelen; 711 local_len = lcl.bytelen;
715 } 712 }
716 argc--;
717 argv++; 713 argv++;
718 } 714 }
719 715
720 if (d == NULL) { 716 if (d == NULL) {
721 bb_error_msg(bb_msg_requires_arg,"\"dev\""); 717 bb_error_msg(bb_msg_requires_arg, "\"dev\"");
722 return -1; 718 return -1;
723 } 719 }
724 if (l && strncmp(d, l, strlen(d)) != 0) { 720 if (l && strncmp(d, l, strlen(d)) != 0) {
@@ -766,7 +762,7 @@ static int ipaddr_modify(int cmd, int argc, char **argv)
766} 762}
767 763
768/* Return value becomes exitcode. It's okay to not return at all */ 764/* Return value becomes exitcode. It's okay to not return at all */
769int do_ipaddr(int argc, char **argv) 765int do_ipaddr(char **argv)
770{ 766{
771 static const char commands[] ALIGN1 = 767 static const char commands[] ALIGN1 =
772 "add\0""delete\0""list\0""show\0""lst\0""flush\0"; 768 "add\0""delete\0""list\0""show\0""lst\0""flush\0";
@@ -775,17 +771,16 @@ int do_ipaddr(int argc, char **argv)
775 771
776 if (*argv) { 772 if (*argv) {
777 command_num = index_in_substrings(commands, *argv); 773 command_num = index_in_substrings(commands, *argv);
774 if (command_num < 0 || command_num > 5)
775 bb_error_msg_and_die("unknown command %s", *argv);
776 argv++;
778 } 777 }
779 if (command_num < 0 || command_num > 5)
780 bb_error_msg_and_die("unknown command %s", *argv);
781 --argc;
782 ++argv;
783 if (command_num == 0) /* add */ 778 if (command_num == 0) /* add */
784 return ipaddr_modify(RTM_NEWADDR, argc, argv); 779 return ipaddr_modify(RTM_NEWADDR, argv);
785 else if (command_num == 1) /* delete */ 780 if (command_num == 1) /* delete */
786 return ipaddr_modify(RTM_DELADDR, argc, argv); 781 return ipaddr_modify(RTM_DELADDR, argv);
787 else if (command_num == 5) /* flush */ 782 if (command_num == 5) /* flush */
788 return ipaddr_list_or_flush(argc, argv, 1); 783 return ipaddr_list_or_flush(argv, 1);
789 else /* 2 == list, 3 == show, 4 == lst */ 784 /* 2 == list, 3 == show, 4 == lst */
790 return ipaddr_list_or_flush(argc, argv, 0); 785 return ipaddr_list_or_flush(argv, 0);
791} 786}