56#define SCAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
61#define AUTOCONFIG_TIMEOUT GNUNET_TIME_relative_multiply ( \
62 GNUNET_TIME_UNIT_SECONDS, 5)
67#define DYNDNS_FREQUENCY GNUNET_TIME_relative_multiply ( \
68 GNUNET_TIME_UNIT_MINUTES, 7)
79 struct sockaddr_storage
ss;
356 "Lost NATed local address %s, stopping NAT server\n",
358 sizeof(
struct sockaddr_in)));
392 uint16_t num_addrs = ntohs (message->
num_addrs);
393 const char *off = (
const char *) &message[1];
394 size_t left = ntohs (message->
header.
size) -
sizeof(*message);
396 for (
unsigned int i = 0; i < num_addrs; i++)
399 const struct sockaddr *sa = (
const struct sockaddr *) off;
401 if (
sizeof(sa_family_t) > left)
406 switch (sa->sa_family)
409 alen =
sizeof(
struct sockaddr_in);
413 alen =
sizeof(
struct sockaddr_in6);
418 alen =
sizeof(
struct sockaddr_un);
433 if (left != ntohs (message->
str_len))
452 const struct in_addr *ip,
464 return ! ((ip->s_addr ^ net.s_addr) & htonl (0xFFFFFFFFu << (32 - bits)));
478 const struct in6_addr *ip,
482 struct in6_addr mask;
490 memset (&mask, 0,
sizeof(mask));
497 mask.s6_addr[off++] = 0xFF;
502 mask.s6_addr[off] = (mask.s6_addr[off] >> 1) + 0x80;
505 for (
unsigned j = 0; j <
sizeof(
struct in6_addr) / sizeof(uint32_t); j++)
506 if (((((uint32_t *) ip)[j] & ((uint32_t *) &mask)[j])) !=
507 (((uint32_t *) &net)[j] & ((
int *) &mask)[j]))
583 const struct sockaddr *
addr,
584 const struct sockaddr *broadcast_addr,
585 const struct sockaddr *netmask,
591 const struct in_addr *ip4;
592 const struct in6_addr *ip6;
595 switch (addr->sa_family)
598 alen =
sizeof(
struct sockaddr_in);
599 ip4 = &((
const struct sockaddr_in *) addr)->sin_addr;
609 alen =
sizeof(
struct sockaddr_in6);
610 ip6 = &((
const struct sockaddr_in6 *) addr)->sin6_addr;
617 if ((ip6->s6_addr[11] == 0xFF) &&
618 (ip6->s6_addr[12] == 0xFE))
635 lal->
af = addr->sa_family;
668 "Notifying client about %s of IP %s\n",
669 add ?
"addition" :
"removal",
675 msg->add_remove = htonl (
add);
676 msg->addr_class = htonl (ac);
699 struct sockaddr_in v4;
700 struct sockaddr_in6 v6;
705 "Not notifying client as it does not care about addresses\n");
711 alen =
sizeof(
struct sockaddr_in);
717 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
719 const struct sockaddr_in *c4;
721 if (AF_INET !=
ch->caddrs[i].ss.ss_family)
723 c4 = (
const struct sockaddr_in *) &
ch->caddrs[i].ss;
724 if (
match_ipv4 (
"127.0.0.1", &c4->sin_addr, 8) &&
725 (0 != c4->sin_addr.s_addr) &&
726 (!
match_ipv4 (
"127.0.0.1", &v4.sin_addr, 8)))
728 if ((!
match_ipv4 (
"127.0.0.1", &c4->sin_addr, 8)) &&
732 (0 != c4->sin_addr.s_addr) &&
738 (0 != c4->sin_addr.s_addr) &&
744 if (0 == htons (v4.sin_port))
745 v4.sin_port = c4->sin_port;
755 alen =
sizeof(
struct sockaddr_in6);
759 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
761 const struct sockaddr_in6 *c6;
763 if (AF_INET6 !=
ch->caddrs[i].ss.ss_family)
765 c6 = (
const struct sockaddr_in6 *) &
ch->caddrs[i].ss;
766 if (
match_ipv6 (
"::1", &c6->sin6_addr, 128) &&
771 if ((!
match_ipv6 (
"::1", &c6->sin6_addr, 128)) &&
787 if ((
match_ipv6 (
"fe80::", &c6->sin6_addr, 10)) &&
797 if (0 == htons (v6.sin6_port))
798 v6.sin6_port = c6->sin6_port;
844 const struct in_addr *v4,
848 struct sockaddr_in sa;
852 if ((NULL !=
ch->hole_external) &&
853 (0 == strcasecmp (
ch->hole_external,
857 struct sockaddr_in *s4;
860 "Detected eternal IP, can now back-fill AUTO:%u in hole punching specification of `%s'\n",
861 (
unsigned int)
ch->ext_dns_port,
863 memset (&lal, 0,
sizeof(lal));
864 s4 = (
struct sockaddr_in *) &lal.
addr;
865 s4->sin_family = AF_INET;
866 s4->sin_port = htons (
ch->ext_dns_port);
876 if (!
ch->natted_address)
879 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
881 const struct sockaddr_storage *ss = &
ch->caddrs[i].ss;
883 if (AF_INET != ss->ss_family)
895 sa.sin_family = AF_INET;
897 sa.sin_port = htons (0);
900 "Detected eternal IP %s, notifying client of external IP (without port)\n",
923 const struct sockaddr_in *ra)
926 const struct sockaddr_in *l4;
929 l4 = (
const struct sockaddr_in *) &lal->
addr;
940 if (!
ch->natted_address)
943 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
946 const struct sockaddr_in *c4;
948 if (AF_INET != ca->
ss.ss_family)
950 c4 = (
const struct sockaddr_in *) &ca->
ss;
951 if ((0 != c4->sin_addr.s_addr) &&
952 (l4->sin_addr.s_addr != c4->sin_addr.s_addr))
962 sizeof(
struct sockaddr_in),
966 sizeof(
struct sockaddr_in));
1005 if ((pos->af == lal->af) &&
1006 (0 == memcmp (&lal->addr,
1008 (AF_INET == lal->af)
1009 ?
sizeof(
struct sockaddr_in)
1010 :
sizeof(
struct sockaddr_in6))))
1036 if ((pos->af == lal->af) &&
1037 (0 == memcmp (&lal->addr,
1039 (AF_INET == lal->af)
1040 ?
sizeof(
struct sockaddr_in)
1041 :
sizeof(
struct sockaddr_in6))))
1058 if ((AF_INET == pos->af) &&
1059 (NULL == pos->hc) &&
1062 const struct sockaddr_in *s4
1063 = (
const struct sockaddr_in *) &pos->addr;
1066 "Found NATed local address %s, starting NAT server\n",
1067 GNUNET_a2s ((
const struct sockaddr *) &pos->addr,
1094 const struct sockaddr *addr,
1111 "Running upnpc failed: %d\n",
1117 "external-ip binary not found\n");
1122 "upnpc binary not found\n");
1127 "external-ip binary could not be run\n");
1132 "upnpc failed to create port mapping\n");
1137 "Invalid output from upnpc\n");
1142 "Invalid address returned by upnpc\n");
1149 switch (addr->sa_family)
1152 ac =
is_nat_v4 (&((
const struct sockaddr_in *) addr)->sin_addr)
1158 ac =
is_nat_v6 (&((
const struct sockaddr_in6 *) addr)->sin6_addr)
1168 "upnp external address %s: %s\n",
1169 add_remove ?
"added" :
"removed",
1203 const struct sockaddr *addr,
1208 struct sockaddr_storage ss;
1209 struct sockaddr_in *v4;
1210 struct sockaddr_in6 *v6;
1222 for (lal =
ch->ext_addr_head; NULL != lal; lal = laln)
1239 "Got IP `%s' for external address `%s'\n",
1251 switch (
addr->sa_family)
1254 v4 = (
struct sockaddr_in *) &ss;
1255 v4->sin_port = htons (
ch->ext_dns_port);
1259 v6 = (
struct sockaddr_in6 *) &ss;
1260 v6->sin6_port = htons (
ch->ext_dns_port);
1268 for (lal =
ch->ext_addr_head; NULL != lal; lal = lal->
next)
1272 if ((addr->sa_family == lal->
addr.ss_family) &&
1285 lal->
af = ss.ss_family;
1311 "Performing DNS lookup for punched hole given for `%s' as `%s:%u'\n",
1314 (
unsigned int)
ch->ext_dns_port);
1315 for (lal =
ch->ext_addr_head; NULL != lal; lal = lal->
next)
1317 ch->ext_dns_task = NULL;
1342 struct sockaddr_in *s4;
1345 port = strrchr (
ch->hole_external,
':');
1349 _ (
"Malformed punched hole specification `%s' (lacks port)\n"),
1353 if ((1 != sscanf (
port + 1,
1360 "Invalid port number in punched hole specification `%s' (lacks port)\n"),
1364 ch->ext_dns_port = (uint16_t) pnum;
1368 if (
'[' == *
ch->hole_external)
1370 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &lal->
addr;
1372 s6->sin6_family = AF_INET6;
1373 if (
']' != (
ch->hole_external[strlen (
ch->hole_external) - 1]))
1376 _ (
"Malformed punched hole specification `%s' (lacks `]')\n"),
1381 ch->hole_external[strlen (
ch->hole_external) - 1] =
'\0';
1382 if (1 != inet_pton (AF_INET6,
1383 ch->hole_external + 1,
1388 "Malformed punched hole specification `%s' (IPv6 address invalid)"),
1389 ch->hole_external + 1);
1393 s6->sin6_port = htons (
ch->ext_dns_port);
1405 s4 = (
struct sockaddr_in *) &lal->
addr;
1406 s4->sin_family = AF_INET;
1407 if (1 == inet_pton (AF_INET,
1412 "IPv4 punched hole given for `%s' via `%s:%u'\n",
1415 (
unsigned int)
ch->ext_dns_port);
1416 s4->sin_port = htons (
ch->ext_dns_port);
1427 if (0 == strcasecmp (
ch->hole_external,
1457 if ((0 !=
ch->proto) ||
1458 (NULL !=
ch->caddrs))
1470 left = ntohs (message->
header.
size) -
sizeof(*message);
1471 off = (
const char *) &message[1];
1472 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
1474 const struct sockaddr *sa = (
const struct sockaddr *) off;
1479 if (
sizeof(sa_family_t) > left)
1486 switch (sa->sa_family)
1490 struct sockaddr_in s4;
1494 sizeof(
struct sockaddr_in));
1495 alen =
sizeof(
struct sockaddr_in);
1498 port = ntohs (s4.sin_port);
1504 struct sockaddr_in6 s6;
1508 sizeof(
struct sockaddr_in6));
1509 alen =
sizeof(
struct sockaddr_in6);
1512 port = ntohs (s6.sin6_port);
1518 alen =
sizeof(
struct sockaddr_un);
1537 ((IPPROTO_TCP ==
ch->proto) ||
1538 (IPPROTO_UDP ==
ch->proto)))
1543 IPPROTO_TCP ==
ch->proto,
1555 "Received REGISTER message from client for subsystem `%s'\n",
1561 &
ch->hole_external))
1574 ch->external_monitor
1594 size_t expect = sa_len + ntohs (message->
payload_size);
1596 if (ntohs (message->
header.
size) -
sizeof(*message) != expect)
1601 if (sa_len <
sizeof(sa_family_t))
1625 struct sockaddr_in v4;
1629 if (!
ch->natted_address)
1632 v4.sin_port = htons (0);
1636 msg->add_remove = htonl ((int32_t)
add);
1682 const char *buf = (
const char *) &message[1];
1683 const struct sockaddr *sa;
1686 size_t payload_size;
1687 struct sockaddr_in external_addr;
1691 sa = (
const struct sockaddr *) &buf[0];
1692 payload = (
const struct sockaddr *) &buf[sa_len];
1693 switch (sa->sa_family)
1696 if (sa_len !=
sizeof(
struct sockaddr_in))
1705 if (sa_len !=
sizeof(
struct sockaddr_in6))
1714 "Received HANDLE_STUN message from client\n");
1800 if (ntohs (message->
header.
size) -
sizeof(*message) != expect)
1822 const char *buf = (
const char *) &message[1];
1825 struct sockaddr_in l4;
1826 struct sockaddr_in r4;
1830 "Received REQUEST CONNECTION REVERSAL message from client\n");
1831 if (local_sa_len !=
sizeof(
struct sockaddr_in))
1837 if (remote_sa_len !=
sizeof(
struct sockaddr_in))
1845 sizeof(
struct sockaddr_in));
1847 buf +=
sizeof(
struct sockaddr_in);
1850 sizeof(
struct sockaddr_in));
1853 ntohs (l4.sin_port),
1858 _ (
"Connection reversal request failed\n"));
1878 size_t left = ntohs (message->
header.
size) -
sizeof(*message);
1907 const char *buf = (
const char *) &message[1];
1909 struct sockaddr_in sockaddr_ipv4 = {
1910 .sin_family = AF_INET
1914 if (1 != inet_pton (AF_INET,
1916 &sockaddr_ipv4.sin_addr))
1919 "natting address %s length %u no ipv4\n",
1942 while (NULL != (se =
se_head))
2001 "UPnP enabled in configuration, but UPnP client `upnpc` command not found, disabling UPnP\n"));
2070 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
2072 if (NULL !=
ch->caddrs[i].mh)
2075 ch->caddrs[i].mh = NULL;
2079 while (NULL != (lal =
ch->ext_addr_head))
2086 if (NULL !=
ch->ext_dns_task)
2089 ch->ext_dns_task = NULL;
2091 if (NULL !=
ch->external_monitor)
2094 ch->external_monitor = NULL;
2096 if (NULL !=
ch->ext_dns)
2137#if defined(__linux__) && defined(__GLIBC__)
2141GNUNET_NATM_memory_init (
void);
2147GNUNET_NATM_memory_init (
void)
2149 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
2150 mallopt (M_TOP_PAD, 1 * 1024);
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static int ret
Final status code.
static uint16_t port
Port number.
static struct GNUNET_CADET_Channel * ch
Channel handle.
static char * name
Name (label) of the records to list.
static int add
Desired action is to add a record.
static int result
Global testing status.
static struct GNUNET_SERVICE_Handle * service
Handle to our service instance.
static unsigned long long payload
How much data are we currently storing in the database?
static void handle_stun(void *cls, const struct GNUNET_NAT_HandleStunMessage *message)
Handler for GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN message from client.
static int check_stun(void *cls, const struct GNUNET_NAT_HandleStunMessage *message)
Check validity of GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN message from client.
static struct ClientHandle * ch_head
Head of client DLL.
static struct StunExternalIP * se_head
Kept in a DLL.
static struct GNUNET_TIME_Relative dyndns_frequency
How often do we scan for changes in how our external (dyndns) hostname resolves?
GNUNET_SERVICE_MAIN(GNUNET_OS_project_data_gnunet(), "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 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.
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.
int enable_ipscan
Is IP Scanning enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, without, only explicitly specif...
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.
static struct GNUNET_STATISTICS_Handle * stats
Handle to the statistics service.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Handle to our current configuration.
static void destroy_lal()
Free the DLL starting at lal_head.
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.
static int check_register(void *cls, const struct GNUNET_NAT_RegisterMessage *message)
Check validity of GNUNET_MESSAGE_TYPE_NAT_REGISTER message from client.
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.
static int match_ipv6(const char *network, const struct in6_addr *ip, uint8_t bits)
Check if ip is in network with bits netmask.
static void process_external_ip(void *cls, const struct sockaddr *addr, socklen_t addrlen)
Our (external) hostname was resolved.
static struct ClientHandle * ch_tail
Tail of client DLL.
static void notify_clients(struct LocalAddressList *delta, int add)
Notify all clients about a change in the list of addresses this peer has.
static void shutdown_task(void *cls)
Task run during shutdown.
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,...
static struct LocalAddressList * lal_head
Head of DLL of local addresses.
static void run_scan(void *cls)
Task we run periodically to scan for network interfaces.
static int match_ipv4(const char *network, const struct in_addr *ip, uint8_t bits)
Check if ip is in network with bits netmask.
static struct GNUNET_SCHEDULER_Task * scan_task
Task scheduled to periodically scan our network interfaces.
#define DYNDNS_FREQUENCY
How often do we scan for changes in how our external (dyndns) hostname resolves?
static void reversal_callback(void *cls, const struct sockaddr_in *ra)
We got a connection reversal request from another peer.
#define SCAN_FREQ
How often should we ask the OS about a list of active network interfaces?
static struct StunExternalIP * se_tail
Kept in a DLL.
static void handle_register(void *cls, const struct GNUNET_NAT_RegisterMessage *message)
Handler for GNUNET_MESSAGE_TYPE_NAT_REGISTER message from client.
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 g...
static void run(void *cls, const struct GNUNET_CONFIGURATION_Handle *c, struct GNUNET_SERVICE_Handle *service)
Setup NAT service.
static void lookup_hole_external(struct ClientHandle *ch)
Resolve the hole_external name to figure out our external address from a manually punched hole.
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.
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.
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.
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.
static void dyndns_lookup(void *cls)
Resolve the hole_external name to figure out our external address from a manually punched hole.
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.
static void client_disconnect_cb(void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls)
Callback called when a client disconnected from the service.
static int is_nat_v6(const struct in6_addr *ip)
Test if the given IPv6 address is in a known range for private networks.
static struct LocalAddressList * lal_tail
Tail of DLL of local addresses.
static void free_lal(struct LocalAddressList *lal)
Remove and free an entry from the lal_head DLL.
static int is_nat_v4(const struct in_addr *ip)
Test if the given IPv4 address is in a known range for private networks.
int enable_upnp
Is UPnP enabled? GNUNET_YES if enabled, GNUNET_NO if disabled, GNUNET_SYSERR if configuration enabled...
static struct GNUNET_TIME_Relative stun_stale_timeout
Timeout to use when STUN data is considered stale.
network address translation traversal service
void GN_external_ipv4_monitor_stop(struct GN_ExternalIPMonitor *mon)
Stop calling monitor.
void GN_nat_status_changed(int have_nat)
We have changed our opinion about being NATed in the first place.
struct GN_ExternalIPMonitor * GN_external_ipv4_monitor_start(GN_NotifyExternalIPv4Change cb, void *cb_cls)
Start monitoring external IPv4 addresses.
Code to figure out what our external IPv4 address(es) might be (external IPv4s are what is seen on th...
int GN_request_connection_reversal(const struct in_addr *internal_address, uint16_t internal_port, const struct in_addr *remote_v4, const struct GNUNET_CONFIGURATION_Handle *cfg)
We want to connect to a peer that is behind NAT.
struct HelperContext * GN_start_gnunet_nat_server_(const struct in_addr *internal_address, GN_ReversalCallback cb, void *cb_cls, const struct GNUNET_CONFIGURATION_Handle *cfg)
Start the gnunet-helper-nat-server and process incoming requests.
void GN_stop_gnunet_nat_server_(struct HelperContext *h)
Start the gnunet-helper-nat-server and process incoming requests.
runs the gnunet-helper-nat-server
struct GNUNET_NAT_MiniHandle * GNUNET_NAT_mini_map_start(uint16_t port, int is_tcp, GNUNET_NAT_MiniAddressCallback ac, void *ac_cls)
Start mapping the given port using (mini)upnpc.
void GNUNET_NAT_mini_map_stop(struct GNUNET_NAT_MiniHandle *mini)
Remove a mapping created with (mini)upnpc.
int GNUNET_NAT_stun_handle_packet_(const void *data, size_t len, struct sockaddr_in *arg)
Handle an incoming STUN response.
This code provides some support for doing STUN transactions.
struct GNUNET_PQ_ResultSpec __attribute__
Constants for network protocols.
Functions related to doing DNS lookups.
API to create, modify and access statistics.
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_time(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, struct GNUNET_TIME_Relative *time)
Get a configuration value that should be a relative time.
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.
#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_memcmp(a, b)
Compare memory in a and b, where both must be of the same pointer type.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
GNUNET_GenericReturnValue
Named constants for return values.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#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.
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_WARNING
@ GNUNET_ERROR_TYPE_ERROR
@ GNUNET_ERROR_TYPE_MESSAGE
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_strndup(a, length)
Wrapper around GNUNET_xstrndup_.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_new_array(n, type)
Allocate a size n array with structs or unions of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
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_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.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
GNUNET_NAT_StatusCode
Error Types for the NAT subsystem (which can then later be converted/resolved to a string)
GNUNET_NAT_AddressClass
Some addresses contain sensitive information or are not suitable for global distribution.
@ GNUNET_NAT_ERROR_UPNPC_NOT_FOUND
upnpc command not found
@ 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_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_IPC_FAILURE
IPC Failure.
@ GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID
"no valid address was returned by `external-ip'"
@ GNUNET_NAT_AC_LAN
Addresses useful in the local wired network, 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_MANUAL
Addresses that were manually configured by the user.
@ GNUNET_NAT_AC_LOOPBACK
Loopback addresses, only useful under special circumstances.
const struct GNUNET_OS_ProjectData * GNUNET_OS_project_data_gnunet(void)
Return default project data used by 'libgnunetutil' for GNUnet.
void GNUNET_OS_network_interfaces_list(GNUNET_OS_NetworkInterfaceProcessor proc, void *proc_cls)
Enumerate all network interfaces.
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_ADD_GLOBAL_ADDRESS
Message to ask NAT service to notify all clients about a new global address.
#define GNUNET_MESSAGE_TYPE_NAT_ADDRESS_CHANGE
Message to from NAT service notifying us that one of our addresses changed.
#define GNUNET_MESSAGE_TYPE_NAT_CONNECTION_REVERSAL_REQUESTED
Message to from NAT service notifying us that connection reversal was requested by another peer.
#define GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL
Message to ask NAT service to request connection reversal.
#define GNUNET_MESSAGE_TYPE_NAT_REGISTER
Message to ask NAT service to register a client.
#define GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN
Message to ask NAT service to handle a STUN packet.
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.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received,...
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.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
void GNUNET_SERVICE_client_drop(struct GNUNET_SERVICE_Client *c)
Ask the server to disconnect from the given client.
void GNUNET_SERVICE_client_continue(struct GNUNET_SERVICE_Client *c)
Continue receiving further messages from the given client.
@ GNUNET_SERVICE_OPTION_NONE
Use defaults.
struct GNUNET_STATISTICS_Handle * GNUNET_STATISTICS_create(const char *subsystem, const struct GNUNET_CONFIGURATION_Handle *cfg)
Get handle for the statistics service.
void GNUNET_STATISTICS_destroy(struct GNUNET_STATISTICS_Handle *h, int sync_first)
Destroy a handle (free all state associated with it).
#define GNUNET_TIME_UNIT_HOURS
One hour.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
GNUNET_NAT_RegisterFlags
Flags specifying the events this client would be interested in being told about.
@ GNUNET_NAT_RF_ADDRESSES
This client wants to be informed about changes to our applicable addresses.
static struct GNUNET_TIME_Relative delta
Information we track per client address.
struct GNUNET_NAT_MiniHandle * mh
Handle to active UPnP request where we asked upnpc to open a port at the NAT.
struct sockaddr_storage ss
Network address used by the client.
Struct containing information about a client, handle to connect to it, and any pending messages that ...
uint16_t num_caddrs
Number of addresses that this service is bound to.
enum GNUNET_NAT_RegisterFlags flags
What does this client care about?
struct LocalAddressList * ext_addr_tail
DLL of external IP addresses as given in hole_external.
uint8_t proto
Client's IPPROTO, e.g.
char * section_name
Name of the configuration section this client cares about.
struct ClientHandle * prev
Kept in a DLL.
struct ClientHandle * next
Kept in a DLL.
char * hole_external
External DNS name and port given by user due to manual hole punching.
int natted_address
Is any of the caddrs in a reserved subnet for NAT?
struct GNUNET_SERVICE_Client * client
The handle to this client.
struct ClientAddress * caddrs
Array of addresses used by the service.
uint16_t ext_dns_port
Port number we found in hole_external.
struct GNUNET_MQ_Handle * mq
The message queue to this client.
struct GNUNET_RESOLVER_RequestHandle * ext_dns
Handle for (DYN)DNS lookup of our external IP as given in hole_external.
struct LocalAddressList * ext_addr_head
DLL of external IP addresses as given in hole_external.
struct GN_ExternalIPMonitor * external_monitor
Handle for monitoring external IP changes.
struct GNUNET_SCHEDULER_Task * ext_dns_task
Task for periodically re-running the ext_dns DNS lookup.
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Handle to a message queue.
Message sent by client to add a global address.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_ADD_GLOBAL_ADDRESS.
unsigned int address_length
Length of the address following the struct, in NBO.
Service notifying the client about changes in the set of addresses it has.
Service telling a client that connection reversal was requested.
Client telling the service to (possibly) handle a STUN message.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_HANDLE_STUN.
uint16_t payload_size
Number of bytes of payload included, in NBO.
uint16_t sender_addr_size
Size of the sender address included, in NBO.
Handle to a mapping created with upnpc.
Message sent by a client to register with its addresses.
uint16_t num_addrs
Number of addresses that this service is bound to that follow.
uint16_t str_len
Number of bytes in the string that follow which specifies a section name in the configuration.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_REGISTER.
uint8_t flags
An enum GNUNET_NAT_RegisterFlags.
uint8_t proto
Client's IPPROTO, e.g.
Client asking the service to initiate connection reversal.
struct GNUNET_MessageHeader header
Header with type GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL.
uint16_t local_addr_size
Size of the local address included, in NBO.
uint16_t remote_addr_size
Size of the remote address included, in NBO.
Handle to a request given to the resolver.
Entry in list of pending tasks.
Handle to a client that is connected to a service.
Time for relative time used by GNUnet, in microseconds.
Handle to monitor for external IP changes.
Information we keep per NAT helper process.
struct LocalAddressList * lal_head
Head of DLL of local addresses.
struct LocalAddressList * lal_tail
Tail of DLL of local addresses.
List of local addresses this system has.
struct LocalAddressList * prev
Previous entry.
int old
GNUNET_YES if we saw this one in the previous iteration, but not in the current iteration and thus mi...
struct HelperContext * hc
Context for a gnunet-helper-nat-server used to listen for ICMP messages to this client for connection...
struct LocalAddressList * next
This is a linked list.
enum GNUNET_NAT_AddressClass ac
What type of address is this?
struct sockaddr_storage addr
The address itself (i.e.
External IP address as given to us via some STUN server.
struct GNUNET_SCHEDULER_Task * timeout_task
Task we run to remove this entry when it is stale.
size_t stun_server_addr_len
Number of bytes used in stun_server_addr.
struct sockaddr_in external_addr
Our external IP address as reported by the STUN server.
struct sockaddr_storage stun_server_addr
Address of the reporting STUN server.
struct StunExternalIP * next
Kept in a DLL.
struct StunExternalIP * prev
Kept in a DLL.