diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-07-04 09:01:40 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-07-04 09:01:40 +0000 |
commit | 169dde4f40fc2f04fa42168e2f931a7736cb95ff (patch) | |
tree | d51e4a63d5de5ab123a94889a1dae1024644b604 /src/nat/nat.c | |
parent | 4e36d4760a9c9e188ac06b229f2b693e5cc1a8e7 (diff) | |
download | gnunet-169dde4f40fc2f04fa42168e2f931a7736cb95ff.tar.gz gnunet-169dde4f40fc2f04fa42168e2f931a7736cb95ff.zip |
report IP from bind
Diffstat (limited to 'src/nat/nat.c')
-rw-r--r-- | src/nat/nat.c | 67 |
1 files changed, 66 insertions, 1 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c index b8c62739e..4642179e1 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -80,6 +80,11 @@ enum LocalAddressSource | |||
80 | * and taking their address (no DNS involved). | 80 | * and taking their address (no DNS involved). |
81 | */ | 81 | */ |
82 | LAL_INTERFACE_ADDRESS, | 82 | LAL_INTERFACE_ADDRESS, |
83 | |||
84 | /** | ||
85 | * Addresses we were explicitly bound to. | ||
86 | */ | ||
87 | LAL_BINDTO_ADDRESS, | ||
83 | 88 | ||
84 | /* TODO: add UPnP, etc. */ | 89 | /* TODO: add UPnP, etc. */ |
85 | 90 | ||
@@ -205,6 +210,11 @@ struct GNUNET_NAT_Handle | |||
205 | GNUNET_SCHEDULER_TaskIdentifier dns_task; | 210 | GNUNET_SCHEDULER_TaskIdentifier dns_task; |
206 | 211 | ||
207 | /** | 212 | /** |
213 | * ID of task to add addresses from bind. | ||
214 | */ | ||
215 | GNUNET_SCHEDULER_TaskIdentifier bind_task; | ||
216 | |||
217 | /** | ||
208 | * How often do we scan for changes in our IP address from our local | 218 | * How often do we scan for changes in our IP address from our local |
209 | * interfaces? | 219 | * interfaces? |
210 | */ | 220 | */ |
@@ -1029,6 +1039,55 @@ resolve_dns (void *cls, | |||
1029 | 1039 | ||
1030 | 1040 | ||
1031 | /** | 1041 | /** |
1042 | * Task to add addresses from original bind to set of valid addrs. | ||
1043 | * | ||
1044 | * @param cls the NAT handle | ||
1045 | * @param tc scheduler context | ||
1046 | */ | ||
1047 | static void | ||
1048 | add_from_bind (void *cls, | ||
1049 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1050 | { | ||
1051 | static struct in6_addr any = IN6ADDR_ANY_INIT; | ||
1052 | struct GNUNET_NAT_Handle *h = cls; | ||
1053 | unsigned int i; | ||
1054 | struct sockaddr *sa; | ||
1055 | |||
1056 | h->bind_task = GNUNET_SCHEDULER_NO_TASK; | ||
1057 | for (i=0;i<h->num_local_addrs;i++) | ||
1058 | { | ||
1059 | sa = h->local_addrs[i]; | ||
1060 | switch (sa->sa_family) | ||
1061 | { | ||
1062 | case AF_INET: | ||
1063 | if (sizeof (struct sockaddr_in) != h->local_addrlens[i]) | ||
1064 | { | ||
1065 | GNUNET_break (0); | ||
1066 | break; | ||
1067 | } | ||
1068 | if (0 != ((const struct sockaddr_in*) sa)->sin_addr.s_addr) | ||
1069 | add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, sizeof (struct sockaddr_in)); | ||
1070 | break; | ||
1071 | case AF_INET6: | ||
1072 | if (sizeof (struct sockaddr_in6) != h->local_addrlens[i]) | ||
1073 | { | ||
1074 | GNUNET_break (0); | ||
1075 | break; | ||
1076 | } | ||
1077 | if (0 != memcmp (&((const struct sockaddr_in6*) sa)->sin6_addr, | ||
1078 | &any, | ||
1079 | sizeof (struct in6_addr))) | ||
1080 | add_to_address_list (h, LAL_BINDTO_ADDRESS, sa, sizeof (struct sockaddr_in6)); | ||
1081 | break; | ||
1082 | default: | ||
1083 | break; | ||
1084 | } | ||
1085 | } | ||
1086 | } | ||
1087 | |||
1088 | |||
1089 | |||
1090 | /** | ||
1032 | * Attempt to enable port redirection and detect public IP address contacting | 1091 | * Attempt to enable port redirection and detect public IP address contacting |
1033 | * UPnP or NAT-PMP routers on the local network. Use addr to specify to which | 1092 | * UPnP or NAT-PMP routers on the local network. Use addr to specify to which |
1034 | * of the local host's addresses should the external port be mapped. The port | 1093 | * of the local host's addresses should the external port be mapped. The port |
@@ -1087,7 +1146,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1087 | memcpy (h->local_addrs[i], addrs[i], addrlens[i]); | 1146 | memcpy (h->local_addrs[i], addrs[i], addrlens[i]); |
1088 | } | 1147 | } |
1089 | } | 1148 | } |
1090 | 1149 | h->bind_task = GNUNET_SCHEDULER_add_now (&add_from_bind, h); | |
1091 | if (GNUNET_OK == | 1150 | if (GNUNET_OK == |
1092 | GNUNET_CONFIGURATION_have_value (cfg, | 1151 | GNUNET_CONFIGURATION_have_value (cfg, |
1093 | "nat", | 1152 | "nat", |
@@ -1218,6 +1277,7 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1218 | if (GNUNET_YES == h->use_hostname) | 1277 | if (GNUNET_YES == h->use_hostname) |
1219 | h->hostname_task = GNUNET_SCHEDULER_add_now (&resolve_hostname, h); | 1278 | h->hostname_task = GNUNET_SCHEDULER_add_now (&resolve_hostname, h); |
1220 | } | 1279 | } |
1280 | |||
1221 | return h; | 1281 | return h; |
1222 | } | 1282 | } |
1223 | 1283 | ||
@@ -1249,6 +1309,11 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h) | |||
1249 | GNUNET_SCHEDULER_cancel (h->server_read_task); | 1309 | GNUNET_SCHEDULER_cancel (h->server_read_task); |
1250 | h->server_read_task = GNUNET_SCHEDULER_NO_TASK; | 1310 | h->server_read_task = GNUNET_SCHEDULER_NO_TASK; |
1251 | } | 1311 | } |
1312 | if (GNUNET_SCHEDULER_NO_TASK != h->bind_task) | ||
1313 | { | ||
1314 | GNUNET_SCHEDULER_cancel (h->bind_task); | ||
1315 | h->bind_task = GNUNET_SCHEDULER_NO_TASK; | ||
1316 | } | ||
1252 | if (GNUNET_SCHEDULER_NO_TASK != h->ifc_task) | 1317 | if (GNUNET_SCHEDULER_NO_TASK != h->ifc_task) |
1253 | { | 1318 | { |
1254 | GNUNET_SCHEDULER_cancel (h->ifc_task); | 1319 | GNUNET_SCHEDULER_cancel (h->ifc_task); |