diff options
Diffstat (limited to 'networking/libiproute/iproute.c')
-rw-r--r-- | networking/libiproute/iproute.c | 74 |
1 files changed, 18 insertions, 56 deletions
diff --git a/networking/libiproute/iproute.c b/networking/libiproute/iproute.c index 23d416344..e7ad7d9c4 100644 --- a/networking/libiproute/iproute.c +++ b/networking/libiproute/iproute.c | |||
@@ -102,10 +102,8 @@ static int print_route(struct sockaddr_nl *who ATTRIBUTE_UNUSED, | |||
102 | if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE) | 102 | if (filter.flushb && n->nlmsg_type != RTM_NEWROUTE) |
103 | return 0; | 103 | return 0; |
104 | len -= NLMSG_LENGTH(sizeof(*r)); | 104 | len -= NLMSG_LENGTH(sizeof(*r)); |
105 | if (len < 0) { | 105 | if (len < 0) |
106 | bb_error_msg("wrong nlmsg len %d", len); | 106 | bb_error_msg_and_die("wrong nlmsg len %d", len); |
107 | return -1; | ||
108 | } | ||
109 | 107 | ||
110 | if (r->rtm_family == AF_INET6) | 108 | if (r->rtm_family == AF_INET6) |
111 | host_len = 128; | 109 | host_len = 128; |
@@ -186,7 +184,7 @@ static int print_route(struct sockaddr_nl *who ATTRIBUTE_UNUSED, | |||
186 | struct nlmsghdr *fn; | 184 | struct nlmsghdr *fn; |
187 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { | 185 | if (NLMSG_ALIGN(filter.flushp) + n->nlmsg_len > filter.flushe) { |
188 | if (flush_update()) | 186 | if (flush_update()) |
189 | return -1; | 187 | bb_error_msg_and_die("flush"); |
190 | } | 188 | } |
191 | fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); | 189 | fn = (struct nlmsghdr*)(filter.flushb + NLMSG_ALIGN(filter.flushp)); |
192 | memcpy(fn, n, n->nlmsg_len); | 190 | memcpy(fn, n, n->nlmsg_len); |
@@ -410,9 +408,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) | |||
410 | argc--; argv++; | 408 | argc--; argv++; |
411 | } | 409 | } |
412 | 410 | ||
413 | if (rtnl_open(&rth, 0) < 0) { | 411 | xrtnl_open(&rth); |
414 | return 1; | ||
415 | } | ||
416 | 412 | ||
417 | if (d) { | 413 | if (d) { |
418 | int idx; | 414 | int idx; |
@@ -420,10 +416,7 @@ static int iproute_modify(int cmd, unsigned flags, int argc, char **argv) | |||
420 | ll_init_map(&rth); | 416 | ll_init_map(&rth); |
421 | 417 | ||
422 | if (d) { | 418 | if (d) { |
423 | idx = ll_name_to_index(d); | 419 | idx = xll_name_to_index(d); |
424 | if (idx == 0) { | ||
425 | bb_error_msg_and_die("cannot find device \"%s\"", d); | ||
426 | } | ||
427 | addattr32(&req.n, sizeof(req), RTA_OIF, idx); | 420 | addattr32(&req.n, sizeof(req), RTA_OIF, idx); |
428 | } | 421 | } |
429 | } | 422 | } |
@@ -478,7 +471,7 @@ static int rtnl_rtcache_request(struct rtnl_handle *rth, int family) | |||
478 | req.rtm.rtm_family = family; | 471 | req.rtm.rtm_family = family; |
479 | req.rtm.rtm_flags |= RTM_F_CLONED; | 472 | req.rtm.rtm_flags |= RTM_F_CLONED; |
480 | 473 | ||
481 | return sendto(rth->fd, (void*)&req, sizeof(req), 0, (struct sockaddr*)&nladdr, sizeof(nladdr)); | 474 | return xsendto(rth->fd, (void*)&req, sizeof(req), (struct sockaddr*)&nladdr, sizeof(nladdr)); |
482 | } | 475 | } |
483 | 476 | ||
484 | static void iproute_flush_cache(void) | 477 | static void iproute_flush_cache(void) |
@@ -592,9 +585,7 @@ static int iproute_list_or_flush(int argc, char **argv, int flush) | |||
592 | do_ipv6 = AF_INET; | 585 | do_ipv6 = AF_INET; |
593 | } | 586 | } |
594 | 587 | ||
595 | if (rtnl_open(&rth, 0) < 0) { | 588 | xrtnl_open(&rth); |
596 | return 1; | ||
597 | } | ||
598 | 589 | ||
599 | ll_init_map(&rth); | 590 | ll_init_map(&rth); |
600 | 591 | ||
@@ -602,18 +593,12 @@ static int iproute_list_or_flush(int argc, char **argv, int flush) | |||
602 | int idx; | 593 | int idx; |
603 | 594 | ||
604 | if (id) { | 595 | if (id) { |
605 | idx = ll_name_to_index(id); | 596 | idx = xll_name_to_index(id); |
606 | if (idx == 0) { | ||
607 | bb_error_msg_and_die("cannot find device \"%s\"", id); | ||
608 | } | ||
609 | filter.iif = idx; | 597 | filter.iif = idx; |
610 | filter.iifmask = -1; | 598 | filter.iifmask = -1; |
611 | } | 599 | } |
612 | if (od) { | 600 | if (od) { |
613 | idx = ll_name_to_index(od); | 601 | idx = xll_name_to_index(od); |
614 | if (idx == 0) { | ||
615 | bb_error_msg("cannot find device \"%s\"", od); | ||
616 | } | ||
617 | filter.oif = idx; | 602 | filter.oif = idx; |
618 | filter.oifmask = -1; | 603 | filter.oifmask = -1; |
619 | } | 604 | } |
@@ -635,13 +620,9 @@ static int iproute_list_or_flush(int argc, char **argv, int flush) | |||
635 | filter.rth = &rth; | 620 | filter.rth = &rth; |
636 | 621 | ||
637 | for (;;) { | 622 | for (;;) { |
638 | if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) { | 623 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); |
639 | bb_perror_msg_and_die("cannot send dump request"); | ||
640 | } | ||
641 | filter.flushed = 0; | 624 | filter.flushed = 0; |
642 | if (rtnl_dump_filter(&rth, print_route, stdout, NULL, NULL) < 0) { | 625 | xrtnl_dump_filter(&rth, print_route, stdout); |
643 | bb_error_msg_and_die("flush terminated"); | ||
644 | } | ||
645 | if (filter.flushed == 0) { | 626 | if (filter.flushed == 0) { |
646 | return 0; | 627 | return 0; |
647 | } | 628 | } |
@@ -651,18 +632,13 @@ static int iproute_list_or_flush(int argc, char **argv, int flush) | |||
651 | } | 632 | } |
652 | 633 | ||
653 | if (filter.tb != -1) { | 634 | if (filter.tb != -1) { |
654 | if (rtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE) < 0) { | 635 | xrtnl_wilddump_request(&rth, do_ipv6, RTM_GETROUTE); |
655 | bb_perror_msg_and_die("cannot send dump request"); | ||
656 | } | ||
657 | } else { | 636 | } else { |
658 | if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { | 637 | if (rtnl_rtcache_request(&rth, do_ipv6) < 0) { |
659 | bb_perror_msg_and_die("cannot send dump request"); | 638 | bb_perror_msg_and_die("cannot send dump request"); |
660 | } | 639 | } |
661 | } | 640 | } |
662 | 641 | xrtnl_dump_filter(&rth, print_route, stdout); | |
663 | if (rtnl_dump_filter(&rth, print_route, stdout, NULL, NULL) < 0) { | ||
664 | bb_error_msg_and_die("dump terminated"); | ||
665 | } | ||
666 | 642 | ||
667 | return 0; | 643 | return 0; |
668 | } | 644 | } |
@@ -755,8 +731,7 @@ static int iproute_get(int argc, char **argv) | |||
755 | bb_error_msg_and_die("need at least destination address"); | 731 | bb_error_msg_and_die("need at least destination address"); |
756 | } | 732 | } |
757 | 733 | ||
758 | if (rtnl_open(&rth, 0) < 0) | 734 | xrtnl_open(&rth); |
759 | return 1; | ||
760 | 735 | ||
761 | ll_init_map(&rth); | 736 | ll_init_map(&rth); |
762 | 737 | ||
@@ -764,17 +739,11 @@ static int iproute_get(int argc, char **argv) | |||
764 | int idx; | 739 | int idx; |
765 | 740 | ||
766 | if (idev) { | 741 | if (idev) { |
767 | idx = ll_name_to_index(idev); | 742 | idx = xll_name_to_index(idev); |
768 | if (idx == 0) { | ||
769 | bb_error_msg_and_die("cannot find device \"%s\"", idev); | ||
770 | } | ||
771 | addattr32(&req.n, sizeof(req), RTA_IIF, idx); | 743 | addattr32(&req.n, sizeof(req), RTA_IIF, idx); |
772 | } | 744 | } |
773 | if (odev) { | 745 | if (odev) { |
774 | idx = ll_name_to_index(odev); | 746 | idx = xll_name_to_index(odev); |
775 | if (idx == 0) { | ||
776 | bb_error_msg_and_die("cannot find device \"%s\"", odev); | ||
777 | } | ||
778 | addattr32(&req.n, sizeof(req), RTA_OIF, idx); | 747 | addattr32(&req.n, sizeof(req), RTA_OIF, idx); |
779 | } | 748 | } |
780 | } | 749 | } |
@@ -792,9 +761,7 @@ static int iproute_get(int argc, char **argv) | |||
792 | int len = req.n.nlmsg_len; | 761 | int len = req.n.nlmsg_len; |
793 | struct rtattr * tb[RTA_MAX+1]; | 762 | struct rtattr * tb[RTA_MAX+1]; |
794 | 763 | ||
795 | if (print_route(NULL, &req.n, (void*)stdout) < 0) { | 764 | print_route(NULL, &req.n, (void*)stdout); |
796 | bb_error_msg_and_die("an error :-)"); | ||
797 | } | ||
798 | 765 | ||
799 | if (req.n.nlmsg_type != RTM_NEWROUTE) { | 766 | if (req.n.nlmsg_type != RTM_NEWROUTE) { |
800 | bb_error_msg_and_die("not a route?"); | 767 | bb_error_msg_and_die("not a route?"); |
@@ -829,12 +796,7 @@ static int iproute_get(int argc, char **argv) | |||
829 | return 2; | 796 | return 2; |
830 | } | 797 | } |
831 | } | 798 | } |
832 | 799 | print_route(NULL, &req.n, (void*)stdout); | |
833 | if (print_route(NULL, &req.n, (void*)stdout) < 0) { | ||
834 | // how is this useful? | ||
835 | bb_error_msg_and_die("an error :-)"); | ||
836 | } | ||
837 | |||
838 | return 0; | 800 | return 0; |
839 | } | 801 | } |
840 | 802 | ||