#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_resolver_service.h"
#include "gnunet_nat_lib.h"
#include "nat.h"
Go to the source code of this file.
Data Structures | |
struct | GNUNET_NAT_AutoHandle |
Handle to auto-configuration in progress. More... | |
Macros | |
#define | LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__) |
#define | TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
How long do we wait for the NAT test to report success? More... | |
#define | NAT_SERVER_TIMEOUT |
Enumerations | |
enum | AutoPhase { AUTO_INIT = 0 , AUTO_EXTERNAL_IP , AUTO_STUN , AUTO_LOCAL_IP , AUTO_NAT_PUNCHED , AUTO_UPNPC , AUTO_ICMP_SERVER , AUTO_ICMP_CLIENT , AUTO_DONE } |
Phases of the auto configuration. More... | |
Functions | |
static void | next_phase (struct GNUNET_NAT_AutoHandle *ah) |
Run the next phase of the auto test. More... | |
static void | process_stun_reply (struct sockaddr_in *answer, struct GNUNET_NAT_AutoHandle *ah) |
static void | stop_stun () |
Function that terminates the test. More... | |
static void | do_udp_read (void *cls) |
Activity on our incoming socket. More... | |
static struct GNUNET_NETWORK_Handle * | bind_v4 () |
Create an IPv4 listen socket bound to our port. More... | |
static void | request_callback (void *cls, enum GNUNET_NAT_StatusCode result) |
static void | result_callback (void *cls, enum GNUNET_NAT_StatusCode ret) |
Function called by NAT to report the outcome of the nat-test. More... | |
static void | reversal_test (void *cls) |
Main function for the connection reversal test. More... | |
static void | set_external_ipv4 (void *cls, const struct in_addr *addr, enum GNUNET_NAT_StatusCode ret) |
Set our external IPv4 address based on the UPnP. More... | |
static void | test_external_ip (struct GNUNET_NAT_AutoHandle *ah) |
Determine our external IPv4 address. More... | |
static void | test_stun (struct GNUNET_NAT_AutoHandle *ah) |
Determine our external IPv4 address and port using an external STUN server. More... | |
static int | process_if (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen) |
Process list of local IP addresses. More... | |
static void | test_local_ip (struct GNUNET_NAT_AutoHandle *ah) |
Determine our local IP addresses; detect internal IP & IPv6-support. More... | |
static void | mq_error_handler (void *cls, enum GNUNET_MQ_Error error) |
We got disconnected from the NAT server. More... | |
static void | test_nat_punched (struct GNUNET_NAT_AutoHandle *ah) |
Test if NAT has been punched. More... | |
static void | test_upnpc (struct GNUNET_NAT_AutoHandle *ah) |
Test if UPnPC works. More... | |
static void | test_icmp_server (struct GNUNET_NAT_AutoHandle *ah) |
Test if ICMP server is working. More... | |
static void | test_icmp_client (struct GNUNET_NAT_AutoHandle *ah) |
Test if ICMP client is working. More... | |
struct GNUNET_NAT_AutoHandle * | GNUNET_NAT_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NAT_AutoResultCallback cb, void *cb_cls) |
Start auto-configuration routine. More... | |
void | GNUNET_NAT_autoconfig_cancel (struct GNUNET_NAT_AutoHandle *ah) |
Abort autoconfiguration. More... | |
Variables | |
static struct GNUNET_NETWORK_Handle * | lsock4 |
The listen socket of the service for IPv4. More... | |
static struct GNUNET_SCHEDULER_Task * | ltask4 |
The listen task ID for IPv4. More... | |
static unsigned long long | port = 7895 |
The port the test service is running on (default 7895) More... | |
static char * | stun_server = "stun.ekiga.net" |
static unsigned int | stun_port = 3478 |
#define LOG | ( | kind, | |
... | |||
) | GNUNET_log_from (kind, "nat", __VA_ARGS__) |
Definition at line 33 of file gnunet-service-nat-auto_legacy.c.
#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
How long do we wait for the NAT test to report success?
Definition at line 39 of file gnunet-service-nat-auto_legacy.c.
#define NAT_SERVER_TIMEOUT |
Definition at line 41 of file gnunet-service-nat-auto_legacy.c.
enum AutoPhase |
Phases of the auto configuration.
Definition at line 47 of file gnunet-service-nat-auto_legacy.c.
|
static |
Run the next phase of the auto test.
ah | auto test handle |
Definition at line 867 of file gnunet-service-nat-auto_legacy.c.
References ah, AUTO_DONE, AUTO_EXTERNAL_IP, AUTO_ICMP_CLIENT, AUTO_ICMP_SERVER, AUTO_INIT, AUTO_LOCAL_IP, AUTO_NAT_PUNCHED, AUTO_STUN, AUTO_UPNPC, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_assert, GNUNET_CONFIGURATION_destroy(), GNUNET_CONFIGURATION_get_diff(), GNUNET_CONFIGURATION_set_value_number(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAT_autoconfig_cancel(), GNUNET_NAT_TYPE_NO_NAT, GNUNET_NAT_TYPE_STUN_PUNCHED_NAT, GNUNET_NAT_TYPE_UNREACHABLE_NAT, test_external_ip(), test_icmp_client(), test_icmp_server(), test_local_ip(), test_nat_punched(), test_stun(), and test_upnpc().
Referenced by do_udp_read(), GNUNET_NAT_autoconfig_start(), mq_error_handler(), process_stun_reply(), result_callback(), set_external_ipv4(), test_external_ip(), test_icmp_client(), test_icmp_server(), test_local_ip(), test_nat_punched(), test_stun(), and test_upnpc().
|
static |
Definition at line 215 of file gnunet-service-nat-auto_legacy.c.
References ah, GNUNET_ERROR_TYPE_INFO, GNUNET_log, and next_phase().
Referenced by do_udp_read().
|
static |
Function that terminates the test.
Definition at line 232 of file gnunet-service-nat-auto_legacy.c.
References GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), lsock4, and ltask4.
Referenced by do_udp_read(), request_callback(), and test_stun().
|
static |
Activity on our incoming socket.
Read data from the incoming connection.
cls |
Definition at line 258 of file gnunet-service-nat-auto_legacy.c.
References ah, AUTO_NAT_PUNCHED, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_stun_handle_packet(), GNUNET_NETWORK_fdset_isset(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_recv(), GNUNET_OK, GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, GNUNET_YES, lsock4, next_phase(), process_stun_reply(), GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_SCHEDULER_TaskContext::reason, stop_stun(), and tc.
Referenced by test_nat_punched(), and test_stun().
|
static |
Create an IPv4 listen socket bound to our port.
Definition at line 320 of file gnunet-service-nat-auto_legacy.c.
References GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_OK, ls, and port.
Referenced by test_stun().
|
static |
Definition at line 351 of file gnunet-service-nat-auto_legacy.c.
References GNUNET_ERROR_TYPE_INFO, GNUNET_log, and stop_stun().
Referenced by test_stun().
|
static |
Function called by NAT to report the outcome of the nat-test.
Clean up and update GUI.
cls | the auto handle |
success | currently always GNUNET_OK |
emsg | NULL on success, otherwise an error message |
Definition at line 373 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_test_stop(), next_phase(), and ret.
Referenced by reversal_test().
|
static |
Main function for the connection reversal test.
cls | the struct GNUNET_NAT_AutoHandle |
Definition at line 399 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_test_start(), GNUNET_RESOLVER_connect(), GNUNET_YES, result_callback(), and TIMEOUT.
Referenced by test_icmp_server().
|
static |
Set our external IPv4 address based on the UPnP.
cls | closure with our setup context |
addr | the address, NULL on errors |
emsg | NULL on success, otherwise an error message |
Definition at line 421 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_break, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, GNUNET_NAT_ERROR_SUCCESS, GNUNET_YES, next_phase(), and ret.
Referenced by test_external_ip().
|
static |
Determine our external IPv4 address.
ah | auto setup context |
Definition at line 469 of file gnunet-service-nat-auto_legacy.c.
References ah, GNUNET_NAT_ERROR_SUCCESS, next_phase(), set_external_ipv4(), and TIMEOUT.
Referenced by next_phase().
|
static |
Determine our external IPv4 address and port using an external STUN server.
ah | auto setup context |
Definition at line 487 of file gnunet-service-nat-auto_legacy.c.
References ah, bind_v4(), GNUNET_NAT_AUTO_AutoHandle::cfg, do_udp_read(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_log_strerror, GNUNET_NAT_stun_make_request(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_read_net(), lsock4, ltask4, NAT_SERVER_TIMEOUT, next_phase(), port, request_callback(), stop_stun(), stun_port, and stun_server.
Referenced by next_phase().
|
static |
Process list of local IP addresses.
Find and set the one of the default interface.
cls | our struct GNUNET_NAT_AutoHandle |
name | name of the interface (can be NULL for unknown) |
isDefault | is this presumably the default interface |
addr | address of this interface (can be NULL for unknown or unassigned) |
broadcast_addr | the broadcast address (can be NULL for unknown or unassigned) |
netmask | the network mask (can be NULL for unknown or unassigned)) |
addrlen | length of the addr and broadcast_addr |
Definition at line 551 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_break, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_memcmp, GNUNET_NAT_ERROR_SUCCESS, GNUNET_OK, GNUNET_SYSERR, and GNUNET_YES.
Referenced by test_local_ip().
|
static |
Determine our local IP addresses; detect internal IP & IPv6-support.
ah | auto setup context |
Definition at line 622 of file gnunet-service-nat-auto_legacy.c.
References ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, GNUNET_NO, GNUNET_OS_network_interfaces_list(), GNUNET_YES, next_phase(), and process_if().
Referenced by next_phase().
|
static |
We got disconnected from the NAT server.
Stop waiting for a reply.
cls | the struct GNUNET_NAT_AutoHandle |
error | error code |
Definition at line 643 of file gnunet-service-nat-auto_legacy.c.
References ah, GNUNET_MQ_destroy(), GNUNET_NAT_AUTO_AutoHandle::mq, and next_phase().
Referenced by test_nat_punched().
|
static |
Test if NAT has been punched.
ah | auto setup context |
Definition at line 661 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, do_udp_read(), env, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MESSAGE_TYPE_NAT_TEST, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_NO, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), LOG, lsock4, ltask4, GNUNET_NAT_AUTO_AutoHandle::mq, mq_error_handler(), msg, NAT_SERVER_TIMEOUT, next_phase(), and port.
Referenced by next_phase().
|
static |
Test if UPnPC works.
ah | auto setup context |
Definition at line 714 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_set_value_string(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NO, GNUNET_OS_check_helper_binary(), GNUNET_SYSERR, GNUNET_YES, and next_phase().
Referenced by next_phase().
|
static |
Test if ICMP server is working.
ah | auto setup context |
Definition at line 742 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_get_libexec_binary_path(), GNUNET_SCHEDULER_add_now(), GNUNET_YES, next_phase(), and reversal_test().
Referenced by next_phase().
|
static |
Test if ICMP client is working.
ah | auto setup context |
Definition at line 813 of file gnunet-service-nat-auto_legacy.c.
References _, ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_log, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_get_libexec_binary_path(), GNUNET_YES, and next_phase().
Referenced by next_phase().
struct GNUNET_NAT_AutoHandle * GNUNET_NAT_autoconfig_start | ( | const struct GNUNET_CONFIGURATION_Handle * | cfg, |
GNUNET_NAT_AutoResultCallback | cb, | ||
void * | cb_cls | ||
) |
Start auto-configuration routine.
The resolver service should be available when this function is called.
cfg | initial configuration |
cb | function to call with autoconfiguration result |
cb_cls | closure for cb |
Definition at line 1035 of file gnunet-service-nat-auto_legacy.c.
References ah, cfg, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_dup(), GNUNET_CONFIGURATION_set_value_string(), GNUNET_NAT_ERROR_SUCCESS, GNUNET_new, and next_phase().
void GNUNET_NAT_autoconfig_cancel | ( | struct GNUNET_NAT_AutoHandle * | ah | ) |
Abort autoconfiguration.
ah | handle for operation to abort |
Definition at line 1065 of file gnunet-service-nat-auto_legacy.c.
References ah, GNUNET_NAT_AUTO_AutoHandle::cfg, GNUNET_CONFIGURATION_destroy(), GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NAT_test_stop(), GNUNET_SCHEDULER_cancel(), and GNUNET_NAT_AUTO_AutoHandle::mq.
Referenced by next_phase().
|
static |
The listen socket of the service for IPv4.
Definition at line 188 of file gnunet-service-nat-auto_legacy.c.
Referenced by do_udp_read(), stop_stun(), test_nat_punched(), and test_stun().
|
static |
The listen task ID for IPv4.
Definition at line 193 of file gnunet-service-nat-auto_legacy.c.
Referenced by stop_stun(), test_nat_punched(), and test_stun().
|
static |
The port the test service is running on (default 7895)
Definition at line 198 of file gnunet-service-nat-auto_legacy.c.
Referenced by bind_v4(), test_nat_punched(), and test_stun().
|
static |
Definition at line 200 of file gnunet-service-nat-auto_legacy.c.
Referenced by test_stun().
|
static |
Definition at line 202 of file gnunet-service-nat-auto_legacy.c.
Referenced by test_stun().