41 #include "gnunet_signatures.h"
58 #define SCAN_FREQ GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15)
63 #define AUTOCONFIG_TIMEOUT GNUNET_TIME_relative_multiply ( \
64 GNUNET_TIME_UNIT_SECONDS, 5)
69 #define DYNDNS_FREQUENCY GNUNET_TIME_relative_multiply ( \
70 GNUNET_TIME_UNIT_MINUTES, 7)
81 struct sockaddr_storage
ss;
117 struct sockaddr_storage
addr;
358 "Lost NATed local address %s, stopping NAT server\n",
360 sizeof(
struct sockaddr_in)));
394 uint16_t num_addrs = ntohs (message->
num_addrs);
395 const char *off = (
const char *) &message[1];
396 size_t left = ntohs (message->
header.
size) -
sizeof(*message);
398 for (
unsigned int i = 0; i < num_addrs; i++)
401 const struct sockaddr *sa = (
const struct sockaddr *) off;
403 if (
sizeof(sa_family_t) > left)
408 switch (sa->sa_family)
411 alen =
sizeof(
struct sockaddr_in);
415 alen =
sizeof(
struct sockaddr_in6);
420 alen =
sizeof(
struct sockaddr_un);
435 if (left != ntohs (message->
str_len))
454 const struct in_addr *ip,
466 return ! ((ip->s_addr ^ net.s_addr) & htonl (0xFFFFFFFFu << (32 - bits)));
480 const struct in6_addr *ip,
484 struct in6_addr mask;
492 memset (&mask, 0,
sizeof(mask));
499 mask.s6_addr[off++] = 0xFF;
504 mask.s6_addr[off] = (mask.s6_addr[off] >> 1) + 0x80;
507 for (
unsigned j = 0; j <
sizeof(
struct in6_addr) / sizeof(uint32_t); j++)
508 if (((((uint32_t *) ip)[j] & ((uint32_t *) &mask)[j])) !=
509 (((uint32_t *) &net)[j] & ((
int *) &mask)[j]))
585 const struct sockaddr *
addr,
586 const struct sockaddr *broadcast_addr,
587 const struct sockaddr *netmask,
593 const struct in_addr *ip4;
594 const struct in6_addr *ip6;
597 switch (addr->sa_family)
600 alen =
sizeof(
struct sockaddr_in);
601 ip4 = &((
const struct sockaddr_in *) addr)->sin_addr;
611 alen =
sizeof(
struct sockaddr_in6);
612 ip6 = &((
const struct sockaddr_in6 *) addr)->sin6_addr;
619 if ((ip6->s6_addr[11] == 0xFF) &&
620 (ip6->s6_addr[12] == 0xFE))
637 lal->
af = addr->sa_family;
670 "Notifying client about %s of IP %s\n",
671 add ?
"addition" :
"removal",
677 msg->add_remove = htonl (
add);
678 msg->addr_class = htonl (
ac);
701 struct sockaddr_in v4;
702 struct sockaddr_in6 v6;
707 "Not notifying client as it does not care about addresses\n");
713 alen =
sizeof(
struct sockaddr_in);
719 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
721 const struct sockaddr_in *c4;
723 if (AF_INET !=
ch->caddrs[i].ss.ss_family)
725 c4 = (
const struct sockaddr_in *) &
ch->caddrs[i].ss;
726 if (
match_ipv4 (
"127.0.0.1", &c4->sin_addr, 8) &&
727 (0 != c4->sin_addr.s_addr) &&
728 (!
match_ipv4 (
"127.0.0.1", &v4.sin_addr, 8)))
730 if ((!
match_ipv4 (
"127.0.0.1", &c4->sin_addr, 8)) &&
734 (0 != c4->sin_addr.s_addr) &&
740 (0 != c4->sin_addr.s_addr) &&
746 if (0 == htons (v4.sin_port))
747 v4.sin_port = c4->sin_port;
757 alen =
sizeof(
struct sockaddr_in6);
761 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
763 const struct sockaddr_in6 *c6;
765 if (AF_INET6 !=
ch->caddrs[i].ss.ss_family)
767 c6 = (
const struct sockaddr_in6 *) &
ch->caddrs[i].ss;
768 if (
match_ipv6 (
"::1", &c6->sin6_addr, 128) &&
773 if ((!
match_ipv6 (
"::1", &c6->sin6_addr, 128)) &&
789 if ((
match_ipv6 (
"fe80::", &c6->sin6_addr, 10)) &&
799 if (0 == htons (v6.sin6_port))
800 v6.sin6_port = c6->sin6_port;
846 const struct in_addr *v4,
850 struct sockaddr_in sa;
854 if ((NULL !=
ch->hole_external) &&
855 (0 == strcasecmp (
ch->hole_external,
859 struct sockaddr_in *s4;
862 "Detected eternal IP, can now back-fill AUTO:%u in hole punching specification of `%s'\n",
863 (
unsigned int)
ch->ext_dns_port,
865 memset (&lal, 0,
sizeof(lal));
866 s4 = (
struct sockaddr_in *) &lal.
addr;
867 s4->sin_family = AF_INET;
868 s4->sin_port = htons (
ch->ext_dns_port);
878 if (!
ch->natted_address)
881 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
883 const struct sockaddr_storage *ss = &
ch->caddrs[i].ss;
885 if (AF_INET != ss->ss_family)
897 sa.sin_family = AF_INET;
899 sa.sin_port = htons (0);
902 "Detected eternal IP %s, notifying client of external IP (without port)\n",
925 const struct sockaddr_in *ra)
928 const struct sockaddr_in *l4;
931 l4 = (
const struct sockaddr_in *) &lal->
addr;
942 if (!
ch->natted_address)
945 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
948 const struct sockaddr_in *c4;
950 if (AF_INET != ca->
ss.ss_family)
952 c4 = (
const struct sockaddr_in *) &ca->
ss;
953 if ((0 != c4->sin_addr.s_addr) &&
954 (l4->sin_addr.s_addr != c4->sin_addr.s_addr))
964 sizeof(
struct sockaddr_in),
968 sizeof(
struct sockaddr_in));
1007 if ((pos->af == lal->af) &&
1008 (0 == memcmp (&lal->addr,
1010 (AF_INET == lal->af)
1011 ?
sizeof(
struct sockaddr_in)
1012 :
sizeof(
struct sockaddr_in6))))
1038 if ((pos->af == lal->af) &&
1039 (0 == memcmp (&lal->addr,
1041 (AF_INET == lal->af)
1042 ?
sizeof(
struct sockaddr_in)
1043 :
sizeof(
struct sockaddr_in6))))
1060 if ((AF_INET == pos->af) &&
1061 (NULL == pos->hc) &&
1064 const struct sockaddr_in *s4
1065 = (
const struct sockaddr_in *) &pos->addr;
1068 "Found NATed local address %s, starting NAT server\n",
1069 GNUNET_a2s ((
const struct sockaddr *) &pos->addr,
1096 const struct sockaddr *addr,
1113 "Running upnpc failed: %d\n",
1119 "external-ip binary not found\n");
1124 "upnpc binary not found\n");
1129 "external-ip binary could not be run\n");
1134 "upnpc failed to create port mapping\n");
1139 "Invalid output from upnpc\n");
1144 "Invalid address returned by upnpc\n");
1151 switch (addr->sa_family)
1154 ac =
is_nat_v4 (&((
const struct sockaddr_in *) addr)->sin_addr)
1160 ac =
is_nat_v6 (&((
const struct sockaddr_in6 *) addr)->sin6_addr)
1170 "upnp external address %s: %s\n",
1171 add_remove ?
"added" :
"removed",
1205 const struct sockaddr *addr,
1210 struct sockaddr_storage ss;
1211 struct sockaddr_in *v4;
1212 struct sockaddr_in6 *v6;
1224 for (lal =
ch->ext_addr_head; NULL != lal; lal = laln)
1241 "Got IP `%s' for external address `%s'\n",
1253 switch (
addr->sa_family)
1256 v4 = (
struct sockaddr_in *) &ss;
1257 v4->sin_port = htons (
ch->ext_dns_port);
1261 v6 = (
struct sockaddr_in6 *) &ss;
1262 v6->sin6_port = htons (
ch->ext_dns_port);
1270 for (lal =
ch->ext_addr_head; NULL != lal; lal = lal->
next)
1274 if ((addr->sa_family == lal->
addr.ss_family) &&
1287 lal->
af = ss.ss_family;
1313 "Performing DNS lookup for punched hole given for `%s' as `%s:%u'\n",
1316 (
unsigned int)
ch->ext_dns_port);
1317 for (lal =
ch->ext_addr_head; NULL != lal; lal = lal->
next)
1319 ch->ext_dns_task = NULL;
1344 struct sockaddr_in *s4;
1347 port = strrchr (
ch->hole_external,
':');
1351 _ (
"Malformed punched hole specification `%s' (lacks port)\n"),
1355 if ((1 != sscanf (
port + 1,
1362 "Invalid port number in punched hole specification `%s' (lacks port)\n"),
1366 ch->ext_dns_port = (uint16_t) pnum;
1370 if (
'[' == *
ch->hole_external)
1372 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &lal->
addr;
1374 s6->sin6_family = AF_INET6;
1375 if (
']' != (
ch->hole_external[strlen (
ch->hole_external) - 1]))
1378 _ (
"Malformed punched hole specification `%s' (lacks `]')\n"),
1383 ch->hole_external[strlen (
ch->hole_external) - 1] =
'\0';
1384 if (1 != inet_pton (AF_INET6,
1385 ch->hole_external + 1,
1390 "Malformed punched hole specification `%s' (IPv6 address invalid)"),
1391 ch->hole_external + 1);
1395 s6->sin6_port = htons (
ch->ext_dns_port);
1407 s4 = (
struct sockaddr_in *) &lal->
addr;
1408 s4->sin_family = AF_INET;
1409 if (1 == inet_pton (AF_INET,
1414 "IPv4 punched hole given for `%s' via `%s:%u'\n",
1417 (
unsigned int)
ch->ext_dns_port);
1418 s4->sin_port = htons (
ch->ext_dns_port);
1429 if (0 == strcasecmp (
ch->hole_external,
1459 if ((0 !=
ch->proto) ||
1460 (NULL !=
ch->caddrs))
1472 left = ntohs (message->
header.
size) -
sizeof(*message);
1473 off = (
const char *) &message[1];
1474 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
1476 const struct sockaddr *sa = (
const struct sockaddr *) off;
1481 if (
sizeof(sa_family_t) > left)
1488 switch (sa->sa_family)
1492 struct sockaddr_in s4;
1496 sizeof(
struct sockaddr_in));
1497 alen =
sizeof(
struct sockaddr_in);
1500 port = ntohs (s4.sin_port);
1506 struct sockaddr_in6 s6;
1510 sizeof(
struct sockaddr_in6));
1511 alen =
sizeof(
struct sockaddr_in6);
1514 port = ntohs (s6.sin6_port);
1520 alen =
sizeof(
struct sockaddr_un);
1539 ((IPPROTO_TCP ==
ch->proto) ||
1540 (IPPROTO_UDP ==
ch->proto)))
1545 IPPROTO_TCP ==
ch->proto,
1557 "Received REGISTER message from client for subsystem `%s'\n",
1563 &
ch->hole_external))
1576 ch->external_monitor
1596 size_t expect = sa_len + ntohs (message->
payload_size);
1598 if (ntohs (message->
header.
size) -
sizeof(*message) != expect)
1603 if (sa_len <
sizeof(sa_family_t))
1627 struct sockaddr_in v4;
1631 if (!
ch->natted_address)
1634 v4.sin_port = htons (0);
1638 msg->add_remove = htonl ((int32_t)
add);
1684 const char *
buf = (
const char *) &message[1];
1685 const struct sockaddr *sa;
1688 size_t payload_size;
1689 struct sockaddr_in external_addr;
1693 sa = (
const struct sockaddr *) &
buf[0];
1694 payload = (
const struct sockaddr *) &
buf[sa_len];
1695 switch (sa->sa_family)
1698 if (sa_len !=
sizeof(
struct sockaddr_in))
1707 if (sa_len !=
sizeof(
struct sockaddr_in6))
1716 "Received HANDLE_STUN message from client\n");
1802 if (ntohs (message->
header.
size) -
sizeof(*message) != expect)
1825 const char *
buf = (
const char *) &message[1];
1828 struct sockaddr_in l4;
1829 struct sockaddr_in r4;
1833 "Received REQUEST CONNECTION REVERSAL message from client\n");
1834 if (local_sa_len !=
sizeof(
struct sockaddr_in))
1840 if (remote_sa_len !=
sizeof(
struct sockaddr_in))
1848 sizeof(
struct sockaddr_in));
1850 buf +=
sizeof(
struct sockaddr_in);
1853 sizeof(
struct sockaddr_in));
1856 ntohs (l4.sin_port),
1861 _ (
"Connection reversal request failed\n"));
1876 while (NULL != (se =
se_head))
1935 "UPnP enabled in configuration, but UPnP client `upnpc` command not found, disabling UPnP\n"));
2004 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
2006 if (NULL !=
ch->caddrs[i].mh)
2009 ch->caddrs[i].mh = NULL;
2013 while (NULL != (lal =
ch->ext_addr_head))
2020 if (NULL !=
ch->ext_dns_task)
2023 ch->ext_dns_task = NULL;
2025 if (NULL !=
ch->external_monitor)
2028 ch->external_monitor = NULL;
2030 if (NULL !=
ch->ext_dns)
2066 #if defined(__linux__) && defined(__GLIBC__)
2073 GNUNET_ARM_memory_init ()
2075 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
2076 mallopt (M_TOP_PAD, 1 * 1024);
struct GNUNET_MQ_Handle * mq
struct GNUNET_MessageHeader * msg
struct GNUNET_MQ_Envelope * env
static int ret
Return value of the commandline.
static uint16_t port
Port number.
static struct GNUNET_CADET_Channel * ch
Channel handle.
static int add
Desired action is to add a record.
static struct GNUNET_MQ_Envelope * ac
Handle to current GNUNET_PEERINFO_add_peer() operation.
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?
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.
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.
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_handler_end())
Define "main" method using service macro.
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 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 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 dyndns_lookup(void *cls)
Resolve the hole_external name to figure out our external address from a manually punched hole.
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.
void GN_stop_gnunet_nat_server_(struct HelperContext *h)
Start the gnunet-helper-nat-server and process incoming requests.
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.
runs the gnunet-helper-nat-server
void GNUNET_NAT_mini_map_stop(struct GNUNET_NAT_MiniHandle *mini)
Remove a mapping created with (mini)upnpc.
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.
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.
#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.
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_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.
void GNUNET_RESOLVER_request_cancel(struct GNUNET_RESOLVER_RequestHandle *rh)
Cancel a request that is still pending with the resolver.
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.
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_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_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.
Messages for interaction with gnunet-nat-server and gnunet-nat-service.
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.
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.