network address translation traversal service More...
#include "platform.h"
#include <math.h>
#include "gnunet_util_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_signatures.h"
#include "gnunet_statistics_service.h"
#include "gnunet_resolver_service.h"
#include "gnunet_nat_service.h"
#include "gnunet-service-nat.h"
#include "gnunet-service-nat_externalip.h"
#include "gnunet-service-nat_stun.h"
#include "gnunet-service-nat_mini.h"
#include "gnunet-service-nat_helper.h"
#include "nat.h"
#include <gcrypt.h>
Go to the source code of this file.
Data Structures | |
struct | ClientAddress |
Information we track per client address. More... | |
struct | LocalAddressList |
List of local addresses this system has. More... | |
struct | ClientHandle |
Struct containing information about a client, handle to connect to it, and any pending messages that need to be sent to it. More... | |
struct | StunExternalIP |
External IP address as given to us via some STUN server. More... | |
struct | IfcProcContext |
Closure for ifc_proc. More... | |
Macros | |
#define | SCAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
How often should we ask the OS about a list of active network interfaces? More... | |
#define | AUTOCONFIG_TIMEOUT |
How long do we wait until we forcefully terminate autoconfiguration? More... | |
#define | DYNDNS_FREQUENCY |
How often do we scan for changes in how our external (dyndns) hostname resolves? More... | |
Functions | |
static void | free_lal (struct LocalAddressList *lal) |
Remove and free an entry from the lal_head DLL. More... | |
static void | destroy_lal () |
Free the DLL starting at lal_head. More... | |
static int | check_register (void *cls, const struct GNUNET_NAT_RegisterMessage *message) |
Check validity of GNUNET_MESSAGE_TYPE_NAT_REGISTER message from client. More... | |
static int | match_ipv4 (const char *network, const struct in_addr *ip, uint8_t bits) |
Check if ip is in network with bits netmask. More... | |
static int | match_ipv6 (const char *network, const struct in6_addr *ip, uint8_t bits) |
Check if ip is in network with bits netmask. More... | |
static int | is_nat_v4 (const struct in_addr *ip) |
Test if the given IPv4 address is in a known range for private networks. More... | |
static int | is_nat_v6 (const struct in6_addr *ip) |
Test if the given IPv6 address is in a known range for private networks. More... | |
static int | ifc_proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, socklen_t addrlen) |
Callback function invoked for each interface found. More... | |
static void | notify_client (enum GNUNET_NAT_AddressClass ac, struct ClientHandle *ch, int add, const void *addr, size_t addr_len) |
Notify client about a change in the list of addresses this peer has. More... | |
static void | check_notify_client (struct LocalAddressList *delta, struct ClientHandle *ch, int add) |
Check if we should bother to notify this client about this address change, and if so, do it. More... | |
static void | notify_clients (struct LocalAddressList *delta, int add) |
Notify all clients about a change in the list of addresses this peer has. More... | |
static void | notify_client_external_ipv4_change (void *cls, const struct in_addr *v4, int add) |
Tell relevant client about a change in our external IPv4 address. More... | |
static void | reversal_callback (void *cls, const struct sockaddr_in *ra) |
We got a connection reversal request from another peer. More... | |
static void | run_scan (void *cls) |
Task we run periodically to scan for network interfaces. More... | |
static void | upnp_addr_change_cb (void *cls, int add_remove, const struct sockaddr *addr, socklen_t addrlen, enum GNUNET_NAT_StatusCode result) |
Function called whenever our set of external addresses as created by upnpc changes. More... | |
static void | dyndns_lookup (void *cls) |
Resolve the hole_external name to figure out our external address from a manually punched hole. More... | |
static void | process_external_ip (void *cls, const struct sockaddr *addr, socklen_t addrlen) |
Our (external) hostname was resolved. More... | |
static void | lookup_hole_external (struct ClientHandle *ch) |
Resolve the hole_external name to figure out our external address from a manually punched hole. More... | |
static void | handle_register (void *cls, const struct GNUNET_NAT_RegisterMessage *message) |
Handler for GNUNET_MESSAGE_TYPE_NAT_REGISTER message from client. More... | |
static int | check_stun (void *cls, const struct GNUNET_NAT_HandleStunMessage *message) |
Check validity of GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN message from client. More... | |
static void | notify_clients_stun_change (const struct sockaddr_in *ip, int add) |
Notify all clients about our external IP address as reported by the STUN server. More... | |
static void | stun_ip_timeout (void *cls) |
Function to be called when we decide that an external IP address as told to us by a STUN server has gone stale. More... | |
static void | handle_stun (void *cls, const struct GNUNET_NAT_HandleStunMessage *message) |
Handler for GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN message from client. More... | |
static int | check_request_connection_reversal (void *cls, const struct GNUNET_NAT_RequestConnectionReversalMessage *message) |
Check validity of GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL message from client. More... | |
static void | handle_request_connection_reversal (void *cls, const struct GNUNET_NAT_RequestConnectionReversalMessage *message) |
Handler for GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL message from client. More... | |
static enum GNUNET_GenericReturnValue | check_add_global_address (void *cls, const struct GNUNET_NAT_AddGlobalAddressMessage *message) |
Check validity of GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS message from client. More... | |
static void | handle_add_global_address (void *cls, const struct GNUNET_NAT_AddGlobalAddressMessage *message) |
Handle GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS message from client. More... | |
static void | shutdown_task (void *cls) |
Task run during shutdown. More... | |
static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service) |
Setup NAT service. More... | |
static void * | client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq) |
Callback called when a client connects to the service. More... | |
static void | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) |
Callback called when a client disconnected from the service. More... | |
GNUNET_SERVICE_MAIN ("nat", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(register, GNUNET_MESSAGE_TYPE_NAT_REGISTER, struct GNUNET_NAT_RegisterMessage, NULL), GNUNET_MQ_hd_var_size(stun, GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN, struct GNUNET_NAT_HandleStunMessage, NULL), GNUNET_MQ_hd_var_size(request_connection_reversal, GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL, struct GNUNET_NAT_RequestConnectionReversalMessage, NULL), GNUNET_MQ_hd_var_size(add_global_address, GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS, struct GNUNET_NAT_AddGlobalAddressMessage, NULL), GNUNET_MQ_handler_end()) | |
Define "main" method using service macro. More... | |
Variables | |
static struct GNUNET_TIME_Relative | stun_stale_timeout |
Timeout to use when STUN data is considered stale. More... | |
static struct GNUNET_TIME_Relative | dyndns_frequency |
How often do we scan for changes in how our external (dyndns) hostname resolves? More... | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Handle to our current configuration. More... | |
static struct GNUNET_STATISTICS_Handle * | stats |
Handle to the statistics service. More... | |
static struct GNUNET_SCHEDULER_Task * | scan_task |
Task scheduled to periodically scan our network interfaces. More... | |
static struct ClientHandle * | ch_head |
Head of client DLL. More... | |
static struct ClientHandle * | ch_tail |
Tail of client DLL. More... | |
static struct LocalAddressList * | lal_head |
Head of DLL of local addresses. More... | |
static struct LocalAddressList * | lal_tail |
Tail of DLL of local addresses. More... | |
static struct StunExternalIP * | se_head |
Kept in a DLL. More... | |
static struct StunExternalIP * | se_tail |
Kept in a DLL. More... | |
int | enable_upnp |
Is UPnP enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, GNUNET_SYSERR if configuration enabled but binary is unavailable. More... | |
int | enable_ipscan |
Is IP Scanning enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, without, only explicitly specified IPs will be handled (HOLE_EXTERNAL) More... | |
network address translation traversal service
The purpose of this service is to enable transports to traverse NAT routers, by providing traversal options and knowledge about the local network topology.
TODO:
Definition in file gnunet-service-nat.c.
#define SCAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) |
How often should we ask the OS about a list of active network interfaces?
Definition at line 58 of file gnunet-service-nat.c.
#define AUTOCONFIG_TIMEOUT |
How long do we wait until we forcefully terminate autoconfiguration?
Definition at line 63 of file gnunet-service-nat.c.
#define DYNDNS_FREQUENCY |
How often do we scan for changes in how our external (dyndns) hostname resolves?
Definition at line 69 of file gnunet-service-nat.c.
|
static |
Remove and free an entry from the lal_head DLL.
lal | entry to free |
Definition at line 350 of file gnunet-service-nat.c.
References LocalAddressList::addr, GN_stop_gnunet_nat_server_(), GNUNET_a2s(), GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_MESSAGE, GNUNET_free, GNUNET_log, LocalAddressList::hc, lal_head, and lal_tail.
Referenced by destroy_lal(), and run_scan().
|
static |
Free the DLL starting at lal_head.
Definition at line 373 of file gnunet-service-nat.c.
References free_lal(), and lal_head.
Referenced by shutdown_task().
|
static |
Check validity of GNUNET_MESSAGE_TYPE_NAT_REGISTER message from client.
cls | client who sent the message |
message | the message received |
Definition at line 391 of file gnunet-service-nat.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAT_RegisterMessage::header, GNUNET_NAT_RegisterMessage::num_addrs, GNUNET_MessageHeader::size, and GNUNET_NAT_RegisterMessage::str_len.
|
static |
Check if ip is in network with bits netmask.
network | to test |
ip | IP address to test |
bits | bitmask for the network |
Definition at line 453 of file gnunet-service-nat.c.
References GNUNET_assert, and GNUNET_YES.
Referenced by check_notify_client(), ifc_proc(), and is_nat_v4().
|
static |
Check if ip is in network with bits netmask.
network | to test |
ip | IP address to test |
bits | bitmask for the network |
Definition at line 479 of file gnunet-service-nat.c.
References GNUNET_assert, GNUNET_memcmp, GNUNET_NO, and GNUNET_YES.
Referenced by check_notify_client(), ifc_proc(), and is_nat_v6().
|
static |
Test if the given IPv4 address is in a known range for private networks.
ip | address to test |
Definition at line 523 of file gnunet-service-nat.c.
References match_ipv4().
Referenced by check_notify_client(), handle_register(), ifc_proc(), notify_client_external_ipv4_change(), and upnp_addr_change_cb().
|
static |
Test if the given IPv6 address is in a known range for private networks.
ip | address to test |
Definition at line 542 of file gnunet-service-nat.c.
References match_ipv6().
Referenced by check_notify_client(), handle_register(), ifc_proc(), and upnp_addr_change_cb().
|
static |
Callback function invoked for each interface found.
Adds them to our new address list.
cls | a struct IfcProcContext * |
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 address |
Definition at line 582 of file gnunet-service-nat.c.
References LocalAddressList::ac, LocalAddressList::addr, LocalAddressList::af, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_malloc, GNUNET_memcpy, GNUNET_NAT_AC_GLOBAL, GNUNET_NAT_AC_LAN, GNUNET_NAT_AC_LOOPBACK, GNUNET_NAT_AC_PRIVATE, GNUNET_OK, is_nat_v4(), is_nat_v6(), IfcProcContext::lal_head, IfcProcContext::lal_tail, match_ipv4(), and match_ipv6().
Referenced by run_scan().
|
static |
Notify client about a change in the list of addresses this peer has.
ac | address class of the entry in the list that changed |
ch | client to contact |
add | GNUNET_YES to add, GNUNET_NO to remove |
addr | the address that changed |
addr_len | number of bytes in addr |
Definition at line 660 of file gnunet-service-nat.c.
References add, ch, env, GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_CADET_Channel::mq, and msg.
Referenced by check_notify_client(), notify_client_external_ipv4_change(), and upnp_addr_change_cb().
|
static |
Check if we should bother to notify this client about this address change, and if so, do it.
delta | the entry in the list that changed |
ch | client to check |
add | GNUNET_YES to add, GNUNET_NO to remove |
Definition at line 696 of file gnunet-service-nat.c.
References add, ch, delta, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcmp, GNUNET_memcpy, GNUNET_NAT_AC_EXTERN, GNUNET_NAT_RF_ADDRESSES, is_nat_v4(), is_nat_v6(), match_ipv4(), match_ipv6(), and notify_client().
Referenced by handle_register(), lookup_hole_external(), notify_client_external_ipv4_change(), notify_clients(), and process_external_ip().
|
static |
Notify all clients about a change in the list of addresses this peer has.
delta | the entry in the list that changed |
add | GNUNET_YES to add, GNUNET_NO to remove |
Definition at line 824 of file gnunet-service-nat.c.
References add, ch, ch_head, check_notify_client(), and delta.
Referenced by run_scan().
|
static |
Tell relevant client about a change in our external IPv4 address.
cls | client to check if it cares and possibly notify |
v4 | the external address that changed |
add | GNUNET_YES to add, GNUNET_NO to remove |
Definition at line 845 of file gnunet-service-nat.c.
References LocalAddressList::ac, add, LocalAddressList::addr, LocalAddressList::af, ch, check_notify_client(), GNUNET_a2s(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_NAT_AC_EXTERN, GNUNET_NAT_AC_GLOBAL, GNUNET_NAT_AC_LAN, GNUNET_NAT_AC_MANUAL, GNUNET_NO, GNUNET_YES, is_nat_v4(), and notify_client().
Referenced by handle_register().
|
static |
We got a connection reversal request from another peer.
Notify applicable clients.
cls | closure with the struct LocalAddressList |
ra | IP address of the peer who wants us to connect to it |
Definition at line 924 of file gnunet-service-nat.c.
References LocalAddressList::addr, LocalAddressList::af, ch, ch_head, env, GNUNET_assert, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NO, GNUNET_YES, GNUNET_CADET_Channel::mq, and ClientAddress::ss.
Referenced by GNUNET_NAT_register(), and run_scan().
|
static |
Task we run periodically to scan for network interfaces.
cls | NULL |
Definition at line 981 of file gnunet-service-nat.c.
References cfg, free_lal(), GN_nat_status_changed(), GN_start_gnunet_nat_server_(), GNUNET_a2s(), GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NAT_AC_LAN, GNUNET_NO, GNUNET_OS_network_interfaces_list(), GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, ifc_proc(), lal_head, IfcProcContext::lal_head, lal_tail, IfcProcContext::lal_tail, LocalAddressList::next, notify_clients(), reversal_callback(), run_scan(), SCAN_FREQ, and scan_task.
Referenced by run(), and run_scan().
|
static |
Function called whenever our set of external addresses as created by upnpc
changes.
cls | closure with our struct ClientHandle * |
add_remove | GNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one, GNUNET_SYSERR indicates an error |
addr | either the previous or the new public IP address |
addrlen | actual length of the addr |
result | GNUNET_NAT_ERROR_SUCCESS on success, otherwise the specific error code |
Definition at line 1094 of file gnunet-service-nat.c.
References ch, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_NAT_AC_EXTERN, GNUNET_NAT_AC_LAN, 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_IPC_FAILURE, GNUNET_NAT_ERROR_SUCCESS, GNUNET_NAT_ERROR_UPNPC_FAILED, GNUNET_NAT_ERROR_UPNPC_NOT_FOUND, GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED, GNUNET_NAT_ERROR_UPNPC_TIMEOUT, is_nat_v4(), is_nat_v6(), notify_client(), and result.
Referenced by handle_register().
|
static |
Resolve the hole_external
name to figure out our external address from a manually punched hole.
The port number has already been parsed, this task is responsible for periodically doing a DNS lookup.
cls | client handle to act upon |
The port number has already been parsed, this task is responsible for periodically doing a DNS lookup.
ch | client handle to act upon |
Definition at line 1307 of file gnunet-service-nat.c.
References ch, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_RESOLVER_ip_get(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, LocalAddressList::next, LocalAddressList::old, and process_external_ip().
Referenced by lookup_hole_external(), and process_external_ip().
|
static |
Our (external) hostname was resolved.
Update lists of current external IPs (note that DNS may return multiple addresses!) and notify client accordingly.
cls | the struct ClientHandle |
addr | NULL on error, otherwise result of DNS lookup |
addrlen | number of bytes in addr |
Definition at line 1204 of file gnunet-service-nat.c.
References LocalAddressList::ac, LocalAddressList::addr, LocalAddressList::af, ch, check_notify_client(), dyndns_frequency, dyndns_lookup(), GNUNET_a2s(), GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_memcpy, GNUNET_NAT_AC_GLOBAL, GNUNET_NAT_AC_MANUAL, GNUNET_new, GNUNET_NO, GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, LocalAddressList::next, and LocalAddressList::old.
Referenced by dyndns_lookup().
|
static |
Resolve the hole_external
name to figure out our external address from a manually punched hole.
The given name may be "AUTO" in which case we should use the IP address(es) we have from upnpc or other methods. The name can also be an IP address, in which case we do not need to do DNS resolution. Finally, we also need to parse the port number.
ch | client handle to act upon |
Definition at line 1340 of file gnunet-service-nat.c.
References _, LocalAddressList::ac, LocalAddressList::addr, LocalAddressList::af, ch, check_notify_client(), dyndns_lookup(), GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_free, GNUNET_log, GNUNET_NAT_AC_GLOBAL, GNUNET_NAT_AC_MANUAL, GNUNET_new, GNUNET_SCHEDULER_add_now(), GNUNET_YES, and port.
Referenced by handle_register().
|
static |
Handler for GNUNET_MESSAGE_TYPE_NAT_REGISTER message from client.
We remember the client for updates upon future NAT events.
cls | client who sent the message |
message | the message received |
Definition at line 1452 of file gnunet-service-nat.c.
References cfg, ch, check_notify_client(), enable_upnp, GNUNET_NAT_RegisterMessage::flags, GN_external_ipv4_monitor_start(), GNUNET_assert, GNUNET_break, GNUNET_CONFIGURATION_get_value_string(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_NAT_mini_map_start(), GNUNET_new_array, GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_strndup, GNUNET_YES, GNUNET_NAT_RegisterMessage::header, is_nat_v4(), is_nat_v6(), lal_head, lookup_hole_external(), LocalAddressList::next, notify_client_external_ipv4_change(), GNUNET_NAT_RegisterMessage::num_addrs, port, GNUNET_NAT_RegisterMessage::proto, GNUNET_MessageHeader::size, GNUNET_NAT_RegisterMessage::str_len, and upnp_addr_change_cb().
|
static |
Check validity of GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN message from client.
cls | client who sent the message |
message | the message received |
Definition at line 1592 of file gnunet-service-nat.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAT_HandleStunMessage::header, GNUNET_NAT_HandleStunMessage::payload_size, GNUNET_NAT_HandleStunMessage::sender_addr_size, and GNUNET_MessageHeader::size.
|
static |
Notify all clients about our external IP address as reported by the STUN server.
ip | the external IP |
add | GNUNET_YES to add, GNUNET_NO to remove |
Definition at line 1620 of file gnunet-service-nat.c.
References add, ch, ch_head, env, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_NAT_AC_EXTERN, GNUNET_NAT_AC_GLOBAL, GNUNET_CADET_Channel::mq, and msg.
Referenced by handle_add_global_address(), handle_stun(), and stun_ip_timeout().
|
static |
Function to be called when we decide that an external IP address as told to us by a STUN server has gone stale.
cls | the struct StunExternalIP to drop |
Definition at line 1658 of file gnunet-service-nat.c.
References StunExternalIP::external_addr, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, notify_clients_stun_change(), se_head, se_tail, and StunExternalIP::timeout_task.
Referenced by handle_stun().
|
static |
Handler for GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN message from client.
cls | client who sent the message |
message | the message received |
Definition at line 1680 of file gnunet-service-nat.c.
References ch, StunExternalIP::external_addr, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcmp, GNUNET_memcpy, GNUNET_NAT_stun_handle_packet_(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_YES, StunExternalIP::next, notify_clients_stun_change(), payload, GNUNET_NAT_HandleStunMessage::payload_size, se_head, se_tail, GNUNET_NAT_HandleStunMessage::sender_addr_size, stun_ip_timeout(), StunExternalIP::stun_server_addr, StunExternalIP::stun_server_addr_len, stun_stale_timeout, and StunExternalIP::timeout_task.
|
static |
Check validity of GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL message from client.
cls | client who sent the message |
message | the message received |
Definition at line 1793 of file gnunet-service-nat.c.
References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAT_RequestConnectionReversalMessage::header, GNUNET_NAT_RequestConnectionReversalMessage::local_addr_size, GNUNET_NAT_RequestConnectionReversalMessage::remote_addr_size, and GNUNET_MessageHeader::size.
|
static |
Handler for GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL message from client.
cls | client who sent the message |
message | the message received |
Definition at line 1819 of file gnunet-service-nat.c.
References _, cfg, ch, GN_request_connection_reversal(), GNUNET_break_op, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcpy, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_NAT_RequestConnectionReversalMessage::local_addr_size, GNUNET_NAT_RequestConnectionReversalMessage::remote_addr_size, and ret.
|
static |
Check validity of GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS message from client.
cls | client who sent the message |
message | the message received |
Definition at line 1874 of file gnunet-service-nat.c.
References GNUNET_NAT_AddGlobalAddressMessage::address_length, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, GNUNET_NAT_AddGlobalAddressMessage::header, and GNUNET_MessageHeader::size.
|
static |
Handle GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS message from client.
cls | client who sent the message |
message | the message received |
Definition at line 1904 of file gnunet-service-nat.c.
References GNUNET_NAT_AddGlobalAddressMessage::address_length, ch, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_SERVICE_client_continue(), GNUNET_YES, and notify_clients_stun_change().
|
static |
Task run during shutdown.
cls | unused |
Definition at line 1940 of file gnunet-service-nat.c.
References destroy_lal(), GN_nat_status_changed(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NO, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_destroy(), scan_task, se_head, se_tail, stats, and StunExternalIP::timeout_task.
Referenced by run().
|
static |
Setup NAT service.
cls | closure |
c | configuration to use |
service | the initialized service |
Definition at line 1976 of file gnunet-service-nat.c.
References _, cfg, DYNDNS_FREQUENCY, dyndns_frequency, enable_ipscan, enable_upnp, GNUNET_CONFIGURATION_get_value_time(), GNUNET_CONFIGURATION_get_value_yesno(), GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_SCHEDULER_add_now(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_STATISTICS_create(), GNUNET_SYSERR, GNUNET_TIME_UNIT_HOURS, GNUNET_YES, run_scan(), scan_task, shutdown_task(), stats, and stun_stale_timeout.
|
static |
Callback called when a client connects to the service.
cls | closure for the service |
c | the new client that connected to the service |
mq | the message queue used to send messages to the client |
struct ClientHandle
Definition at line 2038 of file gnunet-service-nat.c.
References ch, ch_head, ch_tail, GNUNET_CONTAINER_DLL_insert, GNUNET_new, mq, and GNUNET_CADET_Channel::mq.
|
static |
Callback called when a client disconnected from the service.
cls | closure for the service |
c | the client that disconnected |
internal_cls | a struct ClientHandle * |
Definition at line 2062 of file gnunet-service-nat.c.
References ch, ch_head, ch_tail, GN_external_ipv4_monitor_stop(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_NAT_mini_map_stop(), GNUNET_RESOLVER_request_cancel(), and GNUNET_SCHEDULER_cancel().
GNUNET_SERVICE_MAIN | ( | "nat" | , |
GNUNET_SERVICE_OPTION_NONE | , | ||
& | run, | ||
& | client_connect_cb, | ||
& | client_disconnect_cb, | ||
NULL | , | ||
GNUNET_MQ_hd_var_size(register, GNUNET_MESSAGE_TYPE_NAT_REGISTER, struct GNUNET_NAT_RegisterMessage, NULL) | , | ||
GNUNET_MQ_hd_var_size(stun, GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN, struct GNUNET_NAT_HandleStunMessage, NULL) | , | ||
GNUNET_MQ_hd_var_size(request_connection_reversal, GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL, struct GNUNET_NAT_RequestConnectionReversalMessage, NULL) | , | ||
GNUNET_MQ_hd_var_size(add_global_address, GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS, struct GNUNET_NAT_AddGlobalAddressMessage, NULL) | , | ||
GNUNET_MQ_handler_end() | |||
) |
Define "main" method using service macro.
|
static |
Timeout to use when STUN data is considered stale.
Definition at line 280 of file gnunet-service-nat.c.
Referenced by handle_stun(), and run().
|
static |
How often do we scan for changes in how our external (dyndns) hostname resolves?
Definition at line 285 of file gnunet-service-nat.c.
Referenced by process_external_ip(), and run().
|
static |
Handle to our current configuration.
Definition at line 290 of file gnunet-service-nat.c.
Referenced by handle_register(), handle_request_connection_reversal(), run(), and run_scan().
|
static |
Handle to the statistics service.
Definition at line 295 of file gnunet-service-nat.c.
Referenced by run(), and shutdown_task().
|
static |
Task scheduled to periodically scan our network interfaces.
Definition at line 300 of file gnunet-service-nat.c.
Referenced by run(), run_scan(), and shutdown_task().
|
static |
Head of client DLL.
Definition at line 305 of file gnunet-service-nat.c.
Referenced by client_connect_cb(), client_disconnect_cb(), notify_clients(), notify_clients_stun_change(), and reversal_callback().
|
static |
Tail of client DLL.
Definition at line 310 of file gnunet-service-nat.c.
Referenced by client_connect_cb(), and client_disconnect_cb().
|
static |
Head of DLL of local addresses.
Definition at line 315 of file gnunet-service-nat.c.
Referenced by destroy_lal(), free_lal(), handle_register(), and run_scan().
|
static |
Tail of DLL of local addresses.
Definition at line 320 of file gnunet-service-nat.c.
Referenced by free_lal(), and run_scan().
|
static |
Kept in a DLL.
Definition at line 325 of file gnunet-service-nat.c.
Referenced by handle_stun(), shutdown_task(), and stun_ip_timeout().
|
static |
Kept in a DLL.
Definition at line 330 of file gnunet-service-nat.c.
Referenced by handle_stun(), shutdown_task(), and stun_ip_timeout().
int enable_upnp |
Is UPnP enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, GNUNET_SYSERR if configuration enabled but binary is unavailable.
Definition at line 336 of file gnunet-service-nat.c.
Referenced by GN_nat_status_changed(), handle_register(), and run().
int enable_ipscan |
Is IP Scanning enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, without, only explicitly specified IPs will be handled (HOLE_EXTERNAL)
Definition at line 342 of file gnunet-service-nat.c.
Referenced by run().