GNUnet 0.21.2
NAT library

Service for handling UPnP and NAT-PMP port forwarding and external IP address retrieval. More...

Typedefs

typedef void(* GNUNET_NAT_AUTO_AutoResultCallback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *diff, enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type)
 Function called with the result from the autoconfiguration. More...
 
typedef void(* GNUNET_NAT_AddressCallback) (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes. More...
 
typedef void(* GNUNET_NAT_ReversalCallback) (void *cls, const struct sockaddr *remote_addr, socklen_t remote_addrlen)
 Signature of the callback passed to GNUNET_NAT_register(). More...
 
typedef void(* GNUNET_NAT_TestCallback) (void *cls, enum GNUNET_NAT_StatusCode result)
 Function called to report success or failure for NAT configuration test. More...
 

Enumerations

enum  GNUNET_NAT_AddressClass {
  GNUNET_NAT_AC_NONE = 0 , GNUNET_NAT_AC_OTHER = 1 , GNUNET_NAT_AC_PRIVATE = 2 , GNUNET_NAT_AC_GLOBAL = 4 ,
  GNUNET_NAT_AC_GLOBAL_PRIVATE = 6 , GNUNET_NAT_AC_LAN = 8 , GNUNET_NAT_AC_LAN_PRIVATE = 10 , GNUNET_NAT_AC_WLAN = 16 ,
  GNUNET_NAT_AC_BT = 32 , GNUNET_NAT_AC_LOOPBACK = 64 , GNUNET_NAT_AC_EXTERN = 128 , GNUNET_NAT_AC_MANUAL = 256 ,
  GNUNET_NAT_AC_ANY = 65535
}
 Some addresses contain sensitive information or are not suitable for global distribution. More...
 
enum  GNUNET_NAT_StatusCode {
  GNUNET_NAT_ERROR_SUCCESS = GNUNET_OK , GNUNET_NAT_ERROR_IPC_FAILURE , GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR , GNUNET_NAT_ERROR_TIMEOUT ,
  GNUNET_NAT_ERROR_NOT_ONLINE , GNUNET_NAT_ERROR_UPNPC_NOT_FOUND , GNUNET_NAT_ERROR_UPNPC_FAILED , GNUNET_NAT_ERROR_UPNPC_TIMEOUT ,
  GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED , GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND , GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED , GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID ,
  GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID , GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO , GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND , GNUNET_NAT_ERROR_NAT_TEST_START_FAILED ,
  GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT , GNUNET_NAT_ERROR_NAT_REGISTER_FAILED , GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
}
 Error Types for the NAT subsystem (which can then later be converted/resolved to a string) More...
 
enum  GNUNET_NAT_Type {
  GNUNET_NAT_TYPE_NO_NAT = GNUNET_OK , GNUNET_NAT_TYPE_UNREACHABLE_NAT , GNUNET_NAT_TYPE_STUN_PUNCHED_NAT , GNUNET_NAT_TYPE_UPNP_NAT ,
  GNUNET_NAT_TYPE_UNKNOWN
}
 What the situation of the NAT connectivity. More...
 

Functions

struct GNUNET_NAT_AUTO_TestGNUNET_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. More...
 
void GNUNET_NAT_AUTO_test_stop (struct GNUNET_NAT_AUTO_Test *tst)
 Stop an active NAT test. More...
 
const char * GNUNET_NAT_AUTO_status2string (enum GNUNET_NAT_StatusCode err)
 Converts enum GNUNET_NAT_StatusCode to string. More...
 
struct GNUNET_NAT_AUTO_AutoHandleGNUNET_NAT_AUTO_autoconfig_start (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_NAT_AUTO_AutoResultCallback cb, void *cb_cls)
 Start auto-configuration routine. More...
 
void GNUNET_NAT_AUTO_autoconfig_cancel (struct GNUNET_NAT_AUTO_AutoHandle *ah)
 Abort autoconfiguration. More...
 
struct GNUNET_NAT_HandleGNUNET_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 the local network. More...
 
void GNUNET_NAT_add_global_address (struct GNUNET_NAT_Handle *nh, char *addr, unsigned int address_length)
 Add global address to the list of addresses and notify clients. More...
 
int GNUNET_NAT_test_address (struct GNUNET_NAT_Handle *nh, const void *addr, socklen_t addrlen)
 Test if the given address is (currently) a plausible IP address for this peer. More...
 
int GNUNET_NAT_request_reversal (struct GNUNET_NAT_Handle *nh, const struct sockaddr_in *local_sa, const struct sockaddr_in *remote_sa)
 We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP responses to cause that peer to connect to us (connection reversal). More...
 
void GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh)
 Stop port redirection and public IP address detection for the given handle. More...
 
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. More...
 
struct GNUNET_NAT_STUN_HandleGNUNET_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. More...
 
void GNUNET_NAT_stun_make_request_cancel (struct GNUNET_NAT_STUN_Handle *rh)
 Cancel active STUN request. More...
 

Detailed Description

Service for handling UPnP and NAT-PMP port forwarding and external IP address retrieval.

Typedef Documentation

◆ GNUNET_NAT_AUTO_AutoResultCallback

typedef void(* GNUNET_NAT_AUTO_AutoResultCallback) (void *cls, const struct GNUNET_CONFIGURATION_Handle *diff, enum GNUNET_NAT_StatusCode result, enum GNUNET_NAT_Type type)

Function called with the result from the autoconfiguration.

Parameters
clsclosure
diffminimal suggested changes to the original configuration to make it work (as best as we can)
resultGNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code
typewhat the situation of the NAT

Definition at line 101 of file gnunet_nat_auto_service.h.

◆ GNUNET_NAT_AddressCallback

typedef void(* GNUNET_NAT_AddressCallback) (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)

Signature of the callback passed to GNUNET_NAT_register() for a function to call whenever our set of 'valid' addresses changes.

