diff options
Diffstat (limited to 'src/include/gnunet_nat_service.h')
-rw-r--r-- | src/include/gnunet_nat_service.h | 407 |
1 files changed, 159 insertions, 248 deletions
diff --git a/src/include/gnunet_nat_service.h b/src/include/gnunet_nat_service.h index 1620c9433..e75845207 100644 --- a/src/include/gnunet_nat_service.h +++ b/src/include/gnunet_nat_service.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2007-2016 GNUnet e.V. | 3 | Copyright (C) 2007-2017 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -123,6 +123,12 @@ enum GNUNET_NAT_AddressClass | |||
123 | GNUNET_NAT_AC_EXTERN = 128, | 123 | GNUNET_NAT_AC_EXTERN = 128, |
124 | 124 | ||
125 | /** | 125 | /** |
126 | * Addresses that were manually configured by the user. | ||
127 | * Used as a bit in combination with #GNUNET_NAT_AC_GLOBAL. | ||
128 | */ | ||
129 | GNUNET_NAT_AC_MANUAL = 256, | ||
130 | |||
131 | /** | ||
126 | * Bitmask for "any" address. | 132 | * Bitmask for "any" address. |
127 | */ | 133 | */ |
128 | GNUNET_NAT_AC_ANY = 65535 | 134 | GNUNET_NAT_AC_ANY = 65535 |
@@ -131,6 +137,144 @@ enum GNUNET_NAT_AddressClass | |||
131 | 137 | ||
132 | 138 | ||
133 | /** | 139 | /** |
140 | * Error Types for the NAT subsystem (which can then later be converted/resolved to a string) | ||
141 | */ | ||
142 | enum GNUNET_NAT_StatusCode | ||
143 | { | ||
144 | /** | ||
145 | * Just the default | ||
146 | */ | ||
147 | GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK, | ||
148 | |||
149 | /** | ||
150 | * IPC Failure | ||
151 | */ | ||
152 | GNUNET_NAT_ERROR_IPC_FAILURE, | ||
153 | |||
154 | /** | ||
155 | * Failure in network subsystem, check permissions | ||
156 | */ | ||
157 | GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, | ||
158 | |||
159 | /** | ||
160 | * test timed out | ||
161 | */ | ||
162 | GNUNET_NAT_ERROR_TIMEOUT, | ||
163 | |||
164 | /** | ||
165 | * detected that we are offline | ||
166 | */ | ||
167 | GNUNET_NAT_ERROR_NOT_ONLINE, | ||
168 | |||
169 | /** | ||
170 | * `upnpc` command not found | ||
171 | */ | ||
172 | GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, | ||
173 | |||
174 | /** | ||
175 | * Failed to run `upnpc` command | ||
176 | */ | ||
177 | GNUNET_NAT_ERROR_UPNPC_FAILED, | ||
178 | |||
179 | /** | ||
180 | * `upnpc' command took too long, process killed | ||
181 | */ | ||
182 | GNUNET_NAT_ERROR_UPNPC_TIMEOUT, | ||
183 | |||
184 | /** | ||
185 | * `upnpc' command failed to establish port mapping | ||
186 | */ | ||
187 | GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, | ||
188 | |||
189 | /** | ||
190 | * `external-ip' command not found | ||
191 | */ | ||
192 | GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, | ||
193 | |||
194 | /** | ||
195 | * Failed to run `external-ip` command | ||
196 | */ | ||
197 | GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, | ||
198 | |||
199 | /** | ||
200 | * `external-ip' command output invalid | ||
201 | */ | ||
202 | GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, | ||
203 | |||
204 | /** | ||
205 | * "no valid address was returned by `external-ip'" | ||
206 | */ | ||
207 | GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, | ||
208 | |||
209 | /** | ||
210 | * Could not determine interface with internal/local network address | ||
211 | */ | ||
212 | GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, | ||
213 | |||
214 | /** | ||
215 | * No working gnunet-helper-nat-server found | ||
216 | */ | ||
217 | GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND, | ||
218 | |||
219 | /** | ||
220 | * NAT test could not be initialized | ||
221 | */ | ||
222 | GNUNET_NAT_ERROR_NAT_TEST_START_FAILED, | ||
223 | |||
224 | /** | ||
225 | * NAT test timeout | ||
226 | */ | ||
227 | GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT, | ||
228 | |||
229 | /** | ||
230 | * NAT test failed to initiate | ||
231 | */ | ||
232 | GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, | ||
233 | |||
234 | /** | ||
235 | * | ||
236 | */ | ||
237 | GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND | ||
238 | |||
239 | }; | ||
240 | |||
241 | |||
242 | |||
243 | /** | ||
244 | * What the situation of the NAT connectivity | ||
245 | */ | ||
246 | enum GNUNET_NAT_Type | ||
247 | { | ||
248 | /** | ||
249 | * We have a direct connection | ||
250 | */ | ||
251 | GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK, | ||
252 | |||
253 | /** | ||
254 | * We are under a NAT but cannot traverse it | ||
255 | */ | ||
256 | GNUNET_NAT_TYPE_UNREACHABLE_NAT, | ||
257 | |||
258 | /** | ||
259 | * We can traverse using STUN | ||
260 | */ | ||
261 | GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, | ||
262 | |||
263 | /** | ||
264 | * We can traverse using UPNP | ||
265 | */ | ||
266 | GNUNET_NAT_TYPE_UPNP_NAT, | ||
267 | |||
268 | /** | ||
269 | * We know nothing about the NAT. | ||
270 | */ | ||
271 | GNUNET_NAT_TYPE_UNKNOWN | ||
272 | |||
273 | }; | ||
274 | |||
275 | |||
276 | |||
277 | /** | ||
134 | * Signature of the callback passed to #GNUNET_NAT_register() for | 278 | * Signature of the callback passed to #GNUNET_NAT_register() for |
135 | * a function to call whenever our set of 'valid' addresses changes. | 279 | * a function to call whenever our set of 'valid' addresses changes. |
136 | * | 280 | * |
@@ -179,8 +323,8 @@ struct GNUNET_NAT_Handle; | |||
179 | * address_callback for any 'plausible' external address. | 323 | * address_callback for any 'plausible' external address. |
180 | * | 324 | * |
181 | * @param cfg configuration to use | 325 | * @param cfg configuration to use |
326 | * @param config_section name of the configuration section for options | ||
182 | * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP | 327 | * @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP |
183 | * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string) | ||
184 | * @param num_addrs number of addresses in @a addrs | 328 | * @param num_addrs number of addresses in @a addrs |
185 | * @param addrs list of local addresses packets should be redirected to | 329 | * @param addrs list of local addresses packets should be redirected to |
186 | * @param addrlens actual lengths of the addresses in @a addrs | 330 | * @param addrlens actual lengths of the addresses in @a addrs |
@@ -192,8 +336,8 @@ struct GNUNET_NAT_Handle; | |||
192 | */ | 336 | */ |
193 | struct GNUNET_NAT_Handle * | 337 | struct GNUNET_NAT_Handle * |
194 | GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, | 338 | GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg, |
339 | const char *config_section, | ||
195 | uint8_t proto, | 340 | uint8_t proto, |
196 | const char *hole_external, | ||
197 | unsigned int num_addrs, | 341 | unsigned int num_addrs, |
198 | const struct sockaddr **addrs, | 342 | const struct sockaddr **addrs, |
199 | const socklen_t *addrlens, | 343 | const socklen_t *addrlens, |
@@ -251,127 +395,6 @@ GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh); | |||
251 | 395 | ||
252 | 396 | ||
253 | /** | 397 | /** |
254 | * Handle to a NAT test. | ||
255 | */ | ||
256 | struct GNUNET_NAT_Test; | ||
257 | |||
258 | |||
259 | /** | ||
260 | * Error Types for the NAT subsystem (which can then later be converted/resolved to a string) | ||
261 | */ | ||
262 | enum GNUNET_NAT_StatusCode | ||
263 | { | ||
264 | /** | ||
265 | * Just the default | ||
266 | */ | ||
267 | GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK, | ||
268 | |||
269 | /** | ||
270 | * IPC Failure | ||
271 | */ | ||
272 | GNUNET_NAT_ERROR_IPC_FAILURE, | ||
273 | |||
274 | /** | ||
275 | * Failure in network subsystem, check permissions | ||
276 | */ | ||
277 | GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, | ||
278 | |||
279 | /** | ||
280 | * test timed out | ||
281 | */ | ||
282 | GNUNET_NAT_ERROR_TIMEOUT, | ||
283 | |||
284 | /** | ||
285 | * detected that we are offline | ||
286 | */ | ||
287 | GNUNET_NAT_ERROR_NOT_ONLINE, | ||
288 | |||
289 | /** | ||
290 | * `upnpc` command not found | ||
291 | */ | ||
292 | GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, | ||
293 | |||
294 | /** | ||
295 | * Failed to run `upnpc` command | ||
296 | */ | ||
297 | GNUNET_NAT_ERROR_UPNPC_FAILED, | ||
298 | |||
299 | /** | ||
300 | * `upnpc' command took too long, process killed | ||
301 | */ | ||
302 | GNUNET_NAT_ERROR_UPNPC_TIMEOUT, | ||
303 | |||
304 | /** | ||
305 | * `upnpc' command failed to establish port mapping | ||
306 | */ | ||
307 | GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, | ||
308 | |||
309 | /** | ||
310 | * `external-ip' command not found | ||
311 | */ | ||
312 | GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, | ||
313 | |||
314 | /** | ||
315 | * Failed to run `external-ip` command | ||
316 | */ | ||
317 | GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, | ||
318 | |||
319 | /** | ||
320 | * `external-ip' command output invalid | ||
321 | */ | ||
322 | GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, | ||
323 | |||
324 | /** | ||
325 | * "no valid address was returned by `external-ip'" | ||
326 | */ | ||
327 | GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, | ||
328 | |||
329 | /** | ||
330 | * Could not determine interface with internal/local network address | ||
331 | */ | ||
332 | GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, | ||
333 | |||
334 | /** | ||
335 | * No working gnunet-helper-nat-server found | ||
336 | */ | ||
337 | GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND, | ||
338 | |||
339 | /** | ||
340 | * NAT test could not be initialized | ||
341 | */ | ||
342 | GNUNET_NAT_ERROR_NAT_TEST_START_FAILED, | ||
343 | |||
344 | /** | ||
345 | * NAT test timeout | ||
346 | */ | ||
347 | GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT, | ||
348 | |||
349 | /** | ||
350 | * NAT test failed to initiate | ||
351 | */ | ||
352 | GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, | ||
353 | |||
354 | /** | ||
355 | * | ||
356 | */ | ||
357 | GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND | ||
358 | |||
359 | }; | ||
360 | |||
361 | |||
362 | /** | ||
363 | * Function called to report success or failure for | ||
364 | * NAT configuration test. | ||
365 | * | ||
366 | * @param cls closure | ||
367 | * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code | ||
368 | */ | ||
369 | typedef void | ||
370 | (*GNUNET_NAT_TestCallback) (void *cls, | ||
371 | enum GNUNET_NAT_StatusCode result); | ||
372 | |||
373 | |||
374 | /** | ||
375 | * Handle an incoming STUN message. This function is useful as | 398 | * Handle an incoming STUN message. This function is useful as |
376 | * some GNUnet service may be listening on a UDP port and might | 399 | * some GNUnet service may be listening on a UDP port and might |
377 | * thus receive STUN messages while trying to receive other data. | 400 | * thus receive STUN messages while trying to receive other data. |
@@ -411,6 +434,18 @@ struct GNUNET_NAT_STUN_Handle; | |||
411 | 434 | ||
412 | 435 | ||
413 | /** | 436 | /** |
437 | * Function called to report success or failure for | ||
438 | * NAT configuration test. | ||
439 | * | ||
440 | * @param cls closure | ||
441 | * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code | ||
442 | */ | ||
443 | typedef void | ||
444 | (*GNUNET_NAT_TestCallback) (void *cls, | ||
445 | enum GNUNET_NAT_StatusCode result); | ||
446 | |||
447 | |||
448 | /** | ||
414 | * Make Generic STUN request. Sends a generic stun request to the | 449 | * Make Generic STUN request. Sends a generic stun request to the |
415 | * server specified using the specified socket. If we do this, | 450 | * server specified using the specified socket. If we do this, |
416 | * we need to watch for possible responses and call | 451 | * we need to watch for possible responses and call |
@@ -442,130 +477,6 @@ void | |||
442 | GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh); | 477 | GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh); |
443 | 478 | ||
444 | 479 | ||
445 | /** | ||
446 | * Start testing if NAT traversal works using the given configuration | ||
447 | * (IPv4-only). The transport adapters should be down while using | ||
448 | * this function. | ||
449 | * | ||
450 | * @param cfg configuration for the NAT traversal | ||
451 | * @param proto protocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP | ||
452 | * @param bind_ip IPv4 address to bind to | ||
453 | * @param bnd_port port to bind to, 0 to test connection reversal | ||
454 | * @param extern_ip IPv4 address to externally advertise | ||
455 | * @param extern_port externally advertised port to use | ||
456 | * @param report function to call with the result of the test | ||
457 | * @param report_cls closure for @a report | ||
458 | * @return handle to cancel NAT test | ||
459 | */ | ||
460 | struct GNUNET_NAT_Test * | ||
461 | GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
462 | uint8_t proto, | ||
463 | struct in_addr bind_ip, | ||
464 | uint16_t bnd_port, | ||
465 | struct in_addr extern_ip, | ||
466 | uint16_t extern_port, | ||
467 | GNUNET_NAT_TestCallback report, | ||
468 | void *report_cls); | ||
469 | |||
470 | |||
471 | /** | ||
472 | * Stop an active NAT test. | ||
473 | * | ||
474 | * @param tst test to stop. | ||
475 | */ | ||
476 | void | ||
477 | GNUNET_NAT_test_stop (struct GNUNET_NAT_Test *tst); | ||
478 | |||
479 | |||
480 | /** | ||
481 | * Handle to auto-configuration in progress. | ||
482 | */ | ||
483 | struct GNUNET_NAT_AutoHandle; | ||
484 | |||
485 | |||
486 | /** | ||
487 | * What the situation of the NAT connectivity | ||
488 | */ | ||
489 | enum GNUNET_NAT_Type | ||
490 | { | ||
491 | /** | ||
492 | * We have a direct connection | ||
493 | */ | ||
494 | GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK, | ||
495 | |||
496 | /** | ||
497 | * We are under a NAT but cannot traverse it | ||
498 | */ | ||
499 | GNUNET_NAT_TYPE_UNREACHABLE_NAT, | ||
500 | |||
501 | /** | ||
502 | * We can traverse using STUN | ||
503 | */ | ||
504 | GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, | ||
505 | |||
506 | /** | ||
507 | * We can traverse using UPNP | ||
508 | */ | ||
509 | GNUNET_NAT_TYPE_UPNP_NAT, | ||
510 | |||
511 | /** | ||
512 | * We know nothing about the NAT. | ||
513 | */ | ||
514 | GNUNET_NAT_TYPE_UNKNOWN | ||
515 | |||
516 | }; | ||
517 | |||
518 | |||
519 | /** | ||
520 | * Converts `enum GNUNET_NAT_StatusCode` to string | ||
521 | * | ||
522 | * @param err error code to resolve to a string | ||
523 | * @return point to a static string containing the error code | ||
524 | */ | ||
525 | const char * | ||
526 | GNUNET_NAT_status2string (enum GNUNET_NAT_StatusCode err); | ||
527 | |||
528 | |||
529 | /** | ||
530 | * Function called with the result from the autoconfiguration. | ||
531 | * | ||
532 | * @param cls closure | ||
533 | * @param diff minimal suggested changes to the original configuration | ||
534 | * to make it work (as best as we can) | ||
535 | * @param result #GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code | ||
536 | * @param type what the situation of the NAT | ||
537 | */ | ||
538 | typedef void | ||
539 | (*GNUNET_NAT_AutoResultCallback)(void *cls, | ||
540 | const struct GNUNET_CONFIGURATION_Handle *diff, | ||
541 | enum GNUNET_NAT_StatusCode result, | ||
542 | enum GNUNET_NAT_Type type); | ||
543 | |||
544 | |||
545 | /** | ||
546 | * Start auto-configuration routine. The transport adapters should | ||
547 | * be stopped while this function is called. | ||
548 | * | ||
549 | * @param cfg initial configuration | ||
550 | * @param cb function to call with autoconfiguration result | ||
551 | * @param cb_cls closure for @a cb | ||
552 | * @return handle to cancel operation | ||
553 | */ | ||
554 | struct GNUNET_NAT_AutoHandle * | ||
555 | GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
556 | GNUNET_NAT_AutoResultCallback cb, | ||
557 | void *cb_cls); | ||
558 | |||
559 | |||
560 | /** | ||
561 | * Abort autoconfiguration. | ||
562 | * | ||
563 | * @param ah handle for operation to abort | ||
564 | */ | ||
565 | void | ||
566 | GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah); | ||
567 | |||
568 | |||
569 | #endif | 480 | #endif |
570 | 481 | ||
571 | /** @} */ /* end of group */ | 482 | /** @} */ /* end of group */ |