aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-02-09 14:27:47 +0000
committerChristian Grothoff <christian@grothoff.org>2015-02-09 14:27:47 +0000
commit336a09367ceb678108a4bd13aeb852d90b8776e5 (patch)
tree76373cce6857d54f5d73bdd2f9dd581b7675a899 /src
parent46f081c90862c65a9953fd5db24f20caf19678e5 (diff)
downloadgnunet-336a09367ceb678108a4bd13aeb852d90b8776e5.tar.gz
gnunet-336a09367ceb678108a4bd13aeb852d90b8776e5.zip
-instantly report addresses during NAT initialization if possible
Diffstat (limited to 'src')
-rw-r--r--src/nat/nat.c54
1 files changed, 23 insertions, 31 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c
index 929ba3f62..444dabe9b 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -245,12 +245,7 @@ struct GNUNET_NAT_Handle
245 /** 245 /**
246 * ID of DynDNS lookup task 246 * ID of DynDNS lookup task
247 */ 247 */
248 struct GNUNET_SCHEDULER_Task * dns_task; 248 struct GNUNET_SCHEDULER_Task *dns_task;
249
250 /**
251 * ID of task to add addresses from bind.
252 */
253 struct GNUNET_SCHEDULER_Task * bind_task;
254 249
255 /** 250 /**
256 * How often do we scan for changes in our IP address from our local 251 * How often do we scan for changes in our IP address from our local
@@ -1032,10 +1027,10 @@ upnp_add (void *cls,
1032 _("Error while running upnp client:\n")); 1027 _("Error while running upnp client:\n"));
1033 1028
1034 //FIXME: convert error code to string 1029 //FIXME: convert error code to string
1035 1030
1036 return; 1031 return;
1037 } 1032 }
1038 1033
1039 if (GNUNET_YES == add_remove) 1034 if (GNUNET_YES == add_remove)
1040 { 1035 {
1041 add_to_address_list (h, LAL_UPNP, addr, addrlen); 1036 add_to_address_list (h, LAL_UPNP, addr, addrlen);
@@ -1111,20 +1106,17 @@ add_minis (struct GNUNET_NAT_Handle *h,
1111/** 1106/**
1112 * Task to add addresses from original bind to set of valid addrs. 1107 * Task to add addresses from original bind to set of valid addrs.
1113 * 1108 *
1114 * @param cls the NAT handle 1109 * @param h the NAT handle
1115 * @param tc scheduler context
1116 */ 1110 */
1117static void 1111static void
1118add_from_bind (void *cls, 1112add_from_bind (struct GNUNET_NAT_Handle *h)
1119 const struct GNUNET_SCHEDULER_TaskContext *tc)
1120{ 1113{
1121 static struct in6_addr any = IN6ADDR_ANY_INIT; 1114 static struct in6_addr any = IN6ADDR_ANY_INIT;
1122 struct GNUNET_NAT_Handle *h = cls; 1115
1123 unsigned int i; 1116 unsigned int i;
1124 struct sockaddr *sa; 1117 struct sockaddr *sa;
1125 const struct sockaddr_in *v4; 1118 const struct sockaddr_in *v4;
1126 1119
1127 h->bind_task = NULL;
1128 for (i = 0; i < h->num_local_addrs; i++) 1120 for (i = 0; i < h->num_local_addrs; i++)
1129 { 1121 {
1130 sa = h->local_addrs[i]; 1122 sa = h->local_addrs[i];
@@ -1138,13 +1130,14 @@ add_from_bind (void *cls,
1138 } 1130 }
1139 v4 = (const struct sockaddr_in *) sa; 1131 v4 = (const struct sockaddr_in *) sa;
1140 if (0 != v4->sin_addr.s_addr) 1132 if (0 != v4->sin_addr.s_addr)
1141 add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, 1133 add_to_address_list (h,
1134 LAL_BINDTO_ADDRESS, sa,
1142 sizeof (struct sockaddr_in)); 1135 sizeof (struct sockaddr_in));
1143 if (h->enable_upnp) 1136 if (h->enable_upnp)
1144 { 1137 {
1145 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1138 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
1146 "Running upnp client for address `%s'\n", 1139 "Running upnp client for address `%s'\n",
1147 GNUNET_a2s (sa,sizeof (struct sockaddr_in))); 1140 GNUNET_a2s (sa,sizeof (struct sockaddr_in)));
1148 add_minis (h, ntohs (v4->sin_port)); 1141 add_minis (h, ntohs (v4->sin_port));
1149 } 1142 }
1150 break; 1143 break;
@@ -1155,9 +1148,12 @@ add_from_bind (void *cls,
1155 break; 1148 break;
1156 } 1149 }
1157 if (0 != 1150 if (0 !=
1158 memcmp (&((const struct sockaddr_in6 *) sa)->sin6_addr, &any, 1151 memcmp (&((const struct sockaddr_in6 *) sa)->sin6_addr,
1152 &any,
1159 sizeof (struct in6_addr))) 1153 sizeof (struct in6_addr)))
1160 add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, 1154 add_to_address_list (h,
1155 LAL_BINDTO_ADDRESS,
1156 sa,
1161 sizeof (struct sockaddr_in6)); 1157 sizeof (struct sockaddr_in6));
1162 break; 1158 break;
1163 default: 1159 default:
@@ -1167,7 +1163,6 @@ add_from_bind (void *cls,
1167} 1163}
1168 1164
1169 1165
1170
1171/** 1166/**
1172 * Attempt to enable port redirection and detect public IP address contacting 1167 * Attempt to enable port redirection and detect public IP address contacting
1173 * UPnP or NAT-PMP routers on the local network. Use addr to specify to which 1168 * UPnP or NAT-PMP routers on the local network. Use addr to specify to which
@@ -1178,7 +1173,7 @@ add_from_bind (void *cls,
1178 * @param is_tcp #GNUNET_YES for TCP, #GNUNET_NO for UDP 1173 * @param is_tcp #GNUNET_YES for TCP, #GNUNET_NO for UDP
1179 * @param adv_port advertised port (port we are either bound to or that our OS 1174 * @param adv_port advertised port (port we are either bound to or that our OS
1180 * locally performs redirection from to our bound port). 1175 * locally performs redirection from to our bound port).
1181 * @param num_addrs number of addresses in 'addrs' 1176 * @param num_addrs number of addresses in @a addrs
1182 * @param addrs the local addresses packets should be redirected to 1177 * @param addrs the local addresses packets should be redirected to
1183 * @param addrlens actual lengths of the addresses 1178 * @param addrlens actual lengths of the addresses
1184 * @param address_callback function to call everytime the public IP address changes 1179 * @param address_callback function to call everytime the public IP address changes
@@ -1192,7 +1187,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1192 uint16_t adv_port, 1187 uint16_t adv_port,
1193 unsigned int num_addrs, 1188 unsigned int num_addrs,
1194 const struct sockaddr **addrs, 1189 const struct sockaddr **addrs,
1195 const socklen_t * addrlens, 1190 const socklen_t *addrlens,
1196 GNUNET_NAT_AddressCallback address_callback, 1191 GNUNET_NAT_AddressCallback address_callback,
1197 GNUNET_NAT_ReversalCallback reversal_callback, 1192 GNUNET_NAT_ReversalCallback reversal_callback,
1198 void *callback_cls) 1193 void *callback_cls)
@@ -1227,7 +1222,6 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1227 memcpy (h->local_addrs[i], addrs[i], addrlens[i]); 1222 memcpy (h->local_addrs[i], addrs[i], addrlens[i]);
1228 } 1223 }
1229 } 1224 }
1230 h->bind_task = GNUNET_SCHEDULER_add_now (&add_from_bind, h);
1231 if (GNUNET_OK == 1225 if (GNUNET_OK ==
1232 GNUNET_CONFIGURATION_have_value (cfg, "nat", "INTERNAL_ADDRESS")) 1226 GNUNET_CONFIGURATION_have_value (cfg, "nat", "INTERNAL_ADDRESS"))
1233 { 1227 {
@@ -1343,10 +1337,13 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1343 1337
1344 if (NULL != h->address_callback) 1338 if (NULL != h->address_callback)
1345 { 1339 {
1346 h->ifc_task = GNUNET_SCHEDULER_add_now (&list_interfaces, h); 1340 list_interfaces (h,
1341 NULL);
1347 if (GNUNET_YES == h->use_hostname) 1342 if (GNUNET_YES == h->use_hostname)
1348 h->hostname_task = GNUNET_SCHEDULER_add_now (&resolve_hostname, h); 1343 h->hostname_task = GNUNET_SCHEDULER_add_now (&resolve_hostname,
1344 h);
1349 } 1345 }
1346 add_from_bind (h);
1350 1347
1351 return h; 1348 return h;
1352} 1349}
@@ -1389,11 +1386,6 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h)
1389 GNUNET_SCHEDULER_cancel (h->server_read_task); 1386 GNUNET_SCHEDULER_cancel (h->server_read_task);
1390 h->server_read_task = NULL; 1387 h->server_read_task = NULL;
1391 } 1388 }
1392 if (NULL != h->bind_task)
1393 {
1394 GNUNET_SCHEDULER_cancel (h->bind_task);
1395 h->bind_task = NULL;
1396 }
1397 if (NULL != h->ifc_task) 1389 if (NULL != h->ifc_task)
1398 { 1390 {
1399 GNUNET_SCHEDULER_cancel (h->ifc_task); 1391 GNUNET_SCHEDULER_cancel (h->ifc_task);
@@ -1562,7 +1554,7 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
1562 1554
1563/** 1555/**
1564 * Converts enum GNUNET_NAT_StatusCode to a string 1556 * Converts enum GNUNET_NAT_StatusCode to a string
1565 * 1557 *
1566 * @param err error code to resolve to a string 1558 * @param err error code to resolve to a string
1567 * @return pointer to a static string containing the error code 1559 * @return pointer to a static string containing the error code
1568 */ 1560 */