Parameters
clsclosure
app_ctx[in,out]location where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to add a new public IP address, GNUNET_NO to remove a previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual length of the addr

Definition at line 285 of file gnunet_nat_service.h.

◆ GNUNET_NAT_ReversalCallback

typedef void(* GNUNET_NAT_ReversalCallback) (void *cls, const struct sockaddr *remote_addr, socklen_t remote_addrlen)

Signature of the callback passed to GNUNET_NAT_register().

for a function to call whenever someone asks us to do connection reversal.

Parameters
clsclosure
remote_addrpublic IP address of the other peer
remote_addrlenactual length of the remote_addr

Definition at line 303 of file gnunet_nat_service.h.

◆ GNUNET_NAT_TestCallback

typedef void(* GNUNET_NAT_TestCallback) (void *cls, enum GNUNET_NAT_StatusCode result)

Function called to report success or failure for NAT configuration test.

Parameters
clsclosure
resultGNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code

Definition at line 460 of file gnunet_nat_service.h.

Enumeration Type Documentation

◆ GNUNET_NAT_AddressClass

Some addresses contain sensitive information or are not suitable for global distribution.

We use address classes to filter addresses by which domain they make sense to be used in. These are used in a bitmask.

FIXME: might want to define this elsewhere; we have an equivalent enum in gnunet_transport_hello_service.h; might ultimately belong with the new HELLO definition.

Enumerator
GNUNET_NAT_AC_NONE 

No address.

GNUNET_NAT_AC_OTHER 

Addresses that fall into no other category (i.e.

incoming which we cannot use elsewhere).

GNUNET_NAT_AC_PRIVATE 

Flag for addresses that are highly sensitive (i.e.

IPv6 with our MAC).

GNUNET_NAT_AC_GLOBAL 

Addresses that are global (i.e.

IPv4).

GNUNET_NAT_AC_GLOBAL_PRIVATE 

Addresses that are global and are sensitive (i.e.

IPv6 with our MAC).

GNUNET_NAT_AC_LAN 

Addresses useful in the local wired network, i.e.

a MAC. Sensitive, but obvious to people nearby.

Useful for broadcasts.

GNUNET_NAT_AC_LAN_PRIVATE 

Addresses useful in the local wired network, i.e.

a MAC. Sensitive, but obvious to people nearby. Useful for broadcasts.

GNUNET_NAT_AC_WLAN 

Addresses useful in the local wireless network, i.e.

a MAC. Sensitive, but obvious to people nearby. Useful for broadcasts.

GNUNET_NAT_AC_BT 

Addresses useful in the local bluetooth network.

Sensitive, but obvious to people nearby. Useful for broadcasts.

GNUNET_NAT_AC_LOOPBACK 

Loopback addresses, only useful under special circumstances.

GNUNET_NAT_AC_EXTERN 

Addresses that should be our external IP address on the outside of a NAT.

Might be incorrectly determined. Used as a bit in combination with GNUNET_NAT_AC_GLOBAL, or in case of double-NAT with GNUNET_NAT_AC_LAN.

GNUNET_NAT_AC_MANUAL 

Addresses that were manually configured by the user.

Used as a bit in combination with GNUNET_NAT_AC_GLOBAL.

GNUNET_NAT_AC_ANY 

Bitmask for "any" address.

Definition at line 53 of file gnunet_nat_service.h.

