diff options
author | Christian Grothoff <christian@grothoff.org> | 2015-10-07 10:11:29 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2015-10-07 10:11:29 +0000 |
commit | 6c83690184e6f258e61d8187ad5999f4f87f2e49 (patch) | |
tree | e64f62d92cd88b0fe5e663b1671934bd8f45f778 /src/nat/nat.c | |
parent | c787d89df7c64eceb6145b0a8847736641ea73ca (diff) | |
download | gnunet-6c83690184e6f258e61d8187ad5999f4f87f2e49.tar.gz gnunet-6c83690184e6f258e61d8187ad5999f4f87f2e49.zip |
enable clean up of NAT STUN state, prevents test_plugin_udp from segfaulting
Diffstat (limited to 'src/nat/nat.c')
-rw-r--r-- | src/nat/nat.c | 74 |
1 files changed, 45 insertions, 29 deletions
diff --git a/src/nat/nat.c b/src/nat/nat.c index 3573ec497..b0ec4fe19 100644 --- a/src/nat/nat.c +++ b/src/nat/nat.c | |||
@@ -270,17 +270,17 @@ struct GNUNET_NAT_Handle | |||
270 | /** | 270 | /** |
271 | * ID of select gnunet-helper-nat-server stdout read task | 271 | * ID of select gnunet-helper-nat-server stdout read task |
272 | */ | 272 | */ |
273 | struct GNUNET_SCHEDULER_Task * server_read_task; | 273 | struct GNUNET_SCHEDULER_Task *server_read_task; |
274 | 274 | ||
275 | /** | 275 | /** |
276 | * ID of interface IP-scan task | 276 | * ID of interface IP-scan task |
277 | */ | 277 | */ |
278 | struct GNUNET_SCHEDULER_Task * ifc_task; | 278 | struct GNUNET_SCHEDULER_Task *ifc_task; |
279 | 279 | ||
280 | /** | 280 | /** |
281 | * ID of hostname DNS lookup task | 281 | * ID of hostname DNS lookup task |
282 | */ | 282 | */ |
283 | struct GNUNET_SCHEDULER_Task * hostname_task; | 283 | struct GNUNET_SCHEDULER_Task *hostname_task; |
284 | 284 | ||
285 | /** | 285 | /** |
286 | * ID of DynDNS lookup task | 286 | * ID of DynDNS lookup task |
@@ -288,6 +288,11 @@ struct GNUNET_NAT_Handle | |||
288 | struct GNUNET_SCHEDULER_Task *dns_task; | 288 | struct GNUNET_SCHEDULER_Task *dns_task; |
289 | 289 | ||
290 | /** | 290 | /** |
291 | * Active STUN request, if any. | ||
292 | */ | ||
293 | struct GNUNET_NAT_STUN_Handle *stun_request; | ||
294 | |||
295 | /** | ||
291 | * How often do we scan for changes in our IP address from our local | 296 | * How often do we scan for changes in our IP address from our local |
292 | * interfaces? | 297 | * interfaces? |
293 | */ | 298 | */ |
@@ -1109,12 +1114,11 @@ list_interfaces (void *cls, | |||
1109 | } | 1114 | } |
1110 | 1115 | ||
1111 | 1116 | ||
1112 | |||
1113 | /** | 1117 | /** |
1114 | * Callback if the STun request have a error | 1118 | * Callback with the result from the STUN request. |
1115 | * | 1119 | * |
1116 | * @param cls the NAT handle | 1120 | * @param cls the NAT handle |
1117 | * @param result , the status | 1121 | * @param result the status |
1118 | */ | 1122 | */ |
1119 | static void | 1123 | static void |
1120 | stun_request_callback (void *cls, | 1124 | stun_request_callback (void *cls, |
@@ -1122,14 +1126,15 @@ stun_request_callback (void *cls, | |||
1122 | { | 1126 | { |
1123 | struct GNUNET_NAT_Handle *h = cls; | 1127 | struct GNUNET_NAT_Handle *h = cls; |
1124 | 1128 | ||
1125 | if (NULL == h) | 1129 | h->stun_request = NULL; |
1126 | return; | 1130 | if (GNUNET_NAT_ERROR_SUCCESS != result) |
1127 | h->waiting_stun = GNUNET_NO; | ||
1128 | |||
1129 | if(result != GNUNET_OK) | ||
1130 | { | 1131 | { |
1131 | LOG (GNUNET_ERROR_TYPE_WARNING, | 1132 | LOG (GNUNET_ERROR_TYPE_WARNING, |
1132 | "Error processing a STUN request"); | 1133 | "Error processing a STUN request"); |
1134 | } | ||
1135 | else | ||
1136 | { | ||
1137 | h->waiting_stun = GNUNET_YES; | ||
1133 | } | 1138 | } |
1134 | } | 1139 | } |
1135 | 1140 | ||
@@ -1153,7 +1158,7 @@ GNUNET_NAT_is_valid_stun_packet (void *cls, | |||
1153 | struct sockaddr_in answer; | 1158 | struct sockaddr_in answer; |
1154 | 1159 | ||
1155 | /* We are not expecting a STUN message */ | 1160 | /* We are not expecting a STUN message */ |
1156 | if (! h->waiting_stun) | 1161 | if (GNUNET_YES != h->waiting_stun) |
1157 | return GNUNET_NO; | 1162 | return GNUNET_NO; |
1158 | 1163 | ||
1159 | /* We dont have STUN installed */ | 1164 | /* We dont have STUN installed */ |
@@ -1166,14 +1171,14 @@ GNUNET_NAT_is_valid_stun_packet (void *cls, | |||
1166 | sizeof(struct sockaddr_in)); | 1171 | sizeof(struct sockaddr_in)); |
1167 | 1172 | ||
1168 | /*Lets handle the packet*/ | 1173 | /*Lets handle the packet*/ |
1169 | int valid = GNUNET_NAT_stun_handle_packet (data, | 1174 | if (GNUNET_NO == |
1170 | len, | 1175 | GNUNET_NAT_stun_handle_packet (data, |
1171 | &answer); | 1176 | len, |
1172 | if (! valid) | 1177 | &answer)) |
1173 | return GNUNET_NO; | 1178 | return GNUNET_NO; |
1174 | 1179 | ||
1175 | LOG (GNUNET_ERROR_TYPE_INFO, | 1180 | LOG (GNUNET_ERROR_TYPE_INFO, |
1176 | "Stun server returned %s:%d\n", | 1181 | "STUN server returned %s:%d\n", |
1177 | inet_ntoa (answer.sin_addr), | 1182 | inet_ntoa (answer.sin_addr), |
1178 | ntohs (answer.sin_port)); | 1183 | ntohs (answer.sin_port)); |
1179 | /* Remove old IPs from previous STUN calls */ | 1184 | /* Remove old IPs from previous STUN calls */ |
@@ -1208,16 +1213,19 @@ process_stun (void *cls, | |||
1208 | "I will request the stun server %s:%i\n", | 1213 | "I will request the stun server %s:%i\n", |
1209 | elem->address, | 1214 | elem->address, |
1210 | elem->port); | 1215 | elem->port); |
1211 | if (GNUNET_OK == | 1216 | if (NULL != h->stun_request) |
1212 | GNUNET_NAT_stun_make_request (elem->address, | 1217 | { |
1218 | GNUNET_NAT_stun_make_request_cancel (h->stun_request); | ||
1219 | h->stun_request = NULL; | ||
1220 | } | ||
1221 | h->waiting_stun = GNUNET_NO; | ||
1222 | h->stun_request | ||
1223 | = GNUNET_NAT_stun_make_request (elem->address, | ||
1213 | elem->port, | 1224 | elem->port, |
1214 | h->socket, | 1225 | h->socket, |
1215 | &stun_request_callback, | 1226 | &stun_request_callback, |
1216 | NULL)) | 1227 | h); |
1217 | { | 1228 | if (NULL == h->stun_request) |
1218 | h->waiting_stun = GNUNET_YES; | ||
1219 | } | ||
1220 | else | ||
1221 | { | 1229 | { |
1222 | LOG (GNUNET_ERROR_TYPE_ERROR, | 1230 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1223 | "STUN request to %s:%i failed\n", | 1231 | "STUN request to %s:%i failed\n", |
@@ -1226,7 +1234,8 @@ process_stun (void *cls, | |||
1226 | } | 1234 | } |
1227 | h->stun_task = | 1235 | h->stun_task = |
1228 | GNUNET_SCHEDULER_add_delayed (h->stun_frequency, | 1236 | GNUNET_SCHEDULER_add_delayed (h->stun_frequency, |
1229 | &process_stun, h); | 1237 | &process_stun, |
1238 | h); | ||
1230 | 1239 | ||
1231 | /* Set actual Server*/ | 1240 | /* Set actual Server*/ |
1232 | if (NULL != elem->next) | 1241 | if (NULL != elem->next) |
@@ -1709,7 +1718,6 @@ GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1709 | /* Set the actual STUN server*/ | 1718 | /* Set the actual STUN server*/ |
1710 | h->actual_stun_server = h->stun_servers_head; | 1719 | h->actual_stun_server = h->stun_servers_head; |
1711 | } | 1720 | } |
1712 | |||
1713 | h->stun_task = GNUNET_SCHEDULER_add_now (&process_stun, | 1721 | h->stun_task = GNUNET_SCHEDULER_add_now (&process_stun, |
1714 | h); | 1722 | h); |
1715 | } | 1723 | } |
@@ -1821,10 +1829,18 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *h) | |||
1821 | GNUNET_SCHEDULER_cancel (h->stun_task); | 1829 | GNUNET_SCHEDULER_cancel (h->stun_task); |
1822 | h->stun_task = NULL; | 1830 | h->stun_task = NULL; |
1823 | } | 1831 | } |
1832 | if (NULL != h->stun_request) | ||
1833 | { | ||
1834 | GNUNET_NAT_stun_make_request_cancel (h->stun_request); | ||
1835 | h->stun_request = NULL; | ||
1836 | } | ||
1824 | if (NULL != h->server_proc) | 1837 | if (NULL != h->server_proc) |
1825 | { | 1838 | { |
1826 | if (0 != GNUNET_OS_process_kill (h->server_proc, GNUNET_TERM_SIG)) | 1839 | if (0 != GNUNET_OS_process_kill (h->server_proc, |
1827 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, "nat", "kill"); | 1840 | GNUNET_TERM_SIG)) |
1841 | GNUNET_log_from_strerror (GNUNET_ERROR_TYPE_WARNING, | ||
1842 | "nat", | ||
1843 | "kill"); | ||
1828 | GNUNET_OS_process_wait (h->server_proc); | 1844 | GNUNET_OS_process_wait (h->server_proc); |
1829 | GNUNET_OS_process_destroy (h->server_proc); | 1845 | GNUNET_OS_process_destroy (h->server_proc); |
1830 | h->server_proc = NULL; | 1846 | h->server_proc = NULL; |