diff options
-rw-r--r-- | src/transport/plugin_transport_http.c | 152 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 83 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 76 |
3 files changed, 256 insertions, 55 deletions
diff --git a/src/transport/plugin_transport_http.c b/src/transport/plugin_transport_http.c index 0c859cdbf..362851796 100644 --- a/src/transport/plugin_transport_http.c +++ b/src/transport/plugin_transport_http.c | |||
@@ -464,6 +464,11 @@ struct Plugin | |||
464 | int use_ipv4; | 464 | int use_ipv4; |
465 | 465 | ||
466 | /** | 466 | /** |
467 | * use local addresses? | ||
468 | */ | ||
469 | int use_localaddresses; | ||
470 | |||
471 | /** | ||
467 | * Closure passed by MHD to the mhd_logger function | 472 | * Closure passed by MHD to the mhd_logger function |
468 | */ | 473 | */ |
469 | void * mhd_log; | 474 | void * mhd_log; |
@@ -726,6 +731,44 @@ remove_session (struct HTTP_PeerContext * pc, | |||
726 | return GNUNET_OK; | 731 | return GNUNET_OK; |
727 | } | 732 | } |
728 | 733 | ||
734 | static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) | ||
735 | { | ||
736 | uint32_t res = 0; | ||
737 | int local = GNUNET_NO; | ||
738 | int af = addr->sa_family; | ||
739 | switch (af) | ||
740 | { | ||
741 | case AF_INET: | ||
742 | { | ||
743 | uint32_t netmask = 0x7F000000; | ||
744 | uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr); | ||
745 | res = (address >> 24) ^ (netmask >> 24); | ||
746 | if (res != 0) | ||
747 | local = GNUNET_NO; | ||
748 | else | ||
749 | local = GNUNET_YES; | ||
750 | #if DEBUG_HTTP | ||
751 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
752 | "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); | ||
753 | #endif | ||
754 | break; | ||
755 | } | ||
756 | case AF_INET6: | ||
757 | { | ||
758 | if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) || | ||
759 | IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) | ||
760 | local = GNUNET_YES; | ||
761 | else | ||
762 | local = GNUNET_NO; | ||
763 | #if DEBUG_HTTP | ||
764 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
765 | "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); | ||
766 | #endif | ||
767 | break; | ||
768 | } | ||
769 | } | ||
770 | return local; | ||
771 | } | ||
729 | 772 | ||
730 | /** | 773 | /** |
731 | * Add the IP of our network interface to the list of | 774 | * Add the IP of our network interface to the list of |
@@ -749,40 +792,50 @@ process_interfaces (void *cls, | |||
749 | struct IPv6HttpAddress * t6; | 792 | struct IPv6HttpAddress * t6; |
750 | int af; | 793 | int af; |
751 | 794 | ||
795 | if (plugin->use_localaddresses == GNUNET_NO) | ||
796 | { | ||
797 | if (GNUNET_YES == check_localaddress (addr, addrlen)) | ||
798 | { | ||
799 | #if DEBUG_HTTP | ||
800 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
801 | PROTOCOL_PREFIX, | ||
802 | "Not notifying transport of address `%s' (local address)\n", | ||
803 | GNUNET_a2s (addr, addrlen)); | ||
804 | #endif | ||
805 | return GNUNET_OK; | ||
806 | } | ||
807 | } | ||
808 | |||
752 | 809 | ||
753 | GNUNET_assert(cls !=NULL); | 810 | GNUNET_assert(cls !=NULL); |
754 | af = addr->sa_family; | 811 | af = addr->sa_family; |
755 | if ( (af == AF_INET) && | 812 | if ((af == AF_INET) && |
756 | (plugin->use_ipv4 == GNUNET_YES) && | 813 | (plugin->use_ipv4 == GNUNET_YES) && |
757 | (plugin->bind6_address == NULL) ) | 814 | (plugin->bind6_address == NULL) ) { |
758 | { | 815 | |
759 | struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr; | 816 | struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr; |
760 | t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); | 817 | t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress)); |
761 | /* Not skipping loopback addresses | 818 | // Not skipping loopback addresses |
762 | if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr)) | 819 | |
763 | { | ||
764 | 820 | ||
765 | return GNUNET_OK; | ||
766 | } | ||
767 | */ | ||
768 | t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; | 821 | t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr; |
769 | t4->u_port = htons (plugin->port_inbound); | 822 | t4->u_port = htons (plugin->port_inbound); |
770 | if (plugin->bind4_address != NULL) | 823 | if (plugin->bind4_address != NULL) { |
771 | { | ||
772 | if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) | 824 | if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr))) |
773 | { | 825 | { |
774 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,t4); | 826 | GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head, |
775 | plugin->env->notify_address(plugin->env->cls, | 827 | plugin->ipv4_addr_tail,t4); |
776 | PROTOCOL_PREFIX, | 828 | plugin->env->notify_address(plugin->env->cls, |
777 | t4, sizeof (struct IPv4HttpAddress), | 829 | PROTOCOL_PREFIX, |
778 | GNUNET_TIME_UNIT_FOREVER_REL); | 830 | t4, sizeof (struct IPv4HttpAddress), |
779 | return GNUNET_OK; | 831 | GNUNET_TIME_UNIT_FOREVER_REL); |
780 | } | 832 | return GNUNET_OK; |
781 | GNUNET_free (t4); | 833 | } |
782 | return GNUNET_OK; | 834 | GNUNET_free (t4); |
783 | } | 835 | return GNUNET_OK; |
836 | } | ||
784 | else | 837 | else |
785 | { | 838 | { |
786 | GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, | 839 | GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head, |
787 | plugin->ipv4_addr_tail, | 840 | plugin->ipv4_addr_tail, |
788 | t4); | 841 | t4); |
@@ -791,25 +844,21 @@ process_interfaces (void *cls, | |||
791 | t4, sizeof (struct IPv4HttpAddress), | 844 | t4, sizeof (struct IPv4HttpAddress), |
792 | GNUNET_TIME_UNIT_FOREVER_REL); | 845 | GNUNET_TIME_UNIT_FOREVER_REL); |
793 | return GNUNET_OK; | 846 | return GNUNET_OK; |
794 | } | 847 | } |
795 | } | 848 | } |
796 | else if ( (af == AF_INET6) && | 849 | if ((af == AF_INET6) && |
797 | (plugin->use_ipv6 == GNUNET_YES) && | 850 | (plugin->use_ipv6 == GNUNET_YES) && |
798 | (plugin->bind4_address == NULL) ) | 851 | (plugin->bind4_address == NULL) ) { |
799 | { | 852 | |
800 | struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr; | 853 | struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr; |
801 | if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) | 854 | |
802 | { | ||
803 | return GNUNET_OK; | ||
804 | } | ||
805 | t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); | 855 | t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress)); |
806 | GNUNET_assert(t6 != NULL); | 856 | GNUNET_assert(t6 != NULL); |
807 | if (plugin->bind6_address != NULL) | 857 | |
808 | { | 858 | if (plugin->bind6_address != NULL) { |
809 | if (0 == memcmp(&plugin->bind6_address->sin6_addr, | 859 | if (0 == memcmp(&plugin->bind6_address->sin6_addr, |
810 | &bnd_cmp6, | 860 | &bnd_cmp6, |
811 | sizeof (struct in6_addr))) | 861 | sizeof (struct in6_addr))) { |
812 | { | ||
813 | memcpy (&t6->ipv6_addr, | 862 | memcpy (&t6->ipv6_addr, |
814 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 863 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
815 | sizeof (struct in6_addr)); | 864 | sizeof (struct in6_addr)); |
@@ -821,21 +870,21 @@ process_interfaces (void *cls, | |||
821 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, | 870 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head, |
822 | plugin->ipv6_addr_tail, | 871 | plugin->ipv6_addr_tail, |
823 | t6); | 872 | t6); |
824 | return GNUNET_OK; | 873 | return GNUNET_OK; |
825 | } | 874 | } |
826 | GNUNET_free (t6); | 875 | GNUNET_free (t6); |
827 | return GNUNET_OK; | 876 | return GNUNET_OK; |
828 | } | 877 | } |
829 | memcpy (&t6->ipv6_addr, | 878 | memcpy (&t6->ipv6_addr, |
830 | &((struct sockaddr_in6 *) addr)->sin6_addr, | 879 | &((struct sockaddr_in6 *) addr)->sin6_addr, |
831 | sizeof (struct in6_addr)); | 880 | sizeof (struct in6_addr)); |
832 | t6->u6_port = htons (plugin->port_inbound); | 881 | t6->u6_port = htons (plugin->port_inbound); |
833 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6); | 882 | GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6); |
834 | plugin->env->notify_address(plugin->env->cls, | 883 | plugin->env->notify_address(plugin->env->cls, |
835 | PROTOCOL_PREFIX, | 884 | PROTOCOL_PREFIX, |
836 | t6, sizeof (struct IPv6HttpAddress), | 885 | t6, sizeof (struct IPv6HttpAddress), |
837 | GNUNET_TIME_UNIT_FOREVER_REL); | 886 | GNUNET_TIME_UNIT_FOREVER_REL); |
838 | } | 887 | } |
839 | return GNUNET_OK; | 888 | return GNUNET_OK; |
840 | } | 889 | } |
841 | 890 | ||
@@ -2962,8 +3011,10 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2962 | plugin->env = env; | 3011 | plugin->env = env; |
2963 | plugin->peers = NULL; | 3012 | plugin->peers = NULL; |
2964 | plugin->bind4_address = NULL; | 3013 | plugin->bind4_address = NULL; |
3014 | plugin->bind6_address = NULL; | ||
2965 | plugin->use_ipv6 = GNUNET_YES; | 3015 | plugin->use_ipv6 = GNUNET_YES; |
2966 | plugin->use_ipv4 = GNUNET_YES; | 3016 | plugin->use_ipv4 = GNUNET_YES; |
3017 | plugin->use_localaddresses = GNUNET_NO; | ||
2967 | 3018 | ||
2968 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3019 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
2969 | api->cls = plugin; | 3020 | api->cls = plugin; |
@@ -2992,6 +3043,15 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2992 | plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | 3043 | plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, |
2993 | component_name,"USE_IPv4"); | 3044 | component_name,"USE_IPv4"); |
2994 | } | 3045 | } |
3046 | /* use local addresses? */ | ||
3047 | |||
3048 | if (GNUNET_CONFIGURATION_have_value (env->cfg, | ||
3049 | component_name, "USE_LOCALADDR")) | ||
3050 | { | ||
3051 | plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | ||
3052 | component_name, | ||
3053 | "USE_LOCALADDR"); | ||
3054 | } | ||
2995 | /* Reading port number from config file */ | 3055 | /* Reading port number from config file */ |
2996 | if ((GNUNET_OK != | 3056 | if ((GNUNET_OK != |
2997 | GNUNET_CONFIGURATION_get_value_number (env->cfg, | 3057 | GNUNET_CONFIGURATION_get_value_number (env->cfg, |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 677157194..b500b3a72 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -38,9 +38,9 @@ | |||
38 | #include "gnunet_transport_plugin.h" | 38 | #include "gnunet_transport_plugin.h" |
39 | #include "transport.h" | 39 | #include "transport.h" |
40 | 40 | ||
41 | #define DEBUG_TCP GNUNET_YES | 41 | #define DEBUG_TCP GNUNET_NO |
42 | 42 | ||
43 | #define DEBUG_TCP_NAT GNUNET_NO | 43 | #define DEBUG_TCP_NAT GNUNET_YES |
44 | 44 | ||
45 | /** | 45 | /** |
46 | * How long until we give up on transmitting the welcome message? | 46 | * How long until we give up on transmitting the welcome message? |
@@ -434,6 +434,11 @@ struct Plugin | |||
434 | char *bind_address; | 434 | char *bind_address; |
435 | 435 | ||
436 | /** | 436 | /** |
437 | * use local addresses? | ||
438 | */ | ||
439 | int use_localaddresses; | ||
440 | |||
441 | /** | ||
437 | * List of our IP addresses. | 442 | * List of our IP addresses. |
438 | */ | 443 | */ |
439 | struct LocalAddrList *lal_head; | 444 | struct LocalAddrList *lal_head; |
@@ -2139,6 +2144,45 @@ disconnect_notify (void *cls, | |||
2139 | } | 2144 | } |
2140 | 2145 | ||
2141 | 2146 | ||
2147 | static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) | ||
2148 | { | ||
2149 | uint32_t res = 0; | ||
2150 | int local = GNUNET_NO; | ||
2151 | int af = addr->sa_family; | ||
2152 | switch (af) | ||
2153 | { | ||
2154 | case AF_INET: | ||
2155 | { | ||
2156 | uint32_t netmask = 0x7F000000; | ||
2157 | uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr); | ||
2158 | res = (address >> 24) ^ (netmask >> 24); | ||
2159 | if (res != 0) | ||
2160 | local = GNUNET_NO; | ||
2161 | else | ||
2162 | local = GNUNET_YES; | ||
2163 | #if DEBUG_TCP | ||
2164 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2165 | "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); | ||
2166 | #endif | ||
2167 | break; | ||
2168 | } | ||
2169 | case AF_INET6: | ||
2170 | { | ||
2171 | if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) || | ||
2172 | IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) | ||
2173 | local = GNUNET_YES; | ||
2174 | else | ||
2175 | local = GNUNET_NO; | ||
2176 | #if DEBUG_TCP | ||
2177 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
2178 | "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); | ||
2179 | #endif | ||
2180 | break; | ||
2181 | } | ||
2182 | } | ||
2183 | return local; | ||
2184 | } | ||
2185 | |||
2142 | /** | 2186 | /** |
2143 | * Add the IP of our network interface to the list of | 2187 | * Add the IP of our network interface to the list of |
2144 | * our internal IP addresses. | 2188 | * our internal IP addresses. |
@@ -2169,6 +2213,21 @@ process_interfaces (void *cls, | |||
2169 | 2213 | ||
2170 | af = addr->sa_family; | 2214 | af = addr->sa_family; |
2171 | arg_nat = NULL; | 2215 | arg_nat = NULL; |
2216 | |||
2217 | if (plugin->use_localaddresses == GNUNET_NO) | ||
2218 | { | ||
2219 | if (GNUNET_YES == check_localaddress (addr, addrlen)) | ||
2220 | { | ||
2221 | #if DEBUG_TCP | ||
2222 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, | ||
2223 | "tcp", | ||
2224 | "Not notifying transport of address `%s' (local address)\n", | ||
2225 | GNUNET_a2s (addr, addrlen)); | ||
2226 | #endif | ||
2227 | return GNUNET_OK; | ||
2228 | } | ||
2229 | } | ||
2230 | |||
2172 | switch (af) | 2231 | switch (af) |
2173 | { | 2232 | { |
2174 | case AF_INET: | 2233 | case AF_INET: |
@@ -2254,6 +2313,8 @@ process_interfaces (void *cls, | |||
2254 | GNUNET_break (0); | 2313 | GNUNET_break (0); |
2255 | return GNUNET_OK; | 2314 | return GNUNET_OK; |
2256 | } | 2315 | } |
2316 | if (plugin->adv_port != 0) | ||
2317 | { | ||
2257 | #if DEBUG_TCP | 2318 | #if DEBUG_TCP |
2258 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 2319 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
2259 | "tcp", | 2320 | "tcp", |
@@ -2263,6 +2324,7 @@ process_interfaces (void *cls, | |||
2263 | plugin->env->notify_address (plugin->env->cls, | 2324 | plugin->env->notify_address (plugin->env->cls, |
2264 | "tcp", | 2325 | "tcp", |
2265 | arg, args, GNUNET_TIME_UNIT_FOREVER_REL); | 2326 | arg, args, GNUNET_TIME_UNIT_FOREVER_REL); |
2327 | } | ||
2266 | 2328 | ||
2267 | if (arg_nat != NULL) | 2329 | if (arg_nat != NULL) |
2268 | { | 2330 | { |
@@ -2497,9 +2559,7 @@ tcp_transport_start_nat_server (struct Plugin *plugin) | |||
2497 | #if DEBUG_TCP_NAT | 2559 | #if DEBUG_TCP_NAT |
2498 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 2560 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
2499 | "tcp" | 2561 | "tcp" |
2500 | "Starting %s %s\n", | 2562 | "Starting %s %s\n", "gnunet-nat-server", plugin->internal_address); |
2501 | "gnunet-nat-server", | ||
2502 | plugin->internal_address); | ||
2503 | #endif | 2563 | #endif |
2504 | /* Start the server process */ | 2564 | /* Start the server process */ |
2505 | plugin->server_proc = GNUNET_OS_start_process (NULL, | 2565 | plugin->server_proc = GNUNET_OS_start_process (NULL, |
@@ -2677,7 +2737,7 @@ process_external_ip (void *cls, | |||
2677 | t4.t_port = htons(0); | 2737 | t4.t_port = htons(0); |
2678 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | 2738 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
2679 | "tcp", | 2739 | "tcp", |
2680 | "Notifying transport of address %s:%d\n", | 2740 | "Notifying transport of address %s:%d\n", |
2681 | plugin->external_address, | 2741 | plugin->external_address, |
2682 | 0); | 2742 | 0); |
2683 | } | 2743 | } |
@@ -2748,6 +2808,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2748 | int enable_nat_client; | 2808 | int enable_nat_client; |
2749 | int enable_nat_server; | 2809 | int enable_nat_server; |
2750 | int enable_upnp; | 2810 | int enable_upnp; |
2811 | int use_localaddresses; | ||
2751 | char *internal_address; | 2812 | char *internal_address; |
2752 | char *external_address; | 2813 | char *external_address; |
2753 | char *bind_address; | 2814 | char *bind_address; |
@@ -2899,6 +2960,15 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2899 | return NULL; | 2960 | return NULL; |
2900 | } | 2961 | } |
2901 | 2962 | ||
2963 | use_localaddresses = GNUNET_NO; | ||
2964 | if (GNUNET_CONFIGURATION_have_value (env->cfg, | ||
2965 | "transport-tcp", "USE_LOCALADDR")) | ||
2966 | { | ||
2967 | use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | ||
2968 | "transport-tcp", | ||
2969 | "USE_LOCALADDR"); | ||
2970 | } | ||
2971 | |||
2902 | if (aport == 0) | 2972 | if (aport == 0) |
2903 | aport = bport; | 2973 | aport = bport; |
2904 | if (bport == 0) | 2974 | if (bport == 0) |
@@ -2929,6 +2999,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
2929 | plugin->enable_nat_client = enable_nat_client; | 2999 | plugin->enable_nat_client = enable_nat_client; |
2930 | plugin->enable_nat_server = enable_nat_server; | 3000 | plugin->enable_nat_server = enable_nat_server; |
2931 | plugin->enable_upnp = enable_upnp; | 3001 | plugin->enable_upnp = enable_upnp; |
3002 | plugin->use_localaddresses = use_localaddresses; | ||
2932 | plugin->env = env; | 3003 | plugin->env = env; |
2933 | plugin->lsock = NULL; | 3004 | plugin->lsock = NULL; |
2934 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 3005 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 26644bdd3..8e6deb037 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -52,7 +52,7 @@ | |||
52 | #include "gnunet_transport_plugin.h" | 52 | #include "gnunet_transport_plugin.h" |
53 | #include "transport.h" | 53 | #include "transport.h" |
54 | 54 | ||
55 | #define DEBUG_UDP GNUNET_YES | 55 | #define DEBUG_UDP GNUNET_NO |
56 | 56 | ||
57 | #define MAX_PROBES 20 | 57 | #define MAX_PROBES 20 |
58 | 58 | ||
@@ -463,6 +463,11 @@ struct Plugin | |||
463 | int only_nat_addresses; | 463 | int only_nat_addresses; |
464 | 464 | ||
465 | /** | 465 | /** |
466 | * use local addresses? | ||
467 | */ | ||
468 | int use_localaddresses; | ||
469 | |||
470 | /** | ||
466 | * The process id of the server process (if behind NAT) | 471 | * The process id of the server process (if behind NAT) |
467 | */ | 472 | */ |
468 | struct GNUNET_OS_Process *server_proc; | 473 | struct GNUNET_OS_Process *server_proc; |
@@ -918,6 +923,45 @@ check_local_addr (struct Plugin *plugin, | |||
918 | return GNUNET_SYSERR; | 923 | return GNUNET_SYSERR; |
919 | } | 924 | } |
920 | 925 | ||
926 | static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen) | ||
927 | { | ||
928 | uint32_t res = 0; | ||
929 | int local = GNUNET_NO; | ||
930 | int af = addr->sa_family; | ||
931 | switch (af) | ||
932 | { | ||
933 | case AF_INET: | ||
934 | { | ||
935 | uint32_t netmask = 0x7F000000; | ||
936 | uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr); | ||
937 | res = (address >> 24) ^ (netmask >> 24); | ||
938 | if (res != 0) | ||
939 | local = GNUNET_NO; | ||
940 | else | ||
941 | local = GNUNET_YES; | ||
942 | #if DEBUG_UDP | ||
943 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
944 | "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); | ||
945 | #endif | ||
946 | break; | ||
947 | } | ||
948 | case AF_INET6: | ||
949 | { | ||
950 | if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) || | ||
951 | IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr)) | ||
952 | local = GNUNET_YES; | ||
953 | else | ||
954 | local = GNUNET_NO; | ||
955 | #if DEBUG_UDP | ||
956 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
957 | "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global"); | ||
958 | #endif | ||
959 | break; | ||
960 | } | ||
961 | } | ||
962 | return local; | ||
963 | } | ||
964 | |||
921 | 965 | ||
922 | /** | 966 | /** |
923 | * Add the IP of our network interface to the list of | 967 | * Add the IP of our network interface to the list of |
@@ -941,6 +985,20 @@ process_interfaces (void *cls, | |||
941 | addr_nat = NULL; | 985 | addr_nat = NULL; |
942 | af = addr->sa_family; | 986 | af = addr->sa_family; |
943 | 987 | ||
988 | if (plugin->use_localaddresses == GNUNET_NO) | ||
989 | { | ||
990 | if (GNUNET_YES == check_localaddress (addr, addrlen)) | ||
991 | { | ||
992 | #if DEBUG_UDP | ||
993 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
994 | "udp", | ||
995 | "Not notifying transport of address `%s' (local address)\n", | ||
996 | GNUNET_a2s (addr, addrlen)); | ||
997 | #endif | ||
998 | return GNUNET_OK; | ||
999 | } | ||
1000 | } | ||
1001 | |||
944 | memset(buf, 0, INET6_ADDRSTRLEN); | 1002 | memset(buf, 0, INET6_ADDRSTRLEN); |
945 | if (af == AF_INET) | 1003 | if (af == AF_INET) |
946 | { | 1004 | { |
@@ -1271,7 +1329,7 @@ udp_demultiplexer(struct Plugin *plugin, | |||
1271 | struct MessageQueue *pending_message; | 1329 | struct MessageQueue *pending_message; |
1272 | struct MessageQueue *pending_message_temp; | 1330 | struct MessageQueue *pending_message_temp; |
1273 | uint16_t incoming_port; | 1331 | uint16_t incoming_port; |
1274 | 1332 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; | |
1275 | if (memcmp(sender, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)) == 0) | 1333 | if (memcmp(sender, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)) == 0) |
1276 | { | 1334 | { |
1277 | #if DEBUG_UDP | 1335 | #if DEBUG_UDP |
@@ -1471,12 +1529,13 @@ udp_demultiplexer(struct Plugin *plugin, | |||
1471 | /* If we receive these just ignore! */ | 1529 | /* If we receive these just ignore! */ |
1472 | break; | 1530 | break; |
1473 | default: | 1531 | default: |
1532 | |||
1474 | #if DEBUG_UDP | 1533 | #if DEBUG_UDP |
1475 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 1534 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
1476 | "Sending message type %d to transport!\n", | 1535 | "Sending message type %d to transport!\n", |
1477 | ntohs(currhdr->type)); | 1536 | ntohs(currhdr->type)); |
1478 | #endif | 1537 | #endif |
1479 | struct GNUNET_TRANSPORT_ATS_Information distance[2]; | 1538 | |
1480 | distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); | 1539 | distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE); |
1481 | distance[0].value = htonl (UDP_DIRECT_DISTANCE); | 1540 | distance[0].value = htonl (UDP_DIRECT_DISTANCE); |
1482 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); | 1541 | distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR); |
@@ -2167,6 +2226,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2167 | int behind_nat; | 2226 | int behind_nat; |
2168 | int allow_nat; | 2227 | int allow_nat; |
2169 | int only_nat_addresses; | 2228 | int only_nat_addresses; |
2229 | int use_localaddresses; | ||
2170 | char *internal_address; | 2230 | char *internal_address; |
2171 | char *external_address; | 2231 | char *external_address; |
2172 | struct IPv4UdpAddress v4_address; | 2232 | struct IPv4UdpAddress v4_address; |
@@ -2271,6 +2331,15 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2271 | _("MTU %llu for `%s' is probably too low!\n"), mtu, | 2331 | _("MTU %llu for `%s' is probably too low!\n"), mtu, |
2272 | "UDP"); | 2332 | "UDP"); |
2273 | 2333 | ||
2334 | use_localaddresses = GNUNET_NO; | ||
2335 | if (GNUNET_CONFIGURATION_have_value (env->cfg, | ||
2336 | "transport-udp", "USE_LOCALADDR")) | ||
2337 | { | ||
2338 | use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg, | ||
2339 | "transport-udp", | ||
2340 | "USE_LOCALADDR"); | ||
2341 | } | ||
2342 | |||
2274 | plugin = GNUNET_malloc (sizeof (struct Plugin)); | 2343 | plugin = GNUNET_malloc (sizeof (struct Plugin)); |
2275 | plugin->external_address = external_address; | 2344 | plugin->external_address = external_address; |
2276 | plugin->internal_address = internal_address; | 2345 | plugin->internal_address = internal_address; |
@@ -2279,6 +2348,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
2279 | plugin->allow_nat = allow_nat; | 2348 | plugin->allow_nat = allow_nat; |
2280 | plugin->only_nat_addresses = only_nat_addresses; | 2349 | plugin->only_nat_addresses = only_nat_addresses; |
2281 | plugin->env = env; | 2350 | plugin->env = env; |
2351 | plugin->use_localaddresses = use_localaddresses; | ||
2282 | 2352 | ||
2283 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); | 2353 | api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions)); |
2284 | api->cls = plugin; | 2354 | api->cls = plugin; |