54{
59
65
71
76
82
90
97
104
109 GNUNET_NAT_AC_BT = 32,
110
115
124
130
134 GNUNET_NAT_AC_ANY = 65535
135};
@ GNUNET_NAT_AC_LAN_PRIVATE
Addresses useful in the local wired network, i.e.
@ GNUNET_NAT_AC_LAN
Addresses useful in the local wired network, i.e.
@ GNUNET_NAT_AC_GLOBAL_PRIVATE
Addresses that are global and are sensitive (i.e.
@ GNUNET_NAT_AC_GLOBAL
Addresses that are global (i.e.
@ GNUNET_NAT_AC_PRIVATE
Flag for addresses that are highly sensitive (i.e.
@ GNUNET_NAT_AC_EXTERN
Addresses that should be our external IP address on the outside of a NAT.
@ GNUNET_NAT_AC_ANY
Bitmask for "any" address.
@ GNUNET_NAT_AC_WLAN
Addresses useful in the local wireless network, i.e.
@ GNUNET_NAT_AC_OTHER
Addresses that fall into no other category (i.e.
@ GNUNET_NAT_AC_BT
Addresses useful in the local bluetooth network.
@ GNUNET_NAT_AC_NONE
No address.
@ GNUNET_NAT_AC_MANUAL
Addresses that were manually configured by the user.
@ GNUNET_NAT_AC_LOOPBACK
Loopback addresses, only useful under special circumstances.

◆ GNUNET_NAT_StatusCode

Error Types for the NAT subsystem (which can then later be converted/resolved to a string)

Enumerator
GNUNET_NAT_ERROR_SUCCESS 

Just the default.

GNUNET_NAT_ERROR_IPC_FAILURE 

IPC Failure.

GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR 

Failure in network subsystem, check permissions.

GNUNET_NAT_ERROR_TIMEOUT 

test timed out

GNUNET_NAT_ERROR_NOT_ONLINE 

detected that we are offline

GNUNET_NAT_ERROR_UPNPC_NOT_FOUND 

upnpc command not found

GNUNET_NAT_ERROR_UPNPC_FAILED 

Failed to run upnpc command.

GNUNET_NAT_ERROR_UPNPC_TIMEOUT 

‘upnpc’ command took too long, process killed

GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED 

‘upnpc’ command failed to establish port mapping

GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND 

‘external-ip’ command not found

GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED 

Failed to run external-ip command.

GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID 

‘external-ip’ command output invalid

GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID 

"no valid address was returned by `external-ip'"

GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO 

Could not determine interface with internal/local network address.

GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND 

No working gnunet-helper-nat-server found.

GNUNET_NAT_ERROR_NAT_TEST_START_FAILED 

NAT test could not be initialized.

GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT 

NAT test timeout.

GNUNET_NAT_ERROR_NAT_REGISTER_FAILED 

NAT test failed to initiate.

GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND 

Definition at line 141 of file gnunet_nat_service.h.

142{
147
152
157
162
167
172
177
182
187
192
197
202
207
212
217
222
227
232
237};
@ GNUNET_OK
@ GNUNET_NAT_ERROR_UPNPC_NOT_FOUND
upnpc command not found
@ GNUNET_NAT_ERROR_NOT_ONLINE
detected that we are offline
@ GNUNET_NAT_ERROR_UPNPC_TIMEOUT
‘upnpc’ command took too long, process killed
@ GNUNET_NAT_ERROR_SUCCESS
Just the default.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID
‘external-ip’ command output invalid
@ GNUNET_NAT_ERROR_UPNPC_FAILED
Failed to run upnpc command.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED
Failed to run external-ip command.
@ GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR
Failure in network subsystem, check permissions.
@ GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND
@ GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED
‘upnpc’ command failed to establish port mapping
@ GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND
‘external-ip’ command not found
@ GNUNET_NAT_ERROR_NAT_REGISTER_FAILED
NAT test failed to initiate.
@ GNUNET_NAT_ERROR_IPC_FAILURE
IPC Failure.
@ GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO
Could not determine interface with internal/local network address.
@ GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND
No working gnunet-helper-nat-server found.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID
"no valid address was returned by `external-ip'"
@ GNUNET_NAT_ERROR_NAT_TEST_START_FAILED
NAT test could not be initialized.
@ GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT
NAT test timeout.
@ GNUNET_NAT_ERROR_TIMEOUT
test timed out

◆ GNUNET_NAT_Type

What the situation of the NAT connectivity.

Enumerator
GNUNET_NAT_TYPE_NO_NAT 

We have a direct connection.

GNUNET_NAT_TYPE_UNREACHABLE_NAT 

We are under a NAT but cannot traverse it.

GNUNET_NAT_TYPE_STUN_PUNCHED_NAT 

We can traverse using STUN.

GNUNET_NAT_TYPE_UPNP_NAT 

We can traverse using UPNP.

GNUNET_NAT_TYPE_UNKNOWN 

We know nothing about the NAT.

Definition at line 243 of file gnunet_nat_service.h.

244{
249
254
259
264
269};
@ GNUNET_NAT_TYPE_UPNP_NAT
We can traverse using UPNP.
@ GNUNET_NAT_TYPE_UNKNOWN
We know nothing about the NAT.
@ 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.

Function Documentation

◆ GNUNET_NAT_AUTO_test_start()

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.

The transport adapters should be down while using this function.

Parameters
cfgconfiguration for the NAT traversal
protoprotocol to test, i.e. IPPROTO_TCP or IPPROTO_UDP
section_nameconfiguration section to use for configuration
reportfunction to call with the result of the test
report_clsclosure for report
Returns
handle to cancel NAT test

Definition at line 426 of file nat_auto_api_test.c.

431{
432 struct GNUNET_NAT_AUTO_Test *nh;
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) };
437
440 "PORT",
441 &bnd_port)) ||
442 (bnd_port > 65535))
443 {
445 _ ("Failed to find valid PORT in section `%s'\n"),
447 return NULL;
448 }
449
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);
455#endif
456
458 nh->cfg = cfg;
459 nh->proto = proto;
460 nh->section_name = GNUNET_strdup (section_name);
461 nh->report = report;
462 nh->report_cls = report_cls;
464 if (0 == bnd_port)
465 {
466 nh->nat = GNUNET_NAT_register (cfg,
468 proto,
469 0,
470 NULL,
471 NULL,
472 &addr_cb,
474 nh);
475 }
476 else
477 {
478 nh->lsock =
480 (IPPROTO_UDP == proto) ? SOCK_DGRAM
481 : SOCK_STREAM,
482 proto);
483 if ((NULL == nh->lsock) ||
485 (const struct sockaddr *) &sa,
486 sizeof(sa))))
487 {
489 _ ("Failed to create socket bound to `%s' for NAT test: %s\n"),
490 GNUNET_a2s ((const struct sockaddr *) &sa, sizeof(sa)),
491 strerror (errno));
492 if (NULL != nh->lsock)
493 {
495 nh->lsock = NULL;
496 }
499 return nh;
500 }
501 if (IPPROTO_TCP == proto)
502 {
505 nh->lsock,
506 &do_accept,
507 nh);
508 }
509 else
510 {
512 nh->lsock,
514 nh);
515 }
517 "NAT test listens on port %llu (%s)\n",
518 bnd_port,
519 (IPPROTO_TCP == proto) ? "tcp" : "udp");
520 nh->nat = GNUNET_NAT_register (cfg,
522 proto,
523 1,
524 addrs,
525 addrlens,
526 &addr_cb,
527 NULL,
528 nh);
529 if (NULL == nh->nat)
530 {
532 _ ("NAT test failed to start NAT library\n"));
533 if (NULL != nh->ltask)
534 {
536 nh->ltask = NULL;
537 }
538 if (NULL != nh->lsock)
539 {
541 nh->lsock = NULL;
542 }
545 return nh;
546 }
547 }
548 return nh;
549}
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
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.
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_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).
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_INFO
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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...
Definition: nat_api.c:366
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_close(struct GNUNET_NETWORK_Handle *desc)
Close a socket.
Definition: network.c:508
struct GNUNET_NETWORK_Handle * GNUNET_NETWORK_socket_create(int domain, int type, int protocol)
Create a new socket.
Definition: network.c:832
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.
Definition: network.c:439
enum GNUNET_GenericReturnValue GNUNET_NETWORK_socket_listen(const struct GNUNET_NETWORK_Handle *desc, int backlog)
Listen on a socket.
Definition: network.c:651
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...
Definition: scheduler.c:1512
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
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.
Definition: scheduler.c:1305
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
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 do_accept(void *cls)
Activity on our listen socket.
static void do_udp_read(void *cls)
Activity on our incoming socket.
#define LOG(kind,...)
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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
Handle to a NAT test.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Definition: nat_api.c:76

