/*
This file is part of GNUnet.
- Copyright (C) 2007-2016 GNUnet e.V.
+ Copyright (C) 2007-2017 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
* Address class of the address.
*/
enum GNUNET_NAT_AddressClass ac;
-
+
/**
* Number of bytes that follow.
*/
* Configuration we use.
*/
const struct GNUNET_CONFIGURATION_Handle *cfg;
-
+
/**
* Message queue for communicating with the NAT service.
*/
* Our registration message.
*/
struct GNUNET_MessageHeader *reg;
-
+
/**
* Head of address DLL.
*/
* Function to call when our addresses change.
*/
GNUNET_NAT_AddressCallback address_callback;
-
+
/**
* Function to call when another peer requests connection reversal.
*/
GNUNET_NAT_ReversalCallback reversal_callback;
-
+
/**
* Closure for the various callbacks.
*/
reconnect (struct GNUNET_NAT_Handle *nh)
{
struct AddrEntry *ae;
-
+
if (NULL != nh->mq)
{
GNUNET_MQ_destroy (nh->mq);
return GNUNET_OK;
}
-
+
/**
* Handle connection reversal request.
*
return GNUNET_OK;
}
-
+
/**
* Handle connection reversal request.
*
enum GNUNET_NAT_AddressClass ac;
struct AddrEntry *ae;
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Received address change notification\n");
ac = (enum GNUNET_NAT_AddressClass) ntohl (acn->addr_class);
if (GNUNET_YES == ntohl (acn->add_remove))
{
struct GNUNET_MQ_Envelope *env;
nh->reconnect_task = NULL;
- nh->mq = GNUNET_CLIENT_connecT (nh->cfg,
+ nh->mq = GNUNET_CLIENT_connect (nh->cfg,
"nat",
handlers,
&mq_error_handler,
* address_callback for any 'plausible' external address.
*
* @param cfg configuration to use
+ * @param config_section name of the configuration section for optionsx
* @param proto protocol this is about, IPPROTO_TCP or IPPROTO_UDP
- * @param hole_external hostname and port of manually punched hole in NAT, otherwise NULL (or empty string)
* @param num_addrs number of addresses in @a addrs
* @param addrs list of local addresses packets should be redirected to
* @param addrlens actual lengths of the addresses in @a addrs
*/
struct GNUNET_NAT_Handle *
GNUNET_NAT_register (const struct GNUNET_CONFIGURATION_Handle *cfg,
+ const char *config_section,
uint8_t proto,
- const char *hole_external,
unsigned int num_addrs,
const struct sockaddr **addrs,
const socklen_t *addrlens,
struct GNUNET_NAT_Handle *nh;
struct GNUNET_NAT_RegisterMessage *rm;
size_t len;
- size_t hole_external_len;
+ size_t str_len;
char *off;
-
+
len = 0;
for (unsigned int i=0;i<num_addrs;i++)
len += addrlens[i];
- hole_external_len
- = (NULL == hole_external)
- ? 0
- : strlen (hole_external);
- len += hole_external_len;
- if ( (len > GNUNET_SERVER_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
+ str_len = strlen (config_section) + 1;
+ len += str_len;
+ if ( (len > GNUNET_MAX_MESSAGE_SIZE - sizeof (*rm)) ||
(num_addrs > UINT16_MAX) )
{
GNUNET_break (0);
if (NULL != reversal_callback)
rm->flags |= GNUNET_NAT_RF_REVERSAL;
rm->proto = proto;
- rm->hole_external_len = htons (hole_external_len);
+ rm->str_len = htons (str_len);
rm->num_addrs = htons ((uint16_t) num_addrs);
off = (char *) &rm[1];
for (unsigned int i=0;i<num_addrs;i++)
if (sizeof (struct sockaddr_in) != addrlens[i])
{
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
break;
if (sizeof (struct sockaddr_in6) != addrlens[i])
{
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
break;
if (sizeof (struct sockaddr_un) != addrlens[i])
{
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
break;
#endif
default:
GNUNET_break (0);
+ GNUNET_free (rm);
return NULL;
}
GNUNET_memcpy (off,
off += addrlens[i];
}
GNUNET_memcpy (off,
- hole_external,
- hole_external_len);
+ config_section,
+ str_len);
nh = GNUNET_new (struct GNUNET_NAT_Handle);
nh->reg = &rm->header;
*
* The function does some basic sanity checks on packet size and
* content, try to extract a bit of information.
- *
+ *
* At the moment this only processes BIND requests, and returns the
* externally visible address of the request to the rest of the
* NAT logic.
* @param nh handle (used for configuration)
* @param local_sa our local address of the peer (IPv4-only)
* @param remote_sa the remote address of the peer (IPv4-only)
- * @return #GNUNET_SYSERR on error,
+ * @return #GNUNET_SYSERR on error,
* #GNUNET_NO if connection reversal is unavailable,
* #GNUNET_OK otherwise (presumably in progress)
*/
if (NULL == nh->mq)
return GNUNET_SYSERR;
+ GNUNET_break (AF_INET == local_sa->sin_family);
+ GNUNET_break (AF_INET == remote_sa->sin_family);
env = GNUNET_MQ_msg_extra (req,
2 * sizeof (struct sockaddr_in),
GNUNET_MESSAGE_TYPE_NAT_REQUEST_CONNECTION_REVERSAL);
void
GNUNET_NAT_unregister (struct GNUNET_NAT_Handle *nh)
{
- GNUNET_MQ_destroy (nh->mq);
+ if (NULL != nh->mq)
+ {
+ GNUNET_MQ_destroy (nh->mq);
+ nh->mq = NULL;
+ }
+ if (NULL != nh->reconnect_task)
+ {
+ GNUNET_SCHEDULER_cancel (nh->reconnect_task);
+ nh->reconnect_task = NULL;
+ }
GNUNET_free (nh->reg);
GNUNET_free (nh);
}