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;
365 "Lost NATed local address %s, stopping NAT server\n",
367 sizeof(
struct sockaddr_in)));
401 uint16_t num_addrs = ntohs (message->
num_addrs);
402 const char *off = (
const char *) &message[1];
403 size_t left = ntohs (message->
header.
size) -
sizeof(*message);
405 for (
unsigned int i = 0; i < num_addrs; i++)
408 const struct sockaddr *sa = (
const struct sockaddr *) off;
410 if (
sizeof(sa_family_t) > left)
415 switch (sa->sa_family)
418 alen =
sizeof(
struct sockaddr_in);
422 alen =
sizeof(
struct sockaddr_in6);
427 alen =
sizeof(
struct sockaddr_un);
442 if (left != ntohs (message->
str_len))
461 const struct in_addr *ip,
473 return ! ((ip->s_addr ^ net.s_addr) & htonl (0xFFFFFFFFu << (32 - bits)));
487 const struct in6_addr *ip,
491 struct in6_addr mask;
499 memset (&mask, 0,
sizeof(mask));
506 mask.s6_addr[off++] = 0xFF;
511 mask.s6_addr[off] = (mask.s6_addr[off] >> 1) + 0x80;
514 for (
unsigned j = 0; j <
sizeof(
struct in6_addr) / sizeof(uint32_t); j++)
515 if (((((uint32_t *) ip)[j] & ((uint32_t *) &mask)[j])) !=
516 (((uint32_t *) &net)[j] & ((
int *) &mask)[j]))
592 const struct sockaddr *
addr,
593 const struct sockaddr *broadcast_addr,
594 const struct sockaddr *netmask,
600 const struct in_addr *ip4;
601 const struct in6_addr *ip6;
604 switch (addr->sa_family)
607 alen =
sizeof(
struct sockaddr_in);
608 ip4 = &((
const struct sockaddr_in *) addr)->sin_addr;
618 alen =
sizeof(
struct sockaddr_in6);
619 ip6 = &((
const struct sockaddr_in6 *) addr)->sin6_addr;
626 if ((ip6->s6_addr[11] == 0xFF) &&
627 (ip6->s6_addr[12] == 0xFE))
644 lal->
af = addr->sa_family;
677 "Notifying client about %s of IP %s\n",
678 add ?
"addition" :
"removal",
684 msg->add_remove = htonl (
add);
685 msg->addr_class = htonl (ac);
708 struct sockaddr_in v4;
709 struct sockaddr_in6 v6;
714 "Not notifying client as it does not care about addresses\n");
720 alen =
sizeof(
struct sockaddr_in);
726 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
728 const struct sockaddr_in *c4;
730 if (AF_INET !=
ch->caddrs[i].ss.ss_family)
732 c4 = (
const struct sockaddr_in *) &
ch->caddrs[i].ss;
734 (0 == c4->sin_addr.s_addr) &&
738 if (
match_ipv4 (
"127.0.0.1", &c4->sin_addr, 8) &&
739 (0 != c4->sin_addr.s_addr) &&
740 (!
match_ipv4 (
"127.0.0.1", &v4.sin_addr, 8)))
742 if ((!
match_ipv4 (
"127.0.0.1", &c4->sin_addr, 8)) &&
746 (0 != c4->sin_addr.s_addr) &&
752 (0 != c4->sin_addr.s_addr) &&
758 if (0 == htons (v4.sin_port))
759 v4.sin_port = c4->sin_port;
769 alen =
sizeof(
struct sockaddr_in6);
773 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
775 const struct sockaddr_in6 *c6;
777 if (AF_INET6 !=
ch->caddrs[i].ss.ss_family)
779 c6 = (
const struct sockaddr_in6 *) &
ch->caddrs[i].ss;
790 if (
match_ipv6 (
"::1", &c6->sin6_addr, 128) &&
795 if ((!
match_ipv6 (
"::1", &c6->sin6_addr, 128)) &&
811 if ((
match_ipv6 (
"fe80::", &c6->sin6_addr, 10)) &&
821 if (0 == htons (v6.sin6_port))
822 v6.sin6_port = c6->sin6_port;
868 const struct in_addr *v4,
872 struct sockaddr_in sa;
876 if ((NULL !=
ch->hole_external) &&
877 (0 == strcasecmp (
ch->hole_external,
881 struct sockaddr_in *s4;
884 "Detected eternal IP, can now back-fill AUTO:%u in hole punching specification of `%s'\n",
885 (
unsigned int)
ch->ext_dns_port,
887 memset (&lal, 0,
sizeof(lal));
888 s4 = (
struct sockaddr_in *) &lal.
addr;
889 s4->sin_family = AF_INET;
890 s4->sin_port = htons (
ch->ext_dns_port);
900 if (!
ch->natted_address)
903 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
905 const struct sockaddr_storage *ss = &
ch->caddrs[i].ss;
907 if (AF_INET != ss->ss_family)
919 sa.sin_family = AF_INET;
921 sa.sin_port = htons (0);
924 "Detected eternal IP %s, notifying client of external IP (without port)\n",
947 const struct sockaddr_in *ra)
950 const struct sockaddr_in *l4;
953 l4 = (
const struct sockaddr_in *) &lal->
addr;
964 if (!
ch->natted_address)
967 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
970 const struct sockaddr_in *c4;
972 if (AF_INET != ca->
ss.ss_family)
974 c4 = (
const struct sockaddr_in *) &ca->
ss;
975 if ((0 != c4->sin_addr.s_addr) &&
976 (l4->sin_addr.s_addr != c4->sin_addr.s_addr))
986 sizeof(
struct sockaddr_in),
990 sizeof(
struct sockaddr_in));
1029 if ((pos->af == lal->af) &&
1030 (0 == memcmp (&lal->addr,
1032 (AF_INET == lal->af)
1033 ?
sizeof(
struct sockaddr_in)
1034 :
sizeof(
struct sockaddr_in6))))
1060 if ((pos->af == lal->af) &&
1061 (0 == memcmp (&lal->addr,
1063 (AF_INET == lal->af)
1064 ?
sizeof(
struct sockaddr_in)
1065 :
sizeof(
struct sockaddr_in6))))
1082 if ((AF_INET == pos->af) &&
1083 (NULL == pos->hc) &&
1086 const struct sockaddr_in *s4
1087 = (
const struct sockaddr_in *) &pos->addr;
1090 "Found NATed local address %s, starting NAT server\n",
1091 GNUNET_a2s ((
const struct sockaddr *) &pos->addr,
1118 const struct sockaddr *addr,
1135 "Running upnpc failed: %d\n",
1141 "external-ip binary not found\n");
1146 "upnpc binary not found\n");
1151 "external-ip binary could not be run\n");
1156 "upnpc failed to create port mapping\n");
1161 "Invalid output from upnpc\n");
1166 "Invalid address returned by upnpc\n");
1173 switch (addr->sa_family)
1176 ac =
is_nat_v4 (&((
const struct sockaddr_in *) addr)->sin_addr)
1182 ac =
is_nat_v6 (&((
const struct sockaddr_in6 *) addr)->sin6_addr)
1192 "upnp external address %s: %s\n",
1193 add_remove ?
"added" :
"removed",
1227 const struct sockaddr *addr,
1232 struct sockaddr_storage ss;
1233 struct sockaddr_in *v4;
1234 struct sockaddr_in6 *v6;
1246 for (lal =
ch->ext_addr_head; NULL != lal; lal = laln)
1263 "Got IP `%s' for external address `%s'\n",
1275 switch (
addr->sa_family)
1278 v4 = (
struct sockaddr_in *) &ss;
1279 v4->sin_port = htons (
ch->ext_dns_port);
1283 v6 = (
struct sockaddr_in6 *) &ss;
1284 v6->sin6_port = htons (
ch->ext_dns_port);
1292 for (lal =
ch->ext_addr_head; NULL != lal; lal = lal->
next)
1296 if ((addr->sa_family == lal->
addr.ss_family) &&
1309 lal->
af = ss.ss_family;
1335 "Performing DNS lookup for punched hole given for `%s' as `%s:%u'\n",
1338 (
unsigned int)
ch->ext_dns_port);
1339 for (lal =
ch->ext_addr_head; NULL != lal; lal = lal->
next)
1341 ch->ext_dns_task = NULL;
1366 struct sockaddr_in *s4;
1369 port = strrchr (
ch->hole_external,
':');
1373 _ (
"Malformed punched hole specification `%s' (lacks port)\n"),
1377 if ((1 != sscanf (
port + 1,
1384 "Invalid port number in punched hole specification `%s' (lacks port)\n"),
1388 ch->ext_dns_port = (uint16_t) pnum;
1392 if (
'[' == *
ch->hole_external)
1394 struct sockaddr_in6 *s6 = (
struct sockaddr_in6 *) &lal->
addr;
1396 s6->sin6_family = AF_INET6;
1397 if (
']' != (
ch->hole_external[strlen (
ch->hole_external) - 1]))
1400 _ (
"Malformed punched hole specification `%s' (lacks `]')\n"),
1405 ch->hole_external[strlen (
ch->hole_external) - 1] =
'\0';
1406 if (1 != inet_pton (AF_INET6,
1407 ch->hole_external + 1,
1412 "Malformed punched hole specification `%s' (IPv6 address invalid)"),
1413 ch->hole_external + 1);
1417 s6->sin6_port = htons (
ch->ext_dns_port);
1429 s4 = (
struct sockaddr_in *) &lal->
addr;
1430 s4->sin_family = AF_INET;
1431 if (1 == inet_pton (AF_INET,
1436 "IPv4 punched hole given for `%s' via `%s:%u'\n",
1439 (
unsigned int)
ch->ext_dns_port);
1440 s4->sin_port = htons (
ch->ext_dns_port);
1451 if (0 == strcasecmp (
ch->hole_external,
1481 if ((0 !=
ch->proto) ||
1482 (NULL !=
ch->caddrs))
1494 left = ntohs (message->
header.
size) -
sizeof(*message);
1495 off = (
const char *) &message[1];
1496 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
1498 const struct sockaddr *sa = (
const struct sockaddr *) off;
1503 if (
sizeof(sa_family_t) > left)
1510 switch (sa->sa_family)
1514 struct sockaddr_in s4;
1518 sizeof(
struct sockaddr_in));
1519 alen =
sizeof(
struct sockaddr_in);
1522 port = ntohs (s4.sin_port);
1528 struct sockaddr_in6 s6;
1532 sizeof(
struct sockaddr_in6));
1533 alen =
sizeof(
struct sockaddr_in6);
1536 port = ntohs (s6.sin6_port);
1542 alen =
sizeof(
struct sockaddr_un);
1561 ((IPPROTO_TCP ==
ch->proto) ||
1562 (IPPROTO_UDP ==
ch->proto)))
1567 IPPROTO_TCP ==
ch->proto,
1579 "Received REGISTER message from client for subsystem `%s'\n",
1585 &
ch->hole_external))
1598 ch->external_monitor
1618 size_t expect = sa_len + ntohs (message->
payload_size);
1620 if (ntohs (message->
header.
size) -
sizeof(*message) != expect)
1625 if (sa_len <
sizeof(sa_family_t))
1649 struct sockaddr_in v4;
1653 if (!
ch->natted_address)
1656 v4.sin_port = htons (0);
1660 msg->add_remove = htonl ((int32_t)
add);
1706 const char *buf = (
const char *) &message[1];
1707 const struct sockaddr *sa;
1710 size_t payload_size;
1711 struct sockaddr_in external_addr;
1715 sa = (
const struct sockaddr *) &buf[0];
1716 payload = (
const struct sockaddr *) &buf[sa_len];
1717 switch (sa->sa_family)
1720 if (sa_len !=
sizeof(
struct sockaddr_in))
1729 if (sa_len !=
sizeof(
struct sockaddr_in6))
1738 "Received HANDLE_STUN message from client\n");
1824 if (ntohs (message->
header.
size) -
sizeof(*message) != expect)
1846 const char *buf = (
const char *) &message[1];
1849 struct sockaddr_in l4;
1850 struct sockaddr_in r4;
1854 "Received REQUEST CONNECTION REVERSAL message from client\n");
1855 if (local_sa_len !=
sizeof(
struct sockaddr_in))
1861 if (remote_sa_len !=
sizeof(
struct sockaddr_in))
1869 sizeof(
struct sockaddr_in));
1871 buf +=
sizeof(
struct sockaddr_in);
1874 sizeof(
struct sockaddr_in));
1877 ntohs (l4.sin_port),
1882 _ (
"Connection reversal request failed\n"));
1902 size_t left = ntohs (message->
header.
size) -
sizeof(*message);
1931 const char *buf = (
const char *) &message[1];
1932 size_t blen = ntohs (message->
header.
size) -
sizeof(*message);
1933 struct sockaddr_in sockaddr_ipv4 = {
1934 .sin_family = AF_INET
1936 char addr[INET_ADDRSTRLEN];
1944 if (blen >=
sizeof(addr))
1947 "Ignoring global address `%.*s': not an IPv4 address\n",
1955 if (1 != inet_pton (AF_INET,
1957 &sockaddr_ipv4.sin_addr))
1964 "Ignoring global address `%s': not an IPv4 address\n",
1985 while (NULL != (se =
se_head))
2032 "RETURN_LOCAL_ADDRESSES");
2048 "UPnP enabled in configuration, but UPnP client `upnpc` command not found, disabling UPnP\n"));
2117 for (
unsigned int i = 0; i <
ch->num_caddrs; i++)
2119 if (NULL !=
ch->caddrs[i].mh)
2122 ch->caddrs[i].mh = NULL;
2126 while (NULL != (lal =
ch->ext_addr_head))
2133 if (NULL !=
ch->ext_dns_task)
2136 ch->ext_dns_task = NULL;
2138 if (NULL !=
ch->external_monitor)
2141 ch->external_monitor = NULL;
2143 if (NULL !=
ch->ext_dns)
2184#if defined(__linux__) && defined(__GLIBC__)
2188GNUNET_NATM_memory_init (
void);
2194GNUNET_NATM_memory_init (
void)
2196 mallopt (M_TRIM_THRESHOLD, 4 * 1024);
2197 mallopt (M_TOP_PAD, 1 * 1024);
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.
struct GNUNET_SCHEDULER_Task * shutdown_task
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 int return_local_addresses
Do we report addresses that are only meaningful on this host to clients that did not explicitly bind ...
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.
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 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.
#define GNUNET_SERVICE_MAIN(pd, service_name, service_options, init_cb, connect_cb, disconnect_cb, cls,...)
Creates the "main" function for a GNUnet service.
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_MQ_Handle * mq
Our connection to the resolver service, created on-demand, but then persists until error or shutdown.
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.