References _, addr_cb(), cfg, GNUNET_NAT_Handle::cfg, do_accept(), do_fail(), do_udp_read(), GNUNET_a2s(), GNUNET_break, GNUNET_CONFIGURATION_get_value_number(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_register(), GNUNET_NETWORK_socket_bind(), GNUNET_NETWORK_socket_close(), GNUNET_NETWORK_socket_create(), GNUNET_NETWORK_socket_listen(), GNUNET_new, GNUNET_OK, GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_strdup, GNUNET_TIME_UNIT_FOREVER_REL, LOG, nh, proto, reversal_cb(), and section_name.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_AUTO_test_stop()

void GNUNET_NAT_AUTO_test_stop ( struct GNUNET_NAT_AUTO_Test tst)

Stop an active NAT test.

Parameters
tsttest to stop.

Definition at line 558 of file nat_auto_api_test.c.

559{
560 struct NatActivity *pos;
561 struct ClientActivity *cpos;
562
563 LOG (GNUNET_ERROR_TYPE_DEBUG, "Stopping NAT test\n");
564 while (NULL != (cpos = tst->ca_head))
565 {
567 GNUNET_MQ_destroy (cpos->mq);
568 GNUNET_free (cpos);
569 }
570 while (NULL != (pos = tst->na_head))
571 {
575 GNUNET_free (pos);
576 }
577 if (NULL != tst->ttask)
578 {
580 tst->ttask = NULL;
581 }
582 if (NULL != tst->ltask)
583 {
585 tst->ltask = NULL;
586 }
587 if (NULL != tst->lsock)
588 {
590 tst->lsock = NULL;
591 }
592 if (NULL != tst->nat)
593 {
595 tst->nat = NULL;
596 }
598 GNUNET_free (tst);
599}
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
void GNUNET_NAT_unregister(struct GNUNET_NAT_Handle *nh)
Stop port redirection and public IP address detection for the given handle.
Definition: nat_api.c:702
Entry we keep for each connection to the gnunet-nat-service.
struct GNUNET_MQ_Handle * mq
Socket of the incoming connection.
char * section_name
Section name of plugin to test.
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.
struct NatActivity * na_head
Head of list of nat activities.
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.
struct GNUNET_SCHEDULER_Task * ltask
Identity of task for the listen socket (if any)
Entry we keep for each incoming connection.
struct GNUNET_SCHEDULER_Task * rtask
Task reading from the incoming connection.
struct GNUNET_NETWORK_Handle * sock
Socket of the incoming connection.

References GNUNET_NAT_AUTO_Test::ca_head, GNUNET_NAT_AUTO_Test::ca_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_NAT_unregister(), GNUNET_NETWORK_socket_close(), GNUNET_SCHEDULER_cancel(), LOG, GNUNET_NAT_AUTO_Test::lsock, GNUNET_NAT_AUTO_Test::ltask, ClientActivity::mq, GNUNET_NAT_AUTO_Test::na_head, GNUNET_NAT_AUTO_Test::na_tail, GNUNET_NAT_AUTO_Test::nat, NatActivity::rtask, GNUNET_NAT_AUTO_Test::section_name, NatActivity::sock, and GNUNET_NAT_AUTO_Test::ttask.

Referenced by do_shutdown().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_AUTO_status2string()

const char * GNUNET_NAT_AUTO_status2string ( enum GNUNET_NAT_StatusCode  err)

Converts enum GNUNET_NAT_StatusCode to string.

Parameters
errerror code to resolve to a string
Returns
point to a static string containing the error code

Definition at line 68 of file nat_auto_api.c.

69{
70 switch (err)
71 {
73 return _ ("Operation Successful");
74
76 return _ ("IPC failure");
77
79 return _ ("Failure in network subsystem, check permissions.");
80
82 return _ ("Encountered timeout while performing operation");
83
85 return _ ("detected that we are offline");
86
88 return _ ("`upnpc` command not found");
89
91 return _ ("Failed to run `upnpc` command");
92
94 return _ ("`upnpc' command took too long, process killed");
95
97 return _ ("`upnpc' command failed to establish port mapping");
98
100 return _ ("`external-ip' command not found");
101
103 return _ ("Failed to run `external-ip` command");
104
106 return _ ("`external-ip' command output invalid");
107
109 return _ ("no valid address was returned by `external-ip'");
110
112 return _ (
113 "Could not determine interface with internal/local network address");
114
116 return _ ("No functioning gnunet-helper-nat-server installation found");
117
119 return _ ("NAT test could not be initialized");
120
122 return _ ("NAT test timeout reached");
123
125 return _ ("could not register NAT");
126
128 return _ ("No working gnunet-helper-nat-client installation found");
129
130 default:
131 return "unknown status code";
132 }
133}

References _, GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_FAILED, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND, GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID, GNUNET_NAT_ERROR_HELPER_NAT_CLIENT_NOT_FOUND, GNUNET_NAT_ERROR_HELPER_NAT_SERVER_NOT_FOUND, GNUNET_NAT_ERROR_INTERNAL_NETWORK_ERROR, GNUNET_NAT_ERROR_IPC_FAILURE, GNUNET_NAT_ERROR_NAT_REGISTER_FAILED, GNUNET_NAT_ERROR_NAT_TEST_START_FAILED, GNUNET_NAT_ERROR_NAT_TEST_TIMEOUT, GNUNET_NAT_ERROR_NO_VALID_IF_IP_COMBO, GNUNET_NAT_ERROR_NOT_ONLINE, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_ERROR_TIMEOUT, GNUNET_NAT_ERROR_UPNPC_FAILED, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, and GNUNET_NAT_ERROR_UPNPC_TIMEOUT.

Referenced by auto_config_cb(), and test_report_cb().

Here is the caller graph for this function:

◆ GNUNET_NAT_AUTO_autoconfig_start()

struct GNUNET_NAT_AUTO_AutoHandle * GNUNET_NAT_AUTO_autoconfig_start ( const struct GNUNET_CONFIGURATION_Handle cfg,
GNUNET_NAT_AUTO_AutoResultCallback  cb,
void *  cb_cls 
)

Start auto-configuration routine.

The transport adapters should be stopped while this function is called.

Parameters
cfginitial configuration
cbfunction to call with autoconfiguration result
cb_clsclosure for cb
Returns
handle to cancel operation

Definition at line 225 of file nat_auto_api.c.

228{
232 GNUNET_MQ_hd_var_size (auto_result,
235 ah),
237 };
238 struct GNUNET_MQ_Envelope *env;
240 char *buf;
241 size_t size;
242
244 &size);
245 if (size > GNUNET_MAX_MESSAGE_SIZE - sizeof(*req))
246 {
247 GNUNET_break (0);
248 GNUNET_free (buf);
249 GNUNET_free (ah);
250 return NULL;
251 }
252 ah->arc = cb;
253 ah->arc_cls = cb_cls;
255 "nat",
256 handlers,
258 ah);
259 if (NULL == ah->mq)
260 {
261 GNUNET_break (0);
262 GNUNET_free (buf);
263 GNUNET_free (ah);
264 return NULL;
265 }
267 size,
269 GNUNET_memcpy (&req[1],
270 buf,
271 size);
272 GNUNET_free (buf);
274 env);
275 return ah;
276}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_NAT_AUTO_AutoHandle * ah
Handle to ongoing autoconfiguration.
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message,...
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.
Definition: client.c:1057
char * GNUNET_CONFIGURATION_serialize(const struct GNUNET_CONFIGURATION_Handle *cfg, size_t *size)
Serializes the given configuration.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct.
Definition: gnunet_mq_lib.h:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT
Message from NAT service with the autoconfiguration result.
#define GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG
Message to ask NAT service to request autoconfiguration.
static void ah_error_handler(void *cls, enum GNUNET_MQ_Error error)
Handle queue errors by reporting autoconfiguration failure.
Definition: nat_auto_api.c:202
static unsigned int size
Size of the "table".
Definition: peer.c:68
Message handler for a specific message type.
Handle to auto-configuration in progress.
Definition: nat_auto_api.c:38
void * arc_cls
Closure for arc.
Definition: nat_auto_api.c:57
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
Definition: nat_auto_api.c:47
GNUNET_NAT_AUTO_AutoResultCallback arc
Function called with the result from the autoconfiguration.
Definition: nat_auto_api.c:52
Client requesting automatic configuration.
Definition: nat-auto.h:71
Service responding with proposed configuration.
Definition: nat-auto.h:85

