diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-01-02 19:15:51 +0100 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-01-02 19:15:51 +0100 |
commit | f28533eb5fbd2b8e00bb351eb9fd1da322c70505 (patch) | |
tree | 793b1949dd681414d51ea18c151dd6684efa6b9f /src/nat/gnunet-service-nat.c | |
parent | 1082a8e39e4f3d9b908b14995653ac262f640adb (diff) | |
download | gnunet-f28533eb5fbd2b8e00bb351eb9fd1da322c70505.tar.gz gnunet-f28533eb5fbd2b8e00bb351eb9fd1da322c70505.zip |
preparations for proper manual hole punching support in new NAT API
Diffstat (limited to 'src/nat/gnunet-service-nat.c')
-rw-r--r-- | src/nat/gnunet-service-nat.c | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/src/nat/gnunet-service-nat.c b/src/nat/gnunet-service-nat.c index b547e773a..f432eca18 100644 --- a/src/nat/gnunet-service-nat.c +++ b/src/nat/gnunet-service-nat.c | |||
@@ -28,9 +28,12 @@ | |||
28 | * knowledge about the local network topology. | 28 | * knowledge about the local network topology. |
29 | * | 29 | * |
30 | * TODO: | 30 | * TODO: |
31 | * - test ICMP based NAT traversal | 31 | * - test and document (!) ICMP based NAT traversal |
32 | * - implement manual hole punching support (incl. DNS | ||
33 | * lookup for DynDNS setups!) | ||
32 | * - implement "more" autoconfig: | 34 | * - implement "more" autoconfig: |
33 | * re-work gnunet-nat-server & integrate! | 35 | * re-work gnunet-nat-server & integrate! |
36 | * + test manually punched NAT (how?) | ||
34 | * - implement & test STUN processing to classify NAT; | 37 | * - implement & test STUN processing to classify NAT; |
35 | * basically, open port & try different methods. | 38 | * basically, open port & try different methods. |
36 | * - implement NEW logic for external IP detection | 39 | * - implement NEW logic for external IP detection |
@@ -129,6 +132,16 @@ struct ClientHandle | |||
129 | * Array of addresses used by the service. | 132 | * Array of addresses used by the service. |
130 | */ | 133 | */ |
131 | struct ClientAddress *caddrs; | 134 | struct ClientAddress *caddrs; |
135 | |||
136 | /** | ||
137 | * External DNS name and port given by user due to manual | ||
138 | * hole punching. Special DNS name 'AUTO' is used to indicate | ||
139 | * desire for automatic determination of the external IP | ||
140 | * (instead of DNS or manual configuration, i.e. to be used | ||
141 | * if the IP keeps changing and we have no DynDNS, but we do | ||
142 | * have a hole punched). | ||
143 | */ | ||
144 | char *hole_external; | ||
132 | 145 | ||
133 | /** | 146 | /** |
134 | * What does this client care about? | 147 | * What does this client care about? |
@@ -141,12 +154,6 @@ struct ClientHandle | |||
141 | int natted_address; | 154 | int natted_address; |
142 | 155 | ||
143 | /** | 156 | /** |
144 | * Port we would like as we are configured to use this one for | ||
145 | * advertising (in addition to the one we are binding to). | ||
146 | */ | ||
147 | uint16_t adv_port; | ||
148 | |||
149 | /** | ||
150 | * Number of addresses that this service is bound to. | 157 | * Number of addresses that this service is bound to. |
151 | * Length of the @e caddrs array. | 158 | * Length of the @e caddrs array. |
152 | */ | 159 | */ |
@@ -459,7 +466,14 @@ check_register (void *cls, | |||
459 | GNUNET_break (0); | 466 | GNUNET_break (0); |
460 | return GNUNET_SYSERR; | 467 | return GNUNET_SYSERR; |
461 | } | 468 | } |
462 | } | 469 | off += alen; |
470 | left -= alen; | ||
471 | } | ||
472 | if (left != ntohs (message->hole_external_len)) | ||
473 | { | ||
474 | GNUNET_break (0); | ||
475 | return GNUNET_SYSERR; | ||
476 | } | ||
463 | return GNUNET_OK; | 477 | return GNUNET_OK; |
464 | } | 478 | } |
465 | 479 | ||
@@ -870,36 +884,33 @@ check_notify_client_external_ipv4_change (const struct in_addr *v4, | |||
870 | int add) | 884 | int add) |
871 | { | 885 | { |
872 | struct sockaddr_in sa; | 886 | struct sockaddr_in sa; |
873 | uint16_t port; | 887 | int have_v4; |
874 | uint16_t bport; | ||
875 | 888 | ||
876 | /* (1) check if client cares. */ | 889 | /* (1) check if client cares. */ |
877 | if (! ch->natted_address) | 890 | if (! ch->natted_address) |
878 | return; | 891 | return; |
879 | if (0 == (GNUNET_NAT_RF_ADDRESSES & ch->flags)) | 892 | if (0 == (GNUNET_NAT_RF_ADDRESSES & ch->flags)) |
880 | return; | 893 | return; |
881 | bport = 0; | 894 | have_v4 = GNUNET_NO; |
882 | for (unsigned int i=0;i<ch->num_caddrs;i++) | 895 | for (unsigned int i=0;i<ch->num_caddrs;i++) |
883 | { | 896 | { |
884 | const struct sockaddr_storage *ss = &ch->caddrs[i].ss; | 897 | const struct sockaddr_storage *ss = &ch->caddrs[i].ss; |
885 | 898 | ||
886 | if (AF_INET != ss->ss_family) | 899 | if (AF_INET != ss->ss_family) |
887 | continue; | 900 | continue; |
888 | bport = ntohs (((const struct sockaddr_in *) ss)->sin_port); | 901 | have_v4 = GNUNET_YES; |
902 | break; | ||
889 | } | 903 | } |
890 | if (0 == bport) | 904 | if (GNUNET_NO == have_v4) |
891 | return; /* IPv6-only */ | 905 | return; /* IPv6-only */ |
892 | 906 | ||
893 | /* (2) figure out external port, build sockaddr */ | 907 | /* build address info */ |
894 | port = ch->adv_port; | ||
895 | if (0 == port) | ||
896 | port = bport; | ||
897 | memset (&sa, | 908 | memset (&sa, |
898 | 0, | 909 | 0, |
899 | sizeof (sa)); | 910 | sizeof (sa)); |
900 | sa.sin_family = AF_INET; | 911 | sa.sin_family = AF_INET; |
901 | sa.sin_addr = *v4; | 912 | sa.sin_addr = *v4; |
902 | sa.sin_port = htons (port); | 913 | sa.sin_port = htons (0); |
903 | 914 | ||
904 | /* (3) notify client of change */ | 915 | /* (3) notify client of change */ |
905 | notify_client (is_nat_v4 (v4) | 916 | notify_client (is_nat_v4 (v4) |
@@ -1303,7 +1314,6 @@ handle_register (void *cls, | |||
1303 | "Received REGISTER message from client\n"); | 1314 | "Received REGISTER message from client\n"); |
1304 | ch->flags = message->flags; | 1315 | ch->flags = message->flags; |
1305 | ch->proto = message->proto; | 1316 | ch->proto = message->proto; |
1306 | ch->adv_port = ntohs (message->adv_port); | ||
1307 | ch->num_caddrs = ntohs (message->num_addrs); | 1317 | ch->num_caddrs = ntohs (message->num_addrs); |
1308 | ch->caddrs = GNUNET_new_array (ch->num_caddrs, | 1318 | ch->caddrs = GNUNET_new_array (ch->num_caddrs, |
1309 | struct ClientAddress); | 1319 | struct ClientAddress); |
@@ -1379,6 +1389,11 @@ handle_register (void *cls, | |||
1379 | 1389 | ||
1380 | off += alen; | 1390 | off += alen; |
1381 | } | 1391 | } |
1392 | |||
1393 | ch->hole_external | ||
1394 | = GNUNET_strndup (off, | ||
1395 | ntohs (message->hole_external_len)); | ||
1396 | |||
1382 | /* Actually send IP address list to client */ | 1397 | /* Actually send IP address list to client */ |
1383 | for (struct LocalAddressList *lal = lal_head; | 1398 | for (struct LocalAddressList *lal = lal_head; |
1384 | NULL != lal; | 1399 | NULL != lal; |
@@ -1450,7 +1465,7 @@ notify_clients_stun_change (const struct sockaddr_in *ip, | |||
1450 | if (! ch->natted_address) | 1465 | if (! ch->natted_address) |
1451 | continue; | 1466 | continue; |
1452 | v4 = *ip; | 1467 | v4 = *ip; |
1453 | v4.sin_port = htons (ch->adv_port); | 1468 | v4.sin_port = htons (0); |
1454 | env = GNUNET_MQ_msg_extra (msg, | 1469 | env = GNUNET_MQ_msg_extra (msg, |
1455 | sizeof (v4), | 1470 | sizeof (v4), |
1456 | GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE); | 1471 | GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE); |
@@ -2132,6 +2147,7 @@ client_disconnect_cb (void *cls, | |||
2132 | } | 2147 | } |
2133 | } | 2148 | } |
2134 | GNUNET_free_non_null (ch->caddrs); | 2149 | GNUNET_free_non_null (ch->caddrs); |
2150 | GNUNET_free (ch->hole_external); | ||
2135 | GNUNET_free (ch); | 2151 | GNUNET_free (ch); |
2136 | } | 2152 | } |
2137 | 2153 | ||