aboutsummaryrefslogtreecommitdiff
path: root/src/nat
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-06-26 22:26:57 +0000
committerChristian Grothoff <christian@grothoff.org>2011-06-26 22:26:57 +0000
commit1791f39fa6dc0bc37d14af98a0684fe1a23fc697 (patch)
tree66b33b772226f77289f669e6d9e4afa03b42a22b /src/nat
parent8a3016481ba6aeb36de3950a56e641dda53ca544 (diff)
downloadgnunet-1791f39fa6dc0bc37d14af98a0684fe1a23fc697.tar.gz
gnunet-1791f39fa6dc0bc37d14af98a0684fe1a23fc697.zip
partial fix of the NAT troubles
Diffstat (limited to 'src/nat')
-rw-r--r--src/nat/nat.c43
1 files changed, 40 insertions, 3 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c
index e92f57259..99d2bbc7c 100644
--- a/src/nat/nat.c
+++ b/src/nat/nat.c
@@ -178,6 +178,11 @@ struct GNUNET_NAT_Handle
178 GNUNET_SCHEDULER_TaskIdentifier server_read_task; 178 GNUNET_SCHEDULER_TaskIdentifier server_read_task;
179 179
180 /** 180 /**
181 * ID of interface IP-scan task
182 */
183 GNUNET_SCHEDULER_TaskIdentifier ifc_task;
184
185 /**
181 * The process id of the server process (if behind NAT) 186 * The process id of the server process (if behind NAT)
182 */ 187 */
183 struct GNUNET_OS_Process *server_proc; 188 struct GNUNET_OS_Process *server_proc;
@@ -857,6 +862,27 @@ start_gnunet_nat_server (struct GNUNET_NAT_Handle *h)
857 862
858 863
859/** 864/**
865 * Task to scan the local network interfaces for IP addresses.
866 *
867 * @param cls the NAT handle
868 * @param tc scheduler context
869 */
870static void
871list_interfaces (void *cls,
872 const struct GNUNET_SCHEDULER_TaskContext *tc)
873{
874 struct GNUNET_NAT_Handle *h = cls;
875
876 h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
877 GNUNET_OS_network_interfaces_list (&process_interfaces, h);
878#if 0
879 h->ifc_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FIXME,
880 &list_interfaces, h);
881#endif
882}
883
884
885/**
860 * Attempt to enable port redirection and detect public IP address contacting 886 * Attempt to enable port redirection and detect public IP address contacting
861 * UPnP or NAT-PMP routers on the local network. Use addr to specify to which 887 * UPnP or NAT-PMP routers on the local network. Use addr to specify to which
862 * of the local host's addresses should the external port be mapped. The port 888 * of the local host's addresses should the external port be mapped. The port
@@ -889,6 +915,10 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
889 struct in_addr in_addr; 915 struct in_addr in_addr;
890 unsigned int i; 916 unsigned int i;
891 917
918 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
919 "Registered with NAT service at port %u with %u IP bound local addresses\n",
920 (unsigned int) adv_port,
921 num_addrs);
892 h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle)); 922 h = GNUNET_malloc (sizeof (struct GNUNET_NAT_Handle));
893 h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS; 923 h->server_retry_delay = GNUNET_TIME_UNIT_SECONDS;
894 h->cfg = cfg; 924 h->cfg = cfg;
@@ -1016,7 +1046,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
1016 1046
1017 if (NULL != h->address_callback) 1047 if (NULL != h->address_callback)
1018 { 1048 {
1019 GNUNET_OS_network_interfaces_list (&process_interfaces, h); 1049 h->ifc_task = GNUNET_SCHEDULER_add_now (&list_interfaces, h);
1020 h->hostname_dns = GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC, 1050 h->hostname_dns = GNUNET_RESOLVER_hostname_resolve (AF_UNSPEC,
1021 HOSTNAME_RESOLVE_TIMEOUT, 1051 HOSTNAME_RESOLVE_TIMEOUT,
1022 &process_hostname_ip, 1052 &process_hostname_ip,
@@ -1053,6 +1083,11 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h)
1053 GNUNET_SCHEDULER_cancel (h->server_read_task); 1083 GNUNET_SCHEDULER_cancel (h->server_read_task);
1054 h->server_read_task = GNUNET_SCHEDULER_NO_TASK; 1084 h->server_read_task = GNUNET_SCHEDULER_NO_TASK;
1055 } 1085 }
1086 if (GNUNET_SCHEDULER_NO_TASK != h->ifc_task)
1087 {
1088 GNUNET_SCHEDULER_cancel (h->ifc_task);
1089 h->ifc_task = GNUNET_SCHEDULER_NO_TASK;
1090 }
1056 if (NULL != h->server_proc) 1091 if (NULL != h->server_proc)
1057 { 1092 {
1058 if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM)) 1093 if (0 != GNUNET_OS_process_kill (h->server_proc, SIGTERM))
@@ -1172,7 +1207,7 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
1172 struct LocalAddressList *pos; 1207 struct LocalAddressList *pos;
1173 const struct sockaddr_in *in4; 1208 const struct sockaddr_in *in4;
1174 const struct sockaddr_in6 *in6; 1209 const struct sockaddr_in6 *in6;
1175 1210
1176 if ( (addrlen != sizeof (struct in_addr)) && 1211 if ( (addrlen != sizeof (struct in_addr)) &&
1177 (addrlen != sizeof (struct in6_addr)) ) 1212 (addrlen != sizeof (struct in6_addr)) )
1178 { 1213 {
@@ -1202,7 +1237,9 @@ GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *h,
1202 } 1237 }
1203 pos = pos->next; 1238 pos = pos->next;
1204 } 1239 }
1205 return GNUNET_YES; 1240 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1241 "Asked to validate one of my addresses and validation failed!\n");
1242 return GNUNET_NO;
1206} 1243}
1207 1244
1208 1245