References ah, ah_error_handler(), GNUNET_NAT_AUTO_AutoHandle::arc, GNUNET_NAT_AUTO_AutoHandle::arc_cls, cfg, env, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_CONFIGURATION_serialize(), GNUNET_free, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_AUTO_CFG_RESULT, GNUNET_MESSAGE_TYPE_NAT_AUTO_REQUEST_CFG, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_new, handlers, GNUNET_NAT_AUTO_AutoHandle::mq, and size.

Referenced by run().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_AUTO_autoconfig_cancel()

void GNUNET_NAT_AUTO_autoconfig_cancel ( struct GNUNET_NAT_AUTO_AutoHandle ah)

Abort autoconfiguration.

Parameters
ahhandle for operation to abort

Definition at line 285 of file nat_auto_api.c.

286{
288 GNUNET_free (ah);
289}

References ah, GNUNET_free, GNUNET_MQ_destroy(), and GNUNET_NAT_AUTO_AutoHandle::mq.

Referenced by ah_error_handler(), do_shutdown(), and handle_auto_result().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_register()

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 the local network.

Use addr to specify to which of the local host's addresses should the external port be mapped. The port is taken from the corresponding sockaddr_in[6] field. The NAT module should call the given address_callback for any 'plausible' external address.

Parameters
cfgconfiguration to use
config_sectionname of the configuration section for options
protoprotocol this is about, IPPROTO_TCP or IPPROTO_UDP
num_addrsnumber of addresses in addrs
addrslist of local addresses packets should be redirected to
addrlensactual lengths of the addresses in addrs
address_callbackfunction to call every time the public IP address changes
reversal_callbackfunction to call if someone wants connection reversal from us, NULL if connection reversal is not supported
callback_clsclosure for callbacks
Returns
NULL on error, otherwise handle that can be used to unregister

Definition at line 366 of file nat_api.c.

