diff options
author | Sreeram Ramachandran | 2014-07-20 01:24:27 -0500 |
---|---|---|
committer | Sreeram Ramachandran | 2014-07-22 17:00:21 -0500 |
commit | a723689eca75c71fd5260d918c18054a64e8d701 (patch) | |
tree | 808bbba79cea8b797382dd83499476c929746727 /libnetutils | |
parent | 930d53eae6a12b3b11c7d0043ec8c7674b1047cc (diff) | |
download | platform-system-core-a723689eca75c71fd5260d918c18054a64e8d701.tar.gz platform-system-core-a723689eca75c71fd5260d918c18054a64e8d701.tar.xz platform-system-core-a723689eca75c71fd5260d918c18054a64e8d701.zip |
Cleanup: Delete dead code.
Bug: 15413389
Change-Id: I315468832ef18ffc84174e54774ab63b86d284dc
Diffstat (limited to 'libnetutils')
-rw-r--r-- | libnetutils/ifc_utils.c | 301 |
1 files changed, 0 insertions, 301 deletions
diff --git a/libnetutils/ifc_utils.c b/libnetutils/ifc_utils.c index 4d004f639..52ce17156 100644 --- a/libnetutils/ifc_utils.c +++ b/libnetutils/ifc_utils.c | |||
@@ -563,47 +563,6 @@ int ifc_create_default_route(const char *name, in_addr_t gw) | |||
563 | return ret; | 563 | return ret; |
564 | } | 564 | } |
565 | 565 | ||
566 | /* deprecated v4-only */ | ||
567 | int ifc_add_host_route(const char *name, in_addr_t dst) | ||
568 | { | ||
569 | struct in_addr in_dst, in_gw; | ||
570 | |||
571 | in_dst.s_addr = dst; | ||
572 | in_gw.s_addr = 0; | ||
573 | |||
574 | return ifc_act_on_ipv4_route(SIOCADDRT, name, in_dst, 32, in_gw); | ||
575 | } | ||
576 | |||
577 | int ifc_enable(const char *ifname) | ||
578 | { | ||
579 | int result; | ||
580 | |||
581 | ifc_init(); | ||
582 | result = ifc_up(ifname); | ||
583 | ifc_close(); | ||
584 | return result; | ||
585 | } | ||
586 | |||
587 | int ifc_disable(const char *ifname) | ||
588 | { | ||
589 | unsigned addr, count; | ||
590 | int result; | ||
591 | |||
592 | ifc_init(); | ||
593 | result = ifc_down(ifname); | ||
594 | |||
595 | ifc_set_addr(ifname, 0); | ||
596 | for (count=0, addr=1;((addr != 0) && (count < 255)); count++) { | ||
597 | if (ifc_get_addr(ifname, &addr) < 0) | ||
598 | break; | ||
599 | if (addr) | ||
600 | ifc_set_addr(ifname, 0); | ||
601 | } | ||
602 | |||
603 | ifc_close(); | ||
604 | return result; | ||
605 | } | ||
606 | |||
607 | int ifc_reset_connections(const char *ifname, const int reset_mask) | 566 | int ifc_reset_connections(const char *ifname, const int reset_mask) |
608 | { | 567 | { |
609 | #ifdef HAVE_ANDROID_OS | 568 | #ifdef HAVE_ANDROID_OS |
@@ -648,118 +607,6 @@ int ifc_reset_connections(const char *ifname, const int reset_mask) | |||
648 | } | 607 | } |
649 | 608 | ||
650 | /* | 609 | /* |
651 | * Remove the routes associated with the named interface. | ||
652 | */ | ||
653 | int ifc_remove_host_routes(const char *name) | ||
654 | { | ||
655 | char ifname[64]; | ||
656 | in_addr_t dest, gway, mask; | ||
657 | int flags, refcnt, use, metric, mtu, win, irtt; | ||
658 | struct rtentry rt; | ||
659 | FILE *fp; | ||
660 | struct in_addr addr; | ||
661 | |||
662 | fp = fopen("/proc/net/route", "r"); | ||
663 | if (fp == NULL) | ||
664 | return -1; | ||
665 | /* Skip the header line */ | ||
666 | if (fscanf(fp, "%*[^\n]\n") < 0) { | ||
667 | fclose(fp); | ||
668 | return -1; | ||
669 | } | ||
670 | ifc_init(); | ||
671 | for (;;) { | ||
672 | int nread = fscanf(fp, "%63s%X%X%X%d%d%d%X%d%d%d\n", | ||
673 | ifname, &dest, &gway, &flags, &refcnt, &use, &metric, &mask, | ||
674 | &mtu, &win, &irtt); | ||
675 | if (nread != 11) { | ||
676 | break; | ||
677 | } | ||
678 | if ((flags & (RTF_UP|RTF_HOST)) != (RTF_UP|RTF_HOST) | ||
679 | || strcmp(ifname, name) != 0) { | ||
680 | continue; | ||
681 | } | ||
682 | memset(&rt, 0, sizeof(rt)); | ||
683 | rt.rt_dev = (void *)name; | ||
684 | init_sockaddr_in(&rt.rt_dst, dest); | ||
685 | init_sockaddr_in(&rt.rt_gateway, gway); | ||
686 | init_sockaddr_in(&rt.rt_genmask, mask); | ||
687 | addr.s_addr = dest; | ||
688 | if (ioctl(ifc_ctl_sock, SIOCDELRT, &rt) < 0) { | ||
689 | ALOGD("failed to remove route for %s to %s: %s", | ||
690 | ifname, inet_ntoa(addr), strerror(errno)); | ||
691 | } | ||
692 | } | ||
693 | fclose(fp); | ||
694 | ifc_close(); | ||
695 | return 0; | ||
696 | } | ||
697 | |||
698 | /* | ||
699 | * Return the address of the default gateway | ||
700 | * | ||
701 | * TODO: factor out common code from this and remove_host_routes() | ||
702 | * so that we only scan /proc/net/route in one place. | ||
703 | * | ||
704 | * DEPRECATED | ||
705 | */ | ||
706 | int ifc_get_default_route(const char *ifname) | ||
707 | { | ||
708 | char name[64]; | ||
709 | in_addr_t dest, gway, mask; | ||
710 | int flags, refcnt, use, metric, mtu, win, irtt; | ||
711 | int result; | ||
712 | FILE *fp; | ||
713 | |||
714 | fp = fopen("/proc/net/route", "r"); | ||
715 | if (fp == NULL) | ||
716 | return 0; | ||
717 | /* Skip the header line */ | ||
718 | if (fscanf(fp, "%*[^\n]\n") < 0) { | ||
719 | fclose(fp); | ||
720 | return 0; | ||
721 | } | ||
722 | ifc_init(); | ||
723 | result = 0; | ||
724 | for (;;) { | ||
725 | int nread = fscanf(fp, "%63s%X%X%X%d%d%d%X%d%d%d\n", | ||
726 | name, &dest, &gway, &flags, &refcnt, &use, &metric, &mask, | ||
727 | &mtu, &win, &irtt); | ||
728 | if (nread != 11) { | ||
729 | break; | ||
730 | } | ||
731 | if ((flags & (RTF_UP|RTF_GATEWAY)) == (RTF_UP|RTF_GATEWAY) | ||
732 | && dest == 0 | ||
733 | && strcmp(ifname, name) == 0) { | ||
734 | result = gway; | ||
735 | break; | ||
736 | } | ||
737 | } | ||
738 | fclose(fp); | ||
739 | ifc_close(); | ||
740 | return result; | ||
741 | } | ||
742 | |||
743 | /* | ||
744 | * Sets the specified gateway as the default route for the named interface. | ||
745 | * DEPRECATED | ||
746 | */ | ||
747 | int ifc_set_default_route(const char *ifname, in_addr_t gateway) | ||
748 | { | ||
749 | struct in_addr addr; | ||
750 | int result; | ||
751 | |||
752 | ifc_init(); | ||
753 | addr.s_addr = gateway; | ||
754 | if ((result = ifc_create_default_route(ifname, gateway)) < 0) { | ||
755 | ALOGD("failed to add %s as default route for %s: %s", | ||
756 | inet_ntoa(addr), ifname, strerror(errno)); | ||
757 | } | ||
758 | ifc_close(); | ||
759 | return result; | ||
760 | } | ||
761 | |||
762 | /* | ||
763 | * Removes the default route for the named interface. | 610 | * Removes the default route for the named interface. |
764 | */ | 611 | */ |
765 | int ifc_remove_default_route(const char *ifname) | 612 | int ifc_remove_default_route(const char *ifname) |
@@ -821,151 +668,3 @@ ifc_configure(const char *ifname, | |||
821 | 668 | ||
822 | return 0; | 669 | return 0; |
823 | } | 670 | } |
824 | |||
825 | int ifc_act_on_ipv6_route(int action, const char *ifname, struct in6_addr dst, int prefix_length, | ||
826 | struct in6_addr gw) | ||
827 | { | ||
828 | struct in6_rtmsg rtmsg; | ||
829 | int result; | ||
830 | int ifindex; | ||
831 | |||
832 | memset(&rtmsg, 0, sizeof(rtmsg)); | ||
833 | |||
834 | ifindex = if_nametoindex(ifname); | ||
835 | if (ifindex == 0) { | ||
836 | printerr("if_nametoindex() failed: interface %s\n", ifname); | ||
837 | return -ENXIO; | ||
838 | } | ||
839 | |||
840 | rtmsg.rtmsg_ifindex = ifindex; | ||
841 | rtmsg.rtmsg_dst = dst; | ||
842 | rtmsg.rtmsg_dst_len = prefix_length; | ||
843 | rtmsg.rtmsg_flags = RTF_UP; | ||
844 | |||
845 | if (prefix_length == 128) { | ||
846 | rtmsg.rtmsg_flags |= RTF_HOST; | ||
847 | } | ||
848 | |||
849 | if (memcmp(&gw, &in6addr_any, sizeof(in6addr_any))) { | ||
850 | rtmsg.rtmsg_flags |= RTF_GATEWAY; | ||
851 | rtmsg.rtmsg_gateway = gw; | ||
852 | } | ||
853 | |||
854 | ifc_init6(); | ||
855 | |||
856 | if (ifc_ctl_sock6 < 0) { | ||
857 | return -errno; | ||
858 | } | ||
859 | |||
860 | result = ioctl(ifc_ctl_sock6, action, &rtmsg); | ||
861 | if (result < 0) { | ||
862 | if (errno == EEXIST) { | ||
863 | result = 0; | ||
864 | } else { | ||
865 | result = -errno; | ||
866 | } | ||
867 | } | ||
868 | ifc_close6(); | ||
869 | return result; | ||
870 | } | ||
871 | |||
872 | int ifc_act_on_route(int action, const char *ifname, const char *dst, int prefix_length, | ||
873 | const char *gw) | ||
874 | { | ||
875 | int ret = 0; | ||
876 | struct sockaddr_in ipv4_dst, ipv4_gw; | ||
877 | struct sockaddr_in6 ipv6_dst, ipv6_gw; | ||
878 | struct addrinfo hints, *addr_ai, *gw_ai; | ||
879 | |||
880 | memset(&hints, 0, sizeof(hints)); | ||
881 | hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */ | ||
882 | hints.ai_flags = AI_NUMERICHOST; | ||
883 | |||
884 | ret = getaddrinfo(dst, NULL, &hints, &addr_ai); | ||
885 | |||
886 | if (ret != 0) { | ||
887 | printerr("getaddrinfo failed: invalid address %s\n", dst); | ||
888 | return -EINVAL; | ||
889 | } | ||
890 | |||
891 | if (gw == NULL || (strlen(gw) == 0)) { | ||
892 | if (addr_ai->ai_family == AF_INET6) { | ||
893 | gw = "::"; | ||
894 | } else if (addr_ai->ai_family == AF_INET) { | ||
895 | gw = "0.0.0.0"; | ||
896 | } | ||
897 | } | ||
898 | |||
899 | if (((addr_ai->ai_family == AF_INET6) && (prefix_length < 0 || prefix_length > 128)) || | ||
900 | ((addr_ai->ai_family == AF_INET) && (prefix_length < 0 || prefix_length > 32))) { | ||
901 | printerr("ifc_add_route: invalid prefix length"); | ||
902 | freeaddrinfo(addr_ai); | ||
903 | return -EINVAL; | ||
904 | } | ||
905 | |||
906 | ret = getaddrinfo(gw, NULL, &hints, &gw_ai); | ||
907 | if (ret != 0) { | ||
908 | printerr("getaddrinfo failed: invalid gateway %s\n", gw); | ||
909 | freeaddrinfo(addr_ai); | ||
910 | return -EINVAL; | ||
911 | } | ||
912 | |||
913 | if (addr_ai->ai_family != gw_ai->ai_family) { | ||
914 | printerr("ifc_add_route: different address families: %s and %s\n", dst, gw); | ||
915 | freeaddrinfo(addr_ai); | ||
916 | freeaddrinfo(gw_ai); | ||
917 | return -EINVAL; | ||
918 | } | ||
919 | |||
920 | if (addr_ai->ai_family == AF_INET6) { | ||
921 | memcpy(&ipv6_dst, addr_ai->ai_addr, sizeof(struct sockaddr_in6)); | ||
922 | memcpy(&ipv6_gw, gw_ai->ai_addr, sizeof(struct sockaddr_in6)); | ||
923 | ret = ifc_act_on_ipv6_route(action, ifname, ipv6_dst.sin6_addr, | ||
924 | prefix_length, ipv6_gw.sin6_addr); | ||
925 | } else if (addr_ai->ai_family == AF_INET) { | ||
926 | memcpy(&ipv4_dst, addr_ai->ai_addr, sizeof(struct sockaddr_in)); | ||
927 | memcpy(&ipv4_gw, gw_ai->ai_addr, sizeof(struct sockaddr_in)); | ||
928 | ret = ifc_act_on_ipv4_route(action, ifname, ipv4_dst.sin_addr, | ||
929 | prefix_length, ipv4_gw.sin_addr); | ||
930 | } else { | ||
931 | printerr("ifc_add_route: getaddrinfo returned un supported address family %d\n", | ||
932 | addr_ai->ai_family); | ||
933 | ret = -EAFNOSUPPORT; | ||
934 | } | ||
935 | |||
936 | freeaddrinfo(addr_ai); | ||
937 | freeaddrinfo(gw_ai); | ||
938 | return ret; | ||
939 | } | ||
940 | |||
941 | /* | ||
942 | * DEPRECATED | ||
943 | */ | ||
944 | int ifc_add_ipv4_route(const char *ifname, struct in_addr dst, int prefix_length, | ||
945 | struct in_addr gw) | ||
946 | { | ||
947 | int i =ifc_act_on_ipv4_route(SIOCADDRT, ifname, dst, prefix_length, gw); | ||
948 | if (DBG) printerr("ifc_add_ipv4_route(%s, xx, %d, xx) = %d", ifname, prefix_length, i); | ||
949 | return i; | ||
950 | } | ||
951 | |||
952 | /* | ||
953 | * DEPRECATED | ||
954 | */ | ||
955 | int ifc_add_ipv6_route(const char *ifname, struct in6_addr dst, int prefix_length, | ||
956 | struct in6_addr gw) | ||
957 | { | ||
958 | return ifc_act_on_ipv6_route(SIOCADDRT, ifname, dst, prefix_length, gw); | ||
959 | } | ||
960 | |||
961 | int ifc_add_route(const char *ifname, const char *dst, int prefix_length, const char *gw) | ||
962 | { | ||
963 | int i = ifc_act_on_route(SIOCADDRT, ifname, dst, prefix_length, gw); | ||
964 | if (DBG) printerr("ifc_add_route(%s, %s, %d, %s) = %d", ifname, dst, prefix_length, gw, i); | ||
965 | return i; | ||
966 | } | ||
967 | |||
968 | int ifc_remove_route(const char *ifname, const char*dst, int prefix_length, const char *gw) | ||
969 | { | ||
970 | return ifc_act_on_route(SIOCDELRT, ifname, dst, prefix_length, gw); | ||
971 | } | ||