33#define LOG(kind, ...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
39#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
41#define NAT_SERVER_TIMEOUT GNUNET_TIME_relative_multiply ( \
42 GNUNET_TIME_UNIT_SECONDS, 10)
198static unsigned long long port = 7895;
218 ah->stun_ip = inet_ntoa (answer->sin_addr);
219 ah->stun_port = ntohs (answer->sin_port);
221 "External IP is: %s , with port %u\n",
235 "Stopping STUN and quitting...\n");
261 unsigned char reply_buf[1024];
263 struct sockaddr_in answer;
276 memset (&answer, 0,
sizeof(
struct sockaddr_in));
282 "The external server was able to connect back");
303 "TIMEOUT while waiting for an answer\n");
323 struct sockaddr_in sa4;
326 memset (&sa4, 0,
sizeof(sa4));
327 sa4.sin_family = AF_INET;
328 sa4.sin_port = htons (
port);
329#if HAVE_SOCKADDR_IN_SIN_LEN
330 sa4.sin_len =
sizeof(sa4);
357 "Request callback: stop and quit\n");
384 ?
_ (
"NAT traversal with ICMP Server succeeded.\n")
385 :
_ (
"NAT traversal with ICMP Server failed.\n"));
405 _ (
"Testing connection reversal with ICMP server.\n"));
422 const struct in_addr *addr,
426 char buf[INET_ADDRSTRLEN];
437 _ (
"Detected external IP `%s'\n"),
445 if (NULL == inet_ntop (AF_INET, addr, buf,
sizeof(buf)))
476 ah->eh = GNUNET_NAT_mini_get_external_ipv4 (
TIMEOUT,
520 "STUN service listens on port %u\n",
521 (
unsigned int)
port);
554 const struct sockaddr *addr,
555 const struct sockaddr *broadcast_addr,
556 const struct sockaddr *netmask,
560 const struct sockaddr_in *in;
561 char buf[INET_ADDRSTRLEN];
564 if ((
sizeof(
struct sockaddr_in6) == addrlen) &&
566 sockaddr_in6 *) addr)->
568 (! IN6_IS_ADDR_LINKLOCAL (&((
const struct
569 sockaddr_in6 *) addr)->sin6_addr)))
574 "This system has a global IPv6 address, setting IPv6 to supported.\n"));
578 if (addrlen !=
sizeof(
struct sockaddr_in))
580 in = (
const struct sockaddr_in *) addr;
584 if (NULL == inet_ntop (AF_INET, &in->sin_addr, buf,
sizeof(buf)))
592 _ (
"Detected internal network address `%s'.\n"),
599 if (
ah->stun_ip && (strcmp (buf,
ah->stun_ip) == 0))
603 "A internal IP is the sameas the external");
669 "We don't have a STUN IP");
675 "Asking gnunet-nat-server to connect to `%s'\n",
685 _ (
"Failed to connect to `gnunet-nat-server'\n"));
691 msg->dst_ipv4 = inet_addr (
ah->stun_ip);
692 msg->dport = htons (
ah->stun_port);
727 ?
_ (
"upnpc found, enabling its use\n")
728 :
_ (
"upnpc not found\n"));
766 "test_icmp_server not possible, as we have no public IPv4 address\n"));
779 "test_icmp_server not possible, as we are not behind NAT\n"));
791 _ (
"No working gnunet-helper-nat-server found\n"));
829 "test_icmp_client not possible, as we have no internal IPv4 address\n"));
841 "test_icmp_server not possible, as we are not behind NAT\n"));
849 "-d 127.0.0.1 127.0.0.2 42"))
853 _ (
"No working gnunet-helper-nat-server found\n"));
880 "Will run AUTO_EXTERNAL_IP\n");
886 "Will run AUTO_STUN\n");
892 "Will run AUTO_LOCAL_IP\n");
898 "Will run AUTO_NAT_PUNCHED\n");
904 "Will run AUTO_UPNPC\n");
910 "Will run AUTO_ICMP_SERVER\n");
916 "Will run AUTO_ICMP_CLIENT\n");
922 "Done with tests\n");
923 if (!
ah->internal_ip_is_public)
930 if (
ah->connected_back)
951 if (
ah->connected_back)
968 if (0 !=
ah->stun_port)
979 if (
ah->connected_back)
1001 if (0 !=
ah->stun_port)
1015 ah->fin_cb (
ah->fin_cb_cls,
1036 GNUNET_NAT_AutoResultCallback cb,
1043 ah->fin_cb_cls = cb_cls;
1067 if (NULL !=
ah->tst)
1074 GNUNET_NAT_mini_get_external_ipv4_cancel (
ah->eh);
1082 if (NULL !=
ah->task)
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static int ret
Final status code.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * name
Name (label) of the records to list.
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
void GNUNET_NAT_test_stop(struct GNUNET_NAT_Test *tst)
Stop an active NAT test.
struct GNUNET_NAT_Test * GNUNET_NAT_test_start(const struct GNUNET_CONFIGURATION_Handle *cfg, int is_tcp, uint16_t bnd_port, uint16_t adv_port, struct GNUNET_TIME_Relative timeout, GNUNET_NAT_TestCallback report, void *report_cls)
Start testing if NAT traversal works using the given configuration (IPv4-only).
static struct GNUNET_NETWORK_Handle * ls
Listen socket for STUN processing.
static int result
Global testing status.
static void process_stun_reply(struct sockaddr_in *answer, struct GNUNET_NAT_AutoHandle *ah)
static void test_upnpc(struct GNUNET_NAT_AutoHandle *ah)
Test if UPnPC works.
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.
static char * stun_server
static void test_nat_punched(struct GNUNET_NAT_AutoHandle *ah)
Test if NAT has been punched.
static struct GNUNET_NETWORK_Handle * bind_v4()
Create an IPv4 listen socket bound to our port.
static void next_phase(struct GNUNET_NAT_AutoHandle *ah)
Run the next phase of the auto test.
static void request_callback(void *cls, enum GNUNET_NAT_StatusCode result)
void GNUNET_NAT_autoconfig_cancel(struct GNUNET_NAT_AutoHandle *ah)
Abort autoconfiguration.
#define TIMEOUT
How long do we wait for the NAT test to report success?
static void test_stun(struct GNUNET_NAT_AutoHandle *ah)
Determine our external IPv4 address and port using an external STUN server.
#define NAT_SERVER_TIMEOUT
static void test_icmp_client(struct GNUNET_NAT_AutoHandle *ah)
Test if ICMP client is working.
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.
static struct GNUNET_NETWORK_Handle * lsock4
The listen socket of the service for IPv4.
static unsigned long long port
The port the test service is running on (default 7895)
static void stop_stun()
Function that terminates the test.
static unsigned int stun_port
static void test_icmp_server(struct GNUNET_NAT_AutoHandle *ah)
Test if ICMP server is working.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got disconnected from the NAT server.
static void test_local_ip(struct GNUNET_NAT_AutoHandle *ah)
Determine our local IP addresses; detect internal IP & IPv6-support.
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.
static void reversal_test(void *cls)
Main function for the connection reversal test.
static void result_callback(void *cls, enum GNUNET_NAT_StatusCode ret)
Function called by NAT to report the outcome of the nat-test.
static void test_external_ip(struct GNUNET_NAT_AutoHandle *ah)
Determine our external IPv4 address.
static void do_udp_read(void *cls)
Activity on our incoming socket.
AutoPhase
Phases of the auto configuration.
@ AUTO_EXTERNAL_IP
Test our external IP.
@ AUTO_NAT_PUNCHED
Test if NAT was punched.
@ AUTO_LOCAL_IP
Test our internal IP.
@ AUTO_INIT
Initial start value.
@ AUTO_STUN
Test our external IP.
@ AUTO_ICMP_CLIENT
Test if ICMP client works.
@ AUTO_DONE
Last phase, we're done.
@ AUTO_ICMP_SERVER
Test if ICMP server works.
@ AUTO_UPNPC
Test if UPnP is working.
static struct GNUNET_SCHEDULER_Task * ltask4
The listen task ID for IPv4.
Functions related to doing DNS lookups.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
void GNUNET_CONFIGURATION_set_value_string(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, const char *value)
Set a configuration value that should be a string.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_dup(const struct GNUNET_CONFIGURATION_Handle *cfg)
Duplicate an existing configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
void GNUNET_CONFIGURATION_destroy(struct GNUNET_CONFIGURATION_Handle *cfg)
Destroy configuration object.
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_yesno(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option)
Get a configuration value that should be in a set of "YES" or "NO".
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_string(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, char **value)
Get a configuration value that should be a string.
void GNUNET_CONFIGURATION_set_value_number(struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long number)
Set a configuration value that should be a number.
struct GNUNET_CONFIGURATION_Handle * GNUNET_CONFIGURATION_get_diff(const struct GNUNET_CONFIGURATION_Handle *cfg_default, const struct GNUNET_CONFIGURATION_Handle *cfg_new)
Compute configuration with only entries that have been changed.
#define GNUNET_log(kind,...)
#define GNUNET_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_log_strerror(level, cmd)
Log an error message at log-level 'level' that indicates a failure of the command 'cmd' with the mess...
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
GNUNET_NAT_StatusCode
Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
struct GNUNET_NAT_STUN_Handle * GNUNET_NAT_stun_make_request(const char *server, uint16_t port, struct GNUNET_NETWORK_Handle *sock, GNUNET_NAT_TestCallback cb, void *cb_cls)
Make Generic STUN request.
GNUNET_NAT_Type
What the situation of the NAT connectivity.
int GNUNET_NAT_stun_handle_packet(struct GNUNET_NAT_Handle *nh, const struct sockaddr *sender_addr, size_t sender_addr_len, const void *data, size_t data_size)
Handle an incoming STUN message.
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
@ GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO
Could not determine interface with internal/local network address.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID
"no valid address was returned by `external-ip'"
@ GNUNET_NAT_TYPE_UNREACHABLE_NAT
We are under a NAT but cannot traverse it.
@ GNUNET_NAT_TYPE_NO_NAT
We have a direct connection.
@ GNUNET_NAT_TYPE_STUN_PUNCHED_NAT
We can traverse using STUN.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
ssize_t GNUNET_NETWORK_socket_recv(const struct GNUNET_NETWORK_Handle *desc, void *buffer, size_t length)
Read data from a connected socket (always non-blocking).
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_bind(struct GNUNET_NETWORK_Handle *desc, const struct sockaddr *address, socklen_t address_len)
Bind a socket to a particular address.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
char * GNUNET_OS_get_libexec_binary_path(const char *progname)
Given the name of a gnunet-helper, gnunet-service or gnunet-daemon binary, try to prefix it with the ...
enum GNUNET_GenericReturnValue GNUNET_OS_check_helper_binary(const char *binary, bool check_suid, const char *params)
Check whether an executable exists and possibly if the suid bit is set on the file.
#define GNUNET_MESSAGE_TYPE_NAT_TEST
Message to ask NAT server to perform traversal test.
void GNUNET_RESOLVER_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Create the connection to the resolver service.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
@ GNUNET_SCHEDULER_REASON_READ_READY
The reading socket is ready.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Handle to a message queue.
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Handle to auto-configuration in progress.
int internal_ip_is_public
Internal IP is the same as the public one ?
enum GNUNET_NAT_StatusCode ret
Error code for better debugging and user feedback.
struct GNUNET_SCHEDULER_Task * task
Task identifier for the timeout.
int upnp_set_external_address
UPnP already set the external ip address ?
struct GNUNET_NAT_ExternalHandle * eh
Handle for active 'GNUNET_NAT_mini_get_external_ipv4'-operation.
int connected_back
Did the external server connected back ?
struct GNUNET_CONFIGURATION_Handle * cfg
Current configuration (with updates from previous phases)
enum AutoPhase phase
Where are we in the test?
struct GNUNET_NAT_Test * tst
Handle to the active NAT test.
char * stun_ip
Address detected by STUN.
void * fin_cb_cls
Closure for fin_cb.
struct GNUNET_MQ_Handle * mq
Message queue to the gnunet-nat-server.
enum GNUNET_NAT_Type type
Situation of the NAT.
int have_v6
Do we have IPv6?
GNUNET_NAT_AutoResultCallback fin_cb
Function to call when done.
struct GNUNET_CONFIGURATION_Handle * initial_cfg
Original configuration (used to calculate differences)
Opaque handle to cancel "GNUNET_NAT_mini_get_external_ipv4" operation.
Request to test NAT traversal, sent to the gnunet-nat-server (not the service!).
Context information passed to each scheduler task.
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
Entry in list of pending tasks.