diff options
Diffstat (limited to 'src/transport/plugin_transport_udp.c')
-rw-r--r-- | src/transport/plugin_transport_udp.c | 71 |
1 files changed, 46 insertions, 25 deletions
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 35ae92460..fd8493e5f 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | Copyright (C) 2010-2015 GNUnet e.V. | 3 | Copyright (C) 2010-2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -30,7 +30,7 @@ | |||
30 | #include "gnunet_hello_lib.h" | 30 | #include "gnunet_hello_lib.h" |
31 | #include "gnunet_util_lib.h" | 31 | #include "gnunet_util_lib.h" |
32 | #include "gnunet_fragmentation_lib.h" | 32 | #include "gnunet_fragmentation_lib.h" |
33 | #include "gnunet_nat_lib.h" | 33 | #include "gnunet_nat_service.h" |
34 | #include "gnunet_protocols.h" | 34 | #include "gnunet_protocols.h" |
35 | #include "gnunet_resolver_service.h" | 35 | #include "gnunet_resolver_service.h" |
36 | #include "gnunet_signatures.h" | 36 | #include "gnunet_signatures.h" |
@@ -1245,31 +1245,48 @@ udp_plugin_check_address (void *cls, | |||
1245 | 1245 | ||
1246 | if (sizeof(struct IPv4UdpAddress) == addrlen) | 1246 | if (sizeof(struct IPv4UdpAddress) == addrlen) |
1247 | { | 1247 | { |
1248 | struct sockaddr_in s4; | ||
1249 | |||
1248 | v4 = (const struct IPv4UdpAddress *) addr; | 1250 | v4 = (const struct IPv4UdpAddress *) addr; |
1249 | if (GNUNET_OK != check_port (plugin, | 1251 | if (GNUNET_OK != check_port (plugin, |
1250 | ntohs (v4->u4_port))) | 1252 | ntohs (v4->u4_port))) |
1251 | return GNUNET_SYSERR; | 1253 | return GNUNET_SYSERR; |
1254 | memset (&s4, 0, sizeof (s4)); | ||
1255 | s4.sin_family = AF_INET; | ||
1256 | #if HAVE_SOCKADDR_IN_SIN_LEN | ||
1257 | s4.sin_len = sizeof (s4); | ||
1258 | #endif | ||
1259 | s4.sin_port = v4->u4_port; | ||
1260 | s4.sin_addr.s_addr = v4->ipv4_addr; | ||
1261 | |||
1252 | if (GNUNET_OK != | 1262 | if (GNUNET_OK != |
1253 | GNUNET_NAT_test_address (plugin->nat, | 1263 | GNUNET_NAT_test_address (plugin->nat, |
1254 | &v4->ipv4_addr, | 1264 | &s4, |
1255 | sizeof (struct in_addr))) | 1265 | sizeof (struct sockaddr_in))) |
1256 | return GNUNET_SYSERR; | 1266 | return GNUNET_SYSERR; |
1257 | } | 1267 | } |
1258 | else if (sizeof(struct IPv6UdpAddress) == addrlen) | 1268 | else if (sizeof(struct IPv6UdpAddress) == addrlen) |
1259 | { | 1269 | { |
1270 | struct sockaddr_in6 s6; | ||
1271 | |||
1260 | v6 = (const struct IPv6UdpAddress *) addr; | 1272 | v6 = (const struct IPv6UdpAddress *) addr; |
1261 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) | 1273 | if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr)) |
1262 | { | 1274 | { |
1263 | GNUNET_break_op (0); | 1275 | GNUNET_break_op (0); |
1264 | return GNUNET_SYSERR; | 1276 | return GNUNET_SYSERR; |
1265 | } | 1277 | } |
1266 | if (GNUNET_OK != check_port (plugin, | 1278 | memset (&s6, 0, sizeof (s6)); |
1267 | ntohs (v6->u6_port))) | 1279 | s6.sin6_family = AF_INET6; |
1268 | return GNUNET_SYSERR; | 1280 | #if HAVE_SOCKADDR_IN_SIN_LEN |
1281 | s6.sin6_len = sizeof (s6); | ||
1282 | #endif | ||
1283 | s6.sin6_port = v6->u6_port; | ||
1284 | s6.sin6_addr = v6->ipv6_addr; | ||
1285 | |||
1269 | if (GNUNET_OK != | 1286 | if (GNUNET_OK != |
1270 | GNUNET_NAT_test_address (plugin->nat, | 1287 | GNUNET_NAT_test_address (plugin->nat, |
1271 | &v6->ipv6_addr, | 1288 | &s6, |
1272 | sizeof (struct in6_addr))) | 1289 | sizeof(struct sockaddr_in6))) |
1273 | return GNUNET_SYSERR; | 1290 | return GNUNET_SYSERR; |
1274 | } | 1291 | } |
1275 | else | 1292 | else |
@@ -1287,12 +1304,14 @@ udp_plugin_check_address (void *cls, | |||
1287 | * @param cls closure, the `struct Plugin` | 1304 | * @param cls closure, the `struct Plugin` |
1288 | * @param add_remove #GNUNET_YES to mean the new public IP address, | 1305 | * @param add_remove #GNUNET_YES to mean the new public IP address, |
1289 | * #GNUNET_NO to mean the previous (now invalid) one | 1306 | * #GNUNET_NO to mean the previous (now invalid) one |
1307 | * @param ac address class the address belongs to | ||
1290 | * @param addr either the previous or the new public IP address | 1308 | * @param addr either the previous or the new public IP address |
1291 | * @param addrlen actual length of the @a addr | 1309 | * @param addrlen actual length of the @a addr |
1292 | */ | 1310 | */ |
1293 | static void | 1311 | static void |
1294 | udp_nat_port_map_callback (void *cls, | 1312 | udp_nat_port_map_callback (void *cls, |
1295 | int add_remove, | 1313 | int add_remove, |
1314 | enum GNUNET_NAT_AddressClass ac, | ||
1296 | const struct sockaddr *addr, | 1315 | const struct sockaddr *addr, |
1297 | socklen_t addrlen) | 1316 | socklen_t addrlen) |
1298 | { | 1317 | { |
@@ -1359,6 +1378,7 @@ udp_nat_port_map_callback (void *cls, | |||
1359 | return; | 1378 | return; |
1360 | } | 1379 | } |
1361 | /* modify our published address list */ | 1380 | /* modify our published address list */ |
1381 | /* TODO: use 'ac' here in the future... */ | ||
1362 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, | 1382 | address = GNUNET_HELLO_address_allocate (plugin->env->my_identity, |
1363 | PLUGIN_NAME, | 1383 | PLUGIN_NAME, |
1364 | arg, | 1384 | arg, |
@@ -3032,8 +3052,7 @@ read_process_fragment (struct Plugin *plugin, | |||
3032 | msg)) | 3052 | msg)) |
3033 | { | 3053 | { |
3034 | /* keep this 'rc' from expiring */ | 3054 | /* keep this 'rc' from expiring */ |
3035 | GNUNET_CONTAINER_heap_update_cost (plugin->defrag_ctxs, | 3055 | GNUNET_CONTAINER_heap_update_cost (d_ctx->hnode, |
3036 | d_ctx->hnode, | ||
3037 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); | 3056 | (GNUNET_CONTAINER_HeapCostType) now.abs_value_us); |
3038 | } | 3057 | } |
3039 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > | 3058 | if (GNUNET_CONTAINER_heap_get_size (plugin->defrag_ctxs) > |
@@ -3082,7 +3101,7 @@ udp_select_read (struct Plugin *plugin, | |||
3082 | sizeof(addr)); | 3101 | sizeof(addr)); |
3083 | size = GNUNET_NETWORK_socket_recvfrom (rsock, | 3102 | size = GNUNET_NETWORK_socket_recvfrom (rsock, |
3084 | buf, | 3103 | buf, |
3085 | sizeof(buf), | 3104 | sizeof (buf), |
3086 | (struct sockaddr *) &addr, | 3105 | (struct sockaddr *) &addr, |
3087 | &fromlen); | 3106 | &fromlen); |
3088 | sa = (const struct sockaddr *) &addr; | 3107 | sa = (const struct sockaddr *) &addr; |
@@ -3111,9 +3130,12 @@ udp_select_read (struct Plugin *plugin, | |||
3111 | } | 3130 | } |
3112 | 3131 | ||
3113 | /* Check if this is a STUN packet */ | 3132 | /* Check if this is a STUN packet */ |
3114 | if (GNUNET_NAT_is_valid_stun_packet (plugin->nat, | 3133 | if (GNUNET_NO != |
3115 | (uint8_t *)buf, | 3134 | GNUNET_NAT_stun_handle_packet (plugin->nat, |
3116 | size)) | 3135 | (const struct sockaddr *) &addr, |
3136 | fromlen, | ||
3137 | buf, | ||
3138 | size)) | ||
3117 | return; /* was STUN, do not process further */ | 3139 | return; /* was STUN, do not process further */ |
3118 | 3140 | ||
3119 | if (size < sizeof(struct GNUNET_MessageHeader)) | 3141 | if (size < sizeof(struct GNUNET_MessageHeader)) |
@@ -3516,7 +3538,7 @@ udp_plugin_select_v4 (void *cls) | |||
3516 | { | 3538 | { |
3517 | struct Plugin *plugin = cls; | 3539 | struct Plugin *plugin = cls; |
3518 | const struct GNUNET_SCHEDULER_TaskContext *tc; | 3540 | const struct GNUNET_SCHEDULER_TaskContext *tc; |
3519 | 3541 | ||
3520 | plugin->select_task_v4 = NULL; | 3542 | plugin->select_task_v4 = NULL; |
3521 | if (NULL == plugin->sockv4) | 3543 | if (NULL == plugin->sockv4) |
3522 | return; | 3544 | return; |
@@ -3572,13 +3594,13 @@ udp_plugin_select_v6 (void *cls) | |||
3572 | * @param bind_v4 IPv4 address to bind to (can be NULL, for 'any') | 3594 | * @param bind_v4 IPv4 address to bind to (can be NULL, for 'any') |
3573 | * @return number of sockets that were successfully bound | 3595 | * @return number of sockets that were successfully bound |
3574 | */ | 3596 | */ |
3575 | static int | 3597 | static unsigned int |
3576 | setup_sockets (struct Plugin *plugin, | 3598 | setup_sockets (struct Plugin *plugin, |
3577 | const struct sockaddr_in6 *bind_v6, | 3599 | const struct sockaddr_in6 *bind_v6, |
3578 | const struct sockaddr_in *bind_v4) | 3600 | const struct sockaddr_in *bind_v4) |
3579 | { | 3601 | { |
3580 | int tries; | 3602 | int tries; |
3581 | int sockets_created = 0; | 3603 | unsigned int sockets_created = 0; |
3582 | struct sockaddr_in6 server_addrv6; | 3604 | struct sockaddr_in6 server_addrv6; |
3583 | struct sockaddr_in server_addrv4; | 3605 | struct sockaddr_in server_addrv4; |
3584 | const struct sockaddr *server_addr; | 3606 | const struct sockaddr *server_addr; |
@@ -3788,15 +3810,14 @@ setup_sockets (struct Plugin *plugin, | |||
3788 | schedule_select_v4 (plugin); | 3810 | schedule_select_v4 (plugin); |
3789 | schedule_select_v6 (plugin); | 3811 | schedule_select_v6 (plugin); |
3790 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, | 3812 | plugin->nat = GNUNET_NAT_register (plugin->env->cfg, |
3791 | GNUNET_NO, | 3813 | "transport-udp", |
3792 | plugin->port, | 3814 | IPPROTO_UDP, |
3793 | sockets_created, | 3815 | sockets_created, |
3794 | addrs, | 3816 | addrs, |
3795 | addrlens, | 3817 | addrlens, |
3796 | &udp_nat_port_map_callback, | 3818 | &udp_nat_port_map_callback, |
3797 | NULL, | 3819 | NULL, |
3798 | plugin, | 3820 | plugin); |
3799 | plugin->sockv4); | ||
3800 | return sockets_created; | 3821 | return sockets_created; |
3801 | } | 3822 | } |
3802 | 3823 | ||
@@ -3825,7 +3846,7 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
3825 | struct GNUNET_TIME_Relative interval; | 3846 | struct GNUNET_TIME_Relative interval; |
3826 | struct sockaddr_in server_addrv4; | 3847 | struct sockaddr_in server_addrv4; |
3827 | struct sockaddr_in6 server_addrv6; | 3848 | struct sockaddr_in6 server_addrv6; |
3828 | int res; | 3849 | unsigned int res; |
3829 | int have_bind4; | 3850 | int have_bind4; |
3830 | int have_bind6; | 3851 | int have_bind6; |
3831 | 3852 | ||