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_udp.c | |
parent | 7c0a27c527bb8fc6534568b1e8fca7445c283edf (diff) | |
download | gnunet-730f86ac0e726c33a8819f7249b16c46fedc7ce3.tar.gz gnunet-730f86ac0e726c33a8819f7249b16c46fedc7ce3.zip |
NEW: local addresses are filtered
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 76 |
1 files changed, 73 insertions, 3 deletions
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; |