31#define LOG(kind, ...) GNUNET_log_from (kind, "nat-auto", __VA_ARGS__)
33#define NAT_SERVER_TIMEOUT \
34 GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
186reversal_cb (
void *cls,
const struct sockaddr *addr, socklen_t addrlen)
189 const struct sockaddr_in *sa;
191 if (
sizeof(
struct sockaddr_in) != addrlen)
193 sa = (
const struct sockaddr_in *) addr;
194 if (
h->data != sa->sin_port)
197 "Received connection reversal request for wrong port\n");
232 "Received data mismatches expected value\n");
236 "Failed to receive data from inbound connection\n");
267 "Received data does not match expected value\n");
271 "Failed to receive data from inbound connection\n");
301 "Got an inbound connection, waiting for data\n");
349 const struct sockaddr *addr,
356 const struct sockaddr_in *sa;
361 if (addrlen !=
sizeof(
struct sockaddr_in))
364 "NAT test ignores IPv6 address `%s' returned from NAT library\n",
369 "Asking gnunet-nat-server to connect to `%s'\n",
383 _ (
"Failed to connect to `gnunet-nat-server'\n"));
387 sa = (
const struct sockaddr_in *) addr;
389 msg->dst_ipv4 = sa->sin_addr.s_addr;
390 msg->dport = sa->sin_port;
392 msg->is_tcp = htonl ((uint32_t) (
h->proto == IPPROTO_TCP));
410 nh->report (
nh->report_cls,
nh->status);
433 unsigned long long bnd_port;
434 struct sockaddr_in sa;
435 const struct sockaddr *addrs[] = { (
const struct sockaddr *) &sa };
436 const socklen_t addrlens[] = {
sizeof(sa) };
445 _ (
"Failed to find valid PORT in section `%s'\n"),
450 memset (&sa, 0,
sizeof(sa));
451 sa.sin_family = AF_INET;
452 sa.sin_port = htons ((uint16_t) bnd_port);
453#if HAVE_SOCKADDR_IN_SIN_LEN
454 sa.sin_len =
sizeof(sa);
462 nh->report_cls = report_cls;
480 (IPPROTO_UDP ==
proto) ? SOCK_DGRAM
483 if ((NULL ==
nh->lsock) ||
485 (
const struct sockaddr *) &sa,
489 _ (
"Failed to create socket bound to `%s' for NAT test: %s\n"),
490 GNUNET_a2s ((
const struct sockaddr *) &sa,
sizeof(sa)),
492 if (NULL !=
nh->lsock)
501 if (IPPROTO_TCP ==
proto)
517 "NAT test listens on port %llu (%s)\n",
519 (IPPROTO_TCP ==
proto) ?
"tcp" :
"udp");
532 _ (
"NAT test failed to start NAT library\n"));
533 if (NULL !=
nh->ltask)
538 if (NULL !=
nh->lsock)
564 while (NULL != (cpos = tst->
ca_head))
570 while (NULL != (pos = tst->
na_head))
577 if (NULL != tst->
ttask)
582 if (NULL != tst->
ltask)
587 if (NULL != tst->
lsock)
592 if (NULL != tst->
nat)
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static struct GNUNET_ARM_Handle * h
Connection with ARM.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * data
The data to insert into the dht.
static char * section_name
Adapter we are supposed to test.
static uint8_t proto
Protocol to use.
struct GNUNET_NAT_Handle * nh
Handle for connect to the NAT service.
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.
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.
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
#define GNUNET_log(kind,...)
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages).
#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_strdup(a)
Wrapper around GNUNET_xstrdup_.
#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.
void GNUNET_NAT_AUTO_test_stop(struct GNUNET_NAT_AUTO_Test *tst)
Stop an active NAT test.
GNUNET_NAT_StatusCode
Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
struct GNUNET_NAT_Handle * GNUNET_NAT_register(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, uint8_t proto, unsigned int num_addrs, const struct sockaddr **addrs, const socklen_t *addrlens, GNUNET_NAT_AddressCallback address_callback, GNUNET_NAT_ReversalCallback reversal_callback, void *callback_cls)
Attempt to enable port redirection and detect public IP address contacting UPnP or NAT-PMP routers on...
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
void(* GNUNET_NAT_TestCallback)(void *cls, enum GNUNET_NAT_StatusCode result)
Function called to report success or failure for NAT configuration test.
struct GNUNET_NAT_AUTO_Test * GNUNET_NAT_AUTO_test_start(const struct GNUNET_CONFIGURATION_Handle *cfg, uint8_t proto, const char *section_name, GNUNET_NAT_TestCallback report, void *report_cls)
Start testing if NAT traversal works using the given configuration.
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
@ GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR
Failure in network subsystem, check permissions.
@ GNUNET_NAT_ERROR_NAT_REGISTER_FAILED
NAT test failed to initiate.
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_accept(const struct GNUNET_NETWORK_Handle *desc, struct sockaddr *address, socklen_t *address_len)
Accept a new connection on a socket.
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.
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
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.
#define GNUNET_MESSAGE_TYPE_NAT_TEST
Message to ask NAT server to perform traversal test.
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.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
static void do_read(void *cls)
Activity on our incoming socket.
static void reversal_cb(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Function called from GNUNET_NAT_register whenever someone asks us to do connection reversal.
static void do_fail(void *cls)
Calls the report-callback reporting failure.
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We got disconnected from the NAT server.
static void do_accept(void *cls)
Activity on our listen socket.
static void do_udp_read(void *cls)
Activity on our incoming socket.
static void addr_cb(void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
Address-callback, used to send message to gnunet-nat-server.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Entry we keep for each connection to the gnunet-nat-service.
struct GNUNET_MQ_Handle * mq
Socket of the incoming connection.
struct ClientActivity * next
This is a doubly-linked list.
struct GNUNET_NAT_Test * h
Handle to overall NAT test.
struct GNUNET_NAT_AUTO_Test * h
Handle to overall NAT test.
struct ClientActivity * prev
This is a doubly-linked list.
const struct GNUNET_CONFIGURATION_Handle * cfg
The configuration that we are using.
Handle to a message queue.
Request to test NAT traversal, sent to the gnunet-nat-server (not the service!).
char * section_name
Section name of plugin to test.
int proto
IPPROTO_TCP or IPPROTO_UDP.
GNUNET_NAT_TestCallback report
Function to call with success report.
struct NatActivity * na_tail
Tail of list of nat activities.
struct GNUNET_NAT_Handle * nat
Handle to NAT traversal in use.
struct GNUNET_NETWORK_Handle * lsock
Handle to listen socket, or NULL.
uint16_t data
Data that should be transmitted or source-port.
struct NatActivity * na_head
Head of list of nat activities.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration used.
void * report_cls
Closure for report.
struct GNUNET_SCHEDULER_Task * ttask
Task identifier for the timeout (if any)
struct ClientActivity * ca_head
Head of list of client activities.
struct ClientActivity * ca_tail
Tail of list of client activities.
enum GNUNET_NAT_StatusCode status
Status code to be reported to the timeout/status call.
struct GNUNET_SCHEDULER_Task * ltask
Identity of task for the listen socket (if any)
Handle for active NAT registrations.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
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 ...
const struct GNUNET_NETWORK_FDSet * write_ready
Set of file descriptors ready for writing; note that additional bits may be set that were not in the ...
Entry in list of pending tasks.
Entry we keep for each incoming connection.
struct NatActivity * prev
This is a doubly-linked list.
struct GNUNET_SCHEDULER_Task * rtask
Task reading from the incoming connection.
struct GNUNET_NAT_Test * h
Handle of the master context.
struct GNUNET_NETWORK_Handle * sock
Socket of the incoming connection.
struct NatActivity * next
This is a doubly-linked list.
struct GNUNET_NAT_AUTO_Test * h
Handle of the master context.