diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2011-05-19 11:37:08 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2011-05-19 11:37:08 +0000 |
commit | 730f86ac0e726c33a8819f7249b16c46fedc7ce3 (patch) | |
tree | 85f1fa56f947e70d1bd0aafd75b25187b1f1e126 /src/transport/plugin_transport_tcp.c | |
parent | 7c0a27c527bb8fc6534568b1e8fca7445c283edf (diff) | |
download | gnunet-730f86ac0e726c33a8819f7249b16c46fedc7ce3.tar.gz gnunet-730f86ac0e726c33a8819f7249b16c46fedc7ce3.zip |
NEW: local addresses are filtered
Diffstat (limited to 'src/transport/plugin_transport_tcp.c')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 83 |
1 files changed, 77 insertions, 6 deletions
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)); |