diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_nat_service.h | 3 | ||||
-rw-r--r-- | src/nat-auto/nat_auto_api_test.c | 4 | ||||
-rw-r--r-- | src/nat/gnunet-nat.c | 6 | ||||
-rw-r--r-- | src/nat/nat_api.c | 8 | ||||
-rw-r--r-- | src/transport/gnunet-communicator-tcp.c | 51 | ||||
-rw-r--r-- | src/transport/plugin_transport_http_server.c | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 4 |
8 files changed, 73 insertions, 11 deletions
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h index c1e2f0a39..b96b2386e 100644 --- a/src/include/gnunet_nat_service.h +++ b/src/include/gnunet_nat_service.h | |||
@@ -279,6 +279,8 @@ enum GNUNET_NAT_Type | |||
279 | * a function to call whenever our set of 'valid' addresses changes. | 279 | * a function to call whenever our set of 'valid' addresses changes. |
280 | * | 280 | * |
281 | * @param cls closure | 281 | * @param cls closure |
282 | * @param app_ctx[in,out] location where the app can store stuff | ||
283 | * on add and retrieve it on remove | ||
282 | * @param add_remove #GNUNET_YES to add a new public IP address, | 284 | * @param add_remove #GNUNET_YES to add a new public IP address, |
283 | * #GNUNET_NO to remove a previous (now invalid) one | 285 | * #GNUNET_NO to remove a previous (now invalid) one |
284 | * @param ac address class the address belongs to | 286 | * @param ac address class the address belongs to |
@@ -287,6 +289,7 @@ enum GNUNET_NAT_Type | |||
287 | */ | 289 | */ |
288 | typedef void | 290 | typedef void |
289 | (*GNUNET_NAT_AddressCallback) (void *cls, | 291 | (*GNUNET_NAT_AddressCallback) (void *cls, |
292 | void **app_ctx, | ||
290 | int add_remove, | 293 | int add_remove, |
291 | enum GNUNET_NAT_AddressClass ac, | 294 | enum GNUNET_NAT_AddressClass ac, |
292 | const struct sockaddr *addr, | 295 | const struct sockaddr *addr, |
diff --git a/src/nat-auto/nat_auto_api_test.c b/src/nat-auto/nat_auto_api_test.c index 42ce08721..1511d91ba 100644 --- a/src/nat-auto/nat_auto_api_test.c +++ b/src/nat-auto/nat_auto_api_test.c | |||
@@ -357,6 +357,8 @@ mq_error_handler (void *cls, | |||
357 | * Address-callback, used to send message to gnunet-nat-server. | 357 | * Address-callback, used to send message to gnunet-nat-server. |
358 | * | 358 | * |
359 | * @param cls closure | 359 | * @param cls closure |
360 | * @param app_ctx[in,out] location where the app can store stuff | ||
361 | * on add and retrieve it on remove | ||
360 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean | 362 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
361 | * the previous (now invalid) one | 363 | * the previous (now invalid) one |
362 | * @param ac address class the address belongs to | 364 | * @param ac address class the address belongs to |
@@ -365,6 +367,7 @@ mq_error_handler (void *cls, | |||
365 | */ | 367 | */ |
366 | static void | 368 | static void |
367 | addr_cb (void *cls, | 369 | addr_cb (void *cls, |
370 | void **app_ctx, | ||
368 | int add_remove, | 371 | int add_remove, |
369 | enum GNUNET_NAT_AddressClass ac, | 372 | enum GNUNET_NAT_AddressClass ac, |
370 | const struct sockaddr *addr, | 373 | const struct sockaddr *addr, |
@@ -376,6 +379,7 @@ addr_cb (void *cls, | |||
376 | struct GNUNET_NAT_AUTO_TestMessage *msg; | 379 | struct GNUNET_NAT_AUTO_TestMessage *msg; |
377 | const struct sockaddr_in *sa; | 380 | const struct sockaddr_in *sa; |
378 | 381 | ||
382 | (void) app_ctx; | ||
379 | if (GNUNET_YES != add_remove) | 383 | if (GNUNET_YES != add_remove) |
380 | return; | 384 | return; |
381 | if (addrlen != sizeof (struct sockaddr_in)) | 385 | if (addrlen != sizeof (struct sockaddr_in)) |
diff --git a/src/nat/gnunet-nat.c b/src/nat/gnunet-nat.c index 31b6a7268..275553203 100644 --- a/src/nat/gnunet-nat.c +++ b/src/nat/gnunet-nat.c | |||
@@ -110,6 +110,8 @@ test_finished () | |||
110 | * a function to call whenever our set of 'valid' addresses changes. | 110 | * a function to call whenever our set of 'valid' addresses changes. |
111 | * | 111 | * |
112 | * @param cls closure, NULL | 112 | * @param cls closure, NULL |
113 | * @param app_ctx[in,out] location where the app can store stuff | ||
114 | * on add and retrieve it on remove | ||
113 | * @param add_remove #GNUNET_YES to add a new public IP address, | 115 | * @param add_remove #GNUNET_YES to add a new public IP address, |
114 | * #GNUNET_NO to remove a previous (now invalid) one | 116 | * #GNUNET_NO to remove a previous (now invalid) one |
115 | * @param ac address class the address belongs to | 117 | * @param ac address class the address belongs to |
@@ -118,11 +120,15 @@ test_finished () | |||
118 | */ | 120 | */ |
119 | static void | 121 | static void |
120 | address_cb (void *cls, | 122 | address_cb (void *cls, |
123 | void **app_ctx, | ||
121 | int add_remove, | 124 | int add_remove, |
122 | enum GNUNET_NAT_AddressClass ac, | 125 | enum GNUNET_NAT_AddressClass ac, |
123 | const struct sockaddr *addr, | 126 | const struct sockaddr *addr, |
124 | socklen_t addrlen) | 127 | socklen_t addrlen) |
125 | { | 128 | { |
129 | (void) cls; | ||
130 | (void) app_ctx; | ||
131 | |||
126 | fprintf (stdout, | 132 | fprintf (stdout, |
127 | "%s %s (%d)\n", | 133 | "%s %s (%d)\n", |
128 | add_remove ? "+" : "-", | 134 | add_remove ? "+" : "-", |
diff --git a/src/nat/nat_api.c b/src/nat/nat_api.c index 6ae689b63..04fa366aa 100644 --- a/src/nat/nat_api.c +++ b/src/nat/nat_api.c | |||
@@ -49,6 +49,12 @@ struct AddrEntry | |||
49 | struct AddrEntry *prev; | 49 | struct AddrEntry *prev; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Place where the application can store data (on add, | ||
53 | * and retrieve on remove). | ||
54 | */ | ||
55 | void *app_ctx; | ||
56 | |||
57 | /** | ||
52 | * Address class of the address. | 58 | * Address class of the address. |
53 | */ | 59 | */ |
54 | enum GNUNET_NAT_AddressClass ac; | 60 | enum GNUNET_NAT_AddressClass ac; |
@@ -148,6 +154,7 @@ reconnect (struct GNUNET_NAT_Handle *nh) | |||
148 | nh->ae_tail, | 154 | nh->ae_tail, |
149 | ae); | 155 | ae); |
150 | nh->address_callback (nh->callback_cls, | 156 | nh->address_callback (nh->callback_cls, |
157 | &ae->app_ctx, | ||
151 | GNUNET_NO, | 158 | GNUNET_NO, |
152 | ae->ac, | 159 | ae->ac, |
153 | (const struct sockaddr *) &ae[1], | 160 | (const struct sockaddr *) &ae[1], |
@@ -299,6 +306,7 @@ handle_address_change_notification (void *cls, | |||
299 | GNUNET_free (ae); | 306 | GNUNET_free (ae); |
300 | } | 307 | } |
301 | nh->address_callback (nh->callback_cls, | 308 | nh->address_callback (nh->callback_cls, |
309 | &ae->app_ctx, | ||
302 | ntohl (acn->add_remove), | 310 | ntohl (acn->add_remove), |
303 | ac, | 311 | ac, |
304 | sa, | 312 | sa, |
diff --git a/src/transport/gnunet-communicator-tcp.c b/src/transport/gnunet-communicator-tcp.c index 7d52a41db..884fbb0cb 100644 --- a/src/transport/gnunet-communicator-tcp.c +++ b/src/transport/gnunet-communicator-tcp.c | |||
@@ -25,7 +25,8 @@ | |||
25 | * | 25 | * |
26 | * TODO: | 26 | * TODO: |
27 | * - NAT service API change to handle address stops! | 27 | * - NAT service API change to handle address stops! |
28 | * - address construction for HELLOs (FIXMEs, easy) | 28 | * - support NAT connection reversal method |
29 | * - support other TCP-specific NAT traversal methods | ||
29 | */ | 30 | */ |
30 | #include "platform.h" | 31 | #include "platform.h" |
31 | #include "gnunet_util_lib.h" | 32 | #include "gnunet_util_lib.h" |
@@ -1241,9 +1242,17 @@ tcp_address_to_sockaddr (const char *bindto, | |||
1241 | { | 1242 | { |
1242 | /* try IPv6 */ | 1243 | /* try IPv6 */ |
1243 | struct sockaddr_in6 v6; | 1244 | struct sockaddr_in6 v6; |
1245 | const char *start; | ||
1244 | 1246 | ||
1247 | start = cp; | ||
1248 | if ( ('[' == *cp) && | ||
1249 | (']' == cp[strlen (cp)-1]) ) | ||
1250 | { | ||
1251 | start++; /* skip over '[' */ | ||
1252 | cp[strlen (cp) -1] = '\0'; /* eat ']' */ | ||
1253 | } | ||
1245 | if (1 == inet_pton (AF_INET6, | 1254 | if (1 == inet_pton (AF_INET6, |
1246 | cp, | 1255 | start, |
1247 | &v6)) | 1256 | &v6)) |
1248 | { | 1257 | { |
1249 | v6.sin6_port = htons ((uint16_t) port); | 1258 | v6.sin6_port = htons ((uint16_t) port); |
@@ -1574,17 +1583,17 @@ boot_queue (struct Queue *queue, | |||
1574 | { | 1583 | { |
1575 | case AF_INET: | 1584 | case AF_INET: |
1576 | GNUNET_asprintf (&foreign_addr, | 1585 | GNUNET_asprintf (&foreign_addr, |
1577 | "%s-%s:%d", | 1586 | "%s-%s", |
1578 | COMMUNICATOR_ADDRESS_PREFIX, | 1587 | COMMUNICATOR_ADDRESS_PREFIX, |
1579 | "inet-ntop-FIXME", | 1588 | GNUNET_a2s(queue->address, |
1580 | 4242); | 1589 | queue->address_len)); |
1581 | break; | 1590 | break; |
1582 | case AF_INET6: | 1591 | case AF_INET6: |
1583 | GNUNET_asprintf (&foreign_addr, | 1592 | GNUNET_asprintf (&foreign_addr, |
1584 | "%s-%s:%d", | 1593 | "%s-%s", |
1585 | COMMUNICATOR_ADDRESS_PREFIX, | 1594 | COMMUNICATOR_ADDRESS_PREFIX, |
1586 | "inet-ntop-FIXME", | 1595 | GNUNET_a2s(queue->address, |
1587 | 4242); | 1596 | queue->address_len)); |
1588 | break; | 1597 | break; |
1589 | default: | 1598 | default: |
1590 | GNUNET_assert (0); | 1599 | GNUNET_assert (0); |
@@ -2154,6 +2163,8 @@ enc_notify_cb (void *cls, | |||
2154 | * a function to call whenever our set of 'valid' addresses changes. | 2163 | * a function to call whenever our set of 'valid' addresses changes. |
2155 | * | 2164 | * |
2156 | * @param cls closure | 2165 | * @param cls closure |
2166 | * @param app_ctx[in,out] location where the app can store stuff | ||
2167 | * on add and retrieve it on remove | ||
2157 | * @param add_remove #GNUNET_YES to add a new public IP address, | 2168 | * @param add_remove #GNUNET_YES to add a new public IP address, |
2158 | * #GNUNET_NO to remove a previous (now invalid) one | 2169 | * #GNUNET_NO to remove a previous (now invalid) one |
2159 | * @param ac address class the address belongs to | 2170 | * @param ac address class the address belongs to |
@@ -2162,6 +2173,7 @@ enc_notify_cb (void *cls, | |||
2162 | */ | 2173 | */ |
2163 | static void | 2174 | static void |
2164 | nat_address_cb (void *cls, | 2175 | nat_address_cb (void *cls, |
2176 | void **app_ctx, | ||
2165 | int add_remove, | 2177 | int add_remove, |
2166 | enum GNUNET_NAT_AddressClass ac, | 2178 | enum GNUNET_NAT_AddressClass ac, |
2167 | const struct sockaddr *addr, | 2179 | const struct sockaddr *addr, |
@@ -2211,7 +2223,9 @@ run (void *cls, | |||
2211 | char *bindto; | 2223 | char *bindto; |
2212 | struct sockaddr *in; | 2224 | struct sockaddr *in; |
2213 | socklen_t in_len; | 2225 | socklen_t in_len; |
2214 | 2226 | struct sockaddr_storage in_sto; | |
2227 | socklen_t sto_len; | ||
2228 | |||
2215 | (void) cls; | 2229 | (void) cls; |
2216 | cfg = c; | 2230 | cfg = c; |
2217 | if (GNUNET_OK != | 2231 | if (GNUNET_OK != |
@@ -2267,11 +2281,26 @@ run (void *cls, | |||
2267 | GNUNET_free (bindto); | 2281 | GNUNET_free (bindto); |
2268 | return; | 2282 | return; |
2269 | } | 2283 | } |
2284 | /* We might have bound to port 0, allowing the OS to figure it out; | ||
2285 | thus, get the real IN-address from the socket */ | ||
2286 | sto_len = sizeof (in_sto); | ||
2287 | if (0 != getsockname (GNUNET_NETWORK_get_fd (listen_sock), | ||
2288 | (struct sockaddr *) &in_sto, | ||
2289 | &sto_len)) | ||
2290 | { | ||
2291 | memcpy (&in_sto, | ||
2292 | in, | ||
2293 | in_len); | ||
2294 | sto_len = in_len; | ||
2295 | } | ||
2270 | GNUNET_free (in); | 2296 | GNUNET_free (in); |
2297 | GNUNET_free (bindto); | ||
2298 | in = (struct sockaddr *) &in_sto; | ||
2299 | in_len = sto_len; | ||
2271 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 2300 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
2272 | "Bound to `%s'\n", | 2301 | "Bound to `%s'\n", |
2273 | bindto); | 2302 | GNUNET_a2s ((const struct sockaddr *) &in_sto, |
2274 | GNUNET_free (bindto); | 2303 | sto_len)); |
2275 | stats = GNUNET_STATISTICS_create ("C-TCP", | 2304 | stats = GNUNET_STATISTICS_create ("C-TCP", |
2276 | cfg); | 2305 | cfg); |
2277 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, | 2306 | GNUNET_SCHEDULER_add_shutdown (&do_shutdown, |
diff --git a/src/transport/plugin_transport_http_server.c b/src/transport/plugin_transport_http_server.c index c522904d3..495105fe3 100644 --- a/src/transport/plugin_transport_http_server.c +++ b/src/transport/plugin_transport_http_server.c | |||
@@ -2535,6 +2535,8 @@ server_remove_address (void *cls, | |||
2535 | * Our external IP address/port mapping has changed. | 2535 | * Our external IP address/port mapping has changed. |
2536 | * | 2536 | * |
2537 | * @param cls closure, the 'struct LocalAddrList' | 2537 | * @param cls closure, the 'struct LocalAddrList' |
2538 | * @param app_ctx[in,out] location where the app can store stuff | ||
2539 | * on add and retrieve it on remove | ||
2538 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean | 2540 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
2539 | * the previous (now invalid) one | 2541 | * the previous (now invalid) one |
2540 | * @param ac address class the address belongs to | 2542 | * @param ac address class the address belongs to |
@@ -2543,6 +2545,7 @@ server_remove_address (void *cls, | |||
2543 | */ | 2545 | */ |
2544 | static void | 2546 | static void |
2545 | server_nat_port_map_callback (void *cls, | 2547 | server_nat_port_map_callback (void *cls, |
2548 | void **app_ctx, | ||
2546 | int add_remove, | 2549 | int add_remove, |
2547 | enum GNUNET_NAT_AddressClass ac, | 2550 | enum GNUNET_NAT_AddressClass ac, |
2548 | const struct sockaddr *addr, | 2551 | const struct sockaddr *addr, |
@@ -2550,6 +2553,7 @@ server_nat_port_map_callback (void *cls, | |||
2550 | { | 2553 | { |
2551 | struct HTTP_Server_Plugin *plugin = cls; | 2554 | struct HTTP_Server_Plugin *plugin = cls; |
2552 | 2555 | ||
2556 | (void) app_ctx; | ||
2553 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 2557 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
2554 | "NAT called to %s address `%s'\n", | 2558 | "NAT called to %s address `%s'\n", |
2555 | (add_remove == GNUNET_NO) ? "remove" : "add", | 2559 | (add_remove == GNUNET_NO) ? "remove" : "add", |
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index 5afea593f..d93c4423c 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -1430,6 +1430,8 @@ notify_session_monitor (struct Plugin *plugin, | |||
1430 | * Our external IP address/port mapping has changed. | 1430 | * Our external IP address/port mapping has changed. |
1431 | * | 1431 | * |
1432 | * @param cls closure, the `struct Plugin` | 1432 | * @param cls closure, the `struct Plugin` |
1433 | * @param app_ctx[in,out] location where the app can store stuff | ||
1434 | * on add and retrieve it on remove | ||
1433 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean | 1435 | * @param add_remove #GNUNET_YES to mean the new public IP address, #GNUNET_NO to mean |
1434 | * the previous (now invalid) one | 1436 | * the previous (now invalid) one |
1435 | * @param ac address class the address belongs to | 1437 | * @param ac address class the address belongs to |
@@ -1438,6 +1440,7 @@ notify_session_monitor (struct Plugin *plugin, | |||
1438 | */ | 1440 | */ |
1439 | static void | 1441 | static void |
1440 | tcp_nat_port_map_callback (void *cls, | 1442 | tcp_nat_port_map_callback (void *cls, |
1443 | void **app_ctx, | ||
1441 | int add_remove, | 1444 | int add_remove, |
1442 | enum GNUNET_NAT_AddressClass ac, | 1445 | enum GNUNET_NAT_AddressClass ac, |
1443 | const struct sockaddr *addr, | 1446 | const struct sockaddr *addr, |
@@ -1450,6 +1453,7 @@ tcp_nat_port_map_callback (void *cls, | |||
1450 | void *arg; | 1453 | void *arg; |
1451 | size_t args; | 1454 | size_t args; |
1452 | 1455 | ||
1456 | (void) app_ctx; | ||
1453 | LOG (GNUNET_ERROR_TYPE_INFO, | 1457 | LOG (GNUNET_ERROR_TYPE_INFO, |
1454 | "NAT notification to %s address `%s'\n", | 1458 | "NAT notification to %s address `%s'\n", |
1455 | (GNUNET_YES == add_remove) ? "add" : "remove", | 1459 | (GNUNET_YES == add_remove) ? "add" : "remove", |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 30a54cb17..b05192e06 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -1309,6 +1309,8 @@ udp_plugin_check_address (void *cls, | |||
1309 | * Our external IP address/port mapping has changed. | 1309 | * Our external IP address/port mapping has changed. |
1310 | * | 1310 | * |
1311 | * @param cls closure, the `struct Plugin` | 1311 | * @param cls closure, the `struct Plugin` |
1312 | * @param app_ctx[in,out] location where the app can store stuff | ||
1313 | * on add and retrieve it on remove | ||
1312 | * @param add_remove #GNUNET_YES to mean the new public IP address, | 1314 | * @param add_remove #GNUNET_YES to mean the new public IP address, |
1313 | * #GNUNET_NO to mean the previous (now invalid) one | 1315 | * #GNUNET_NO to mean the previous (now invalid) one |
1314 | * @param ac address class the address belongs to | 1316 | * @param ac address class the address belongs to |
@@ -1317,6 +1319,7 @@ udp_plugin_check_address (void *cls, | |||
1317 | */ | 1319 | */ |
1318 | static void | 1320 | static void |
1319 | udp_nat_port_map_callback (void *cls, | 1321 | udp_nat_port_map_callback (void *cls, |
1322 | void **app_ctx, | ||
1320 | int add_remove, | 1323 | int add_remove, |
1321 | enum GNUNET_NAT_AddressClass ac, | 1324 | enum GNUNET_NAT_AddressClass ac, |
1322 | const struct sockaddr *addr, | 1325 | const struct sockaddr *addr, |
@@ -1329,6 +1332,7 @@ udp_nat_port_map_callback (void *cls, | |||
1329 | void *arg; | 1332 | void *arg; |
1330 | size_t args; | 1333 | size_t args; |
1331 | 1334 | ||
1335 | (void) app_ctx; | ||
1332 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1336 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1333 | (GNUNET_YES == add_remove) | 1337 | (GNUNET_YES == add_remove) |
1334 | ? "NAT notification to add address `%s'\n" | 1338 | ? "NAT notification to add address `%s'\n" |