375{
376 struct GNUNET_NAT_Handle *nh;
378 size_t len;
379 size_t str_len;
380 char *off;
381
382 len = 0;
383 for (unsigned int i = 0; i < num_addrs; i++)
384 len += addrlens[i];
385 str_len = strlen (config_section) + 1;
386 len += str_len;
387 if ( (len > GNUNET_MAX_MESSAGE_SIZE - sizeof(*rm)) ||
388 (num_addrs > UINT16_MAX) ||
389 (str_len > UINT16_MAX) )
390 {
391 GNUNET_break (0);
392 return NULL;
393 }
394 rm = GNUNET_malloc (sizeof(*rm) + len);
395 rm->header.size = htons (sizeof(*rm) + len);
398 if (NULL != address_callback)
400 if (NULL != reversal_callback)
402 rm->proto = proto;
403 rm->str_len = htons (str_len);
404 rm->num_addrs = htons ((uint16_t) num_addrs);
405 off = (char *) &rm[1];
406 for (unsigned int i = 0; i < num_addrs; i++)
407 {
408 switch (addrs[i]->sa_family)
409 {
410 case AF_INET:
411 if (sizeof(struct sockaddr_in) != addrlens[i])
412 {
413 GNUNET_break (0);
414 GNUNET_free (rm);
415 return NULL;
416 }
417 break;
418
419 case AF_INET6:
420 if (sizeof(struct sockaddr_in6) != addrlens[i])
421 {
422 GNUNET_break (0);
423 GNUNET_free (rm);
424 return NULL;
425 }
426 break;
427
428#if AF_UNIX
429 case AF_UNIX:
430 if (sizeof(struct sockaddr_un) != addrlens[i])
431 {
432 GNUNET_break (0);
433 GNUNET_free (rm);
434 return NULL;
435 }
436 break;
437#endif
438 default:
439 GNUNET_break (0);
440 GNUNET_free (rm);
441 return NULL;
442 }
443 GNUNET_memcpy (off, addrs[i], addrlens[i]);
444 off += addrlens[i];
445 }
446 GNUNET_memcpy (off, config_section, str_len);
447
449 nh->reg = &rm->header;
450 nh->cfg = cfg;
451 nh->address_callback = address_callback;
453 nh->callback_cls = callback_cls;
454 do_connect (nh);
455 return nh;
456}
static void reversal_callback(void *cls, const struct sockaddr_in *ra)
We got a connection reversal request from another peer.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_MESSAGE_TYPE_NAT_REGISTER
Message to ask NAT service to register a client.
@ GNUNET_NAT_RF_ADDRESSES
This client wants to be informed about changes to our applicable addresses.
Definition: nat.h:82
@ GNUNET_NAT_RF_NONE
This client does not want any notifications.
Definition: nat.h:76
@ GNUNET_NAT_RF_REVERSAL
This client supports address reversal.
Definition: nat.h:87
static void do_connect(void *cls)
Task to connect to the NAT service.
Definition: nat_api.c:329
Handle for active NAT registrations.
Definition: nat_api.c:72
void * callback_cls
Closure for the various callbacks.
Definition: nat_api.c:111
struct GNUNET_MessageHeader * reg
Our registration message.
Definition: nat_api.c:86
GNUNET_NAT_ReversalCallback reversal_callback
Function to call when another peer requests connection reversal.
Definition: nat_api.c:106
GNUNET_NAT_AddressCallback address_callback
Function to call when our addresses change.
Definition: nat_api.c:101
Message sent by a client to register with its addresses.
Definition: nat.h:95
uint16_t num_addrs
Number of addresses that this service is bound to that follow.
Definition: nat.h:122
uint16_t str_len
Number of bytes in the string that follow which specifies a section name in the configuration.
Definition: nat.h:115
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_REGISTER.
Definition: nat.h:99
uint8_t flags
An enum GNUNET_NAT_RegisterFlags.
Definition: nat.h:104
uint8_t proto
Client's IPPROTO, e.g.
Definition: nat.h:109

References GNUNET_NAT_Handle::address_callback, GNUNET_NAT_Handle::callback_cls, cfg, GNUNET_NAT_Handle::cfg, do_connect(), GNUNET_NAT_RegisterMessage::flags, GNUNET_break, GNUNET_free, GNUNET_malloc, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_REGISTER, GNUNET_NAT_RF_ADDRESSES, GNUNET_NAT_RF_NONE, GNUNET_NAT_RF_REVERSAL, GNUNET_new, GNUNET_NAT_RegisterMessage::header, nh, GNUNET_NAT_RegisterMessage::num_addrs, proto, GNUNET_NAT_RegisterMessage::proto, GNUNET_NAT_Handle::reg, reversal_callback(), GNUNET_NAT_Handle::reversal_callback, GNUNET_MessageHeader::size, GNUNET_NAT_RegisterMessage::str_len, and GNUNET_MessageHeader::type.

Referenced by GNUNET_NAT_AUTO_test_start(), GNUNET_NAT_test_start(), nat_register(), run(), and try_anat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_add_global_address()

void GNUNET_NAT_add_global_address ( struct GNUNET_NAT_Handle nh,
char *  addr,
unsigned int  address_length 
)

Add global address to the list of addresses and notify clients.

Parameters
nhthe handle returned by register
addrIP address to add.
address_lengthnumber of bytes in addr

Definition at line 459 of file nat_api.c.

462{
464 struct GNUNET_MQ_Envelope *env;
465 //char *address_without_port = get_address_without_port (addr);
466 //unsigned int address_len_without_port = strlen (address_without_port);
467 char *off;
468
470 "natting address %s length %u\n",
471 addr,
472 address_length);
473
475 address_length,
477 aam->address_length = htons (address_length);
478 off = (char *) &aam[1];
479 GNUNET_memcpy (off, addr, address_length);
481 env);
482 //GNUNET_free (address_without_port);
483}
#define GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS
Message to ask NAT service to notify all clients about a new global address.
Message sent by client to add a global address.
Definition: nat.h:225
unsigned int address_length
Length of the address following the struct, in NBO.
Definition: nat.h:234
struct GNUNET_MQ_Handle * mq
Message queue for communicating with the NAT service.
Definition: nat_api.c:81

References GNUNET_NAT_AddGlobalAddressMessage::address_length, env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NAT_Handle::mq, and nh.

Referenced by handle_flow_control().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_test_address()

int GNUNET_NAT_test_address ( struct GNUNET_NAT_Handle nh,
const void *  addr,
socklen_t  addrlen 
)

Test if the given address is (currently) a plausible IP address for this peer.

Mostly a convenience function so that clients do not have to explicitly track all IPs that the GNUNET_NAT_AddressCallback has returned so far.

Parameters
nhthe handle returned by register
addrIP address to test (IPv4 or IPv6)
addrlennumber of bytes in addr
Returns
GNUNET_YES if the address is plausible, GNUNET_NO if the address is not plausible, GNUNET_SYSERR if the address is malformed

Definition at line 642 of file nat_api.c.

645{
646 struct AddrEntry *ae;
647
648 if ((addrlen != sizeof(struct sockaddr_in)) &&
649 (addrlen != sizeof(struct sockaddr_in6)))
650 {
651 GNUNET_break (0);
652 return GNUNET_SYSERR;
653 }
654 for (ae = nh->ae_head; NULL != ae; ae = ae->next)
655 if ((addrlen == ae->addrlen) && (0 == memcmp (addr, &ae[1], addrlen)))
656 return GNUNET_YES;
657 return GNUNET_NO;
658}
@ GNUNET_YES
@ GNUNET_NO
@ GNUNET_SYSERR
Entry in DLL of addresses of this peer.
Definition: nat_api.c:39
struct AddrEntry * next
DLL.
Definition: nat_api.c:43
socklen_t addrlen
Number of bytes that follow.
Definition: nat_api.c:64
struct AddrEntry * ae_head
Head of address DLL.
Definition: nat_api.c:91

References AddrEntry::addrlen, GNUNET_NAT_Handle::ae_head, GNUNET_break, GNUNET_NO, GNUNET_SYSERR, GNUNET_YES, AddrEntry::next, and nh.

◆ GNUNET_NAT_request_reversal()

int GNUNET_NAT_request_reversal ( struct GNUNET_NAT_Handle nh,
const struct sockaddr_in *  local_sa,
const struct sockaddr_in *  remote_sa 
)

We learned about a peer (possibly behind NAT) so run the gnunet-nat-client to send dummy ICMP responses to cause that peer to connect to us (connection reversal).

Parameters
nhhandle (used for configuration)
local_saour local address of the peer (IPv4-only)
remote_sathe remote address of the peer (IPv4-only)
Returns
GNUNET_SYSERR on error, GNUNET_NO if connection reversal is unavailable, GNUNET_OK otherwise (presumably in progress)

Definition at line 674 of file nat_api.c.

677{
678 struct GNUNET_MQ_Envelope *env;
680 char *buf;
681
682 if (NULL == nh->mq)
683 return GNUNET_SYSERR;
684 GNUNET_break (AF_INET == local_sa->sin_family);
685 GNUNET_break (AF_INET == remote_sa->sin_family);
686 env =
688 2 * sizeof(struct sockaddr_in),
690 req->local_addr_size = htons (sizeof(struct sockaddr_in));
691 req->remote_addr_size = htons (sizeof(struct sockaddr_in));
692 buf = (char *) &req[1];
693 GNUNET_memcpy (buf, local_sa, sizeof(struct sockaddr_in));
694 buf += sizeof(struct sockaddr_in);
695 GNUNET_memcpy (buf, remote_sa, sizeof(struct sockaddr_in));
697 return GNUNET_OK;
698}
#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL
Message to ask NAT service to request connection reversal.
Client asking the service to initiate connection reversal.
Definition: nat.h:161
uint16_t local_addr_size
Size of the local address included, in NBO.
Definition: nat.h:170
uint16_t remote_addr_size
Size of the remote address included, in NBO.
Definition: nat.h:175

References env, GNUNET_break, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, GNUNET_NAT_RequestConnectionReversalMessage::local_addr_size, GNUNET_NAT_Handle::mq, nh, and GNUNET_NAT_RequestConnectionReversalMessage::remote_addr_size.

Referenced by mq_init(), run(), and try_anat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_unregister()

void GNUNET_NAT_unregister ( struct GNUNET_NAT_Handle nh)

Stop port redirection and public IP address detection for the given handle.

This frees the handle, after having sent the needed commands to close open ports.

FIXME: No, the implementation of this API does not do anything beyond cleaning up the handle. This is a problem for applications that use GNUNET_NAT_AddressCallback and use the app_ctx to store objects, because the callback will never be called for cleanup on unregister.

Parameters
nhthe handle to unregister

Definition at line 702 of file nat_api.c.

703{
704 struct AddrEntry *ae;
705 struct AddrEntry *next;
706
707 if (NULL != nh->mq)
708 {
710 nh->mq = NULL;
711 }
712 if (NULL != nh->reconnect_task)
713 {
715 nh->reconnect_task = NULL;
716 }
717 next = nh->ae_head;
718 while (NULL != next)
719 {
720 ae = next;
721 next = next->next;
723 GNUNET_free (ae);
724 }
725 GNUNET_free (nh->reg);
726 GNUNET_free (nh);
727}
struct GNUNET_SCHEDULER_Task * reconnect_task
Task scheduled to reconnect to the service.
Definition: nat_api.c:116
struct AddrEntry * ae_tail
Tail of address DLL.
Definition: nat_api.c:96

References GNUNET_NAT_Handle::ae_head, GNUNET_NAT_Handle::ae_tail, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_cancel(), GNUNET_NAT_Handle::mq, AddrEntry::next, nh, GNUNET_NAT_Handle::reconnect_task, and GNUNET_NAT_Handle::reg.

Referenced by do_shutdown(), GNUNET_NAT_AUTO_test_stop(), GNUNET_NAT_test_stop(), and try_anat().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_stun_handle_packet()

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.

This function is useful as some GNUnet service may be listening on a UDP port and might thus receive STUN messages while trying to receive other data. In this case, this function can be used to process replies to STUN requests.

The function does some basic sanity checks on packet size and content, try to extract a bit of information.

At the moment this only processes BIND requests, and returns the externally visible address of the request to the rest of the NAT logic.

Parameters
nhhandle to the NAT service
sender_addraddress from which we got data
sender_addr_lennumber of bytes in sender_addr
datathe packet
data_sizenumber of bytes in data
Returns
GNUNET_OK on success GNUNET_NO if the packet is not a STUN packet GNUNET_SYSERR on internal error handling the packet

Definition at line 600 of file nat_api.c.

605{
606 struct GNUNET_MQ_Envelope *env;
608 char *buf;
609
611 return GNUNET_NO;
612 if (NULL == nh->mq)
613 return GNUNET_SYSERR;
615 data_size + sender_addr_len,
617 hsn->sender_addr_size = htons ((uint16_t) sender_addr_len);
618 hsn->payload_size = htons ((uint16_t) data_size);
619 buf = (char *) &hsn[1];
620 GNUNET_memcpy (buf, sender_addr, sender_addr_len);
621 buf += sender_addr_len;
624 return GNUNET_OK;
625}
static char * data
The data to insert into the dht.
static size_t data_size
Number of bytes in data.
#define GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN
Message to ask NAT service to handle a STUN packet.
static enum GNUNET_GenericReturnValue test_stun_packet(const void *data, size_t len)
Check if an incoming message is a STUN message.
Definition: nat_api.c:496
Client telling the service to (possibly) handle a STUN message.
Definition: nat.h:135
uint16_t payload_size
Number of bytes of payload included, in NBO.
Definition: nat.h:149
uint16_t sender_addr_size
Size of the sender address included, in NBO.
Definition: nat.h:144

References data, data_size, env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, GNUNET_NAT_Handle::mq, nh, GNUNET_NAT_HandleStunMessage::payload_size, GNUNET_NAT_HandleStunMessage::sender_addr_size, and test_stun_packet().

Referenced by do_udp_read(), and stun_read_task().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_stun_make_request()

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.

Sends a generic stun request to the server specified using the specified socket. If we do this, we need to watch for possible responses and call GNUNET_NAT_stun_handle_packet() on incoming packets.

Parameters
serverthe address of the stun server
portport of the stun server, in host byte order
sockthe socket used to send the request, must be a UDP socket
cbcallback in case of error
cb_clsclosure for cb
Returns
NULL on error

Sends a generic stun request to the server specified using the specified socket.

Parameters
serverthe address of the stun server
portport of the stun server, in host byte order
sockthe socket used to send the request
cbcallback in case of error
cb_clsclosure for cb
Returns
NULL on error

Definition at line 211 of file nat_api_stun.c.

216{
217 struct GNUNET_NAT_STUN_Handle *rh;
218
220 rh->sock = sock;
221 rh->cb = cb;
222 rh->cb_cls = cb_cls;
223 rh->stun_server = GNUNET_strdup (server);
224 rh->stun_port = port;
227 AF_INET,
228 TIMEOUT,
230 rh);
231 if (NULL == rh->dns_active)
232 {
234 return NULL;
235 }
236 return rh;
237}
static uint16_t port
Port number.
Definition: gnunet-bcd.c:147
void GNUNET_NAT_stun_make_request_cancel(struct GNUNET_NAT_STUN_Handle *rh)
Cancel active STUN request.
Definition: nat_api_stun.c:247
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_ip_get(const char *hostname, int af, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_AddressCallback callback, void *callback_cls)
Convert a string to one or more IP addresses.
Definition: resolver_api.c:940
static void stun_dns_callback(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Try to establish a connection given the specified address.
Definition: nat_api_stun.c:135
#define TIMEOUT
Definition: nat_api_stun.c:48
Handle to a request given to the resolver.
Definition: nat_api_stun.c:57
int dns_success
Do we got a DNS resolution successfully?
Definition: nat_api_stun.c:86
GNUNET_NAT_TestCallback cb
Function to call when a error occurs.
Definition: nat_api_stun.c:76
struct GNUNET_RESOLVER_RequestHandle * dns_active
Handle to a pending DNS lookup request.
Definition: nat_api_stun.c:61
void * cb_cls
Closure for cb.
Definition: nat_api_stun.c:81
char * stun_server
Stun server address.
Definition: nat_api_stun.c:71
uint16_t stun_port
STUN port.
Definition: nat_api_stun.c:91
struct GNUNET_NETWORK_Handle * sock
Handle to the listen socket.
Definition: nat_api_stun.c:66

References GNUNET_NAT_STUN_Handle::cb, GNUNET_NAT_STUN_Handle::cb_cls, GNUNET_NAT_STUN_Handle::dns_active, GNUNET_NAT_STUN_Handle::dns_success, GNUNET_NAT_stun_make_request_cancel(), GNUNET_new, GNUNET_NO, GNUNET_RESOLVER_ip_get(), GNUNET_strdup, port, GNUNET_NAT_STUN_Handle::sock, stun_dns_callback(), GNUNET_NAT_STUN_Handle::stun_port, GNUNET_NAT_STUN_Handle::stun_server, and TIMEOUT.

Referenced by test_stun().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_NAT_stun_make_request_cancel()

void GNUNET_NAT_stun_make_request_cancel ( struct GNUNET_NAT_STUN_Handle rh)

Cancel active STUN request.

Frees associated resources and ensures that the callback is no longer invoked.

Parameters
rhrequest to cancel

Definition at line 247 of file nat_api_stun.c.

248{
249 if (NULL != rh->dns_active)
250 {
252 rh->dns_active = NULL;
253 }
255 GNUNET_free (rh);
256}
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.

References GNUNET_NAT_STUN_Handle::dns_active, GNUNET_free, GNUNET_RESOLVER_request_cancel(), and GNUNET_NAT_STUN_Handle::stun_server.

Referenced by GNUNET_NAT_stun_make_request(), and stun_dns_callback().

Here is the call graph for this function:
Here is the caller graph for this function: