*/
int use_ipv4;
+ /**
+ * use local addresses?
+ */
+ int use_localaddresses;
+
/**
* Closure passed by MHD to the mhd_logger function
*/
return GNUNET_OK;
}
+static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
+{
+ uint32_t res = 0;
+ int local = GNUNET_NO;
+ int af = addr->sa_family;
+ switch (af)
+ {
+ case AF_INET:
+ {
+ uint32_t netmask = 0x7F000000;
+ uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
+ res = (address >> 24) ^ (netmask >> 24);
+ if (res != 0)
+ local = GNUNET_NO;
+ else
+ local = GNUNET_YES;
+#if DEBUG_HTTP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+#endif
+ break;
+ }
+ case AF_INET6:
+ {
+ if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
+ IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ local = GNUNET_YES;
+ else
+ local = GNUNET_NO;
+#if DEBUG_HTTP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+#endif
+ break;
+ }
+ }
+ return local;
+}
/**
* Add the IP of our network interface to the list of
struct IPv6HttpAddress * t6;
int af;
+ if (plugin->use_localaddresses == GNUNET_NO)
+ {
+ if (GNUNET_YES == check_localaddress (addr, addrlen))
+ {
+#if DEBUG_HTTP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ PROTOCOL_PREFIX,
+ "Not notifying transport of address `%s' (local address)\n",
+ GNUNET_a2s (addr, addrlen));
+#endif
+ return GNUNET_OK;
+ }
+ }
+
GNUNET_assert(cls !=NULL);
af = addr->sa_family;
- if ( (af == AF_INET) &&
- (plugin->use_ipv4 == GNUNET_YES) &&
- (plugin->bind6_address == NULL) )
- {
- struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
+ if ((af == AF_INET) &&
+ (plugin->use_ipv4 == GNUNET_YES) &&
+ (plugin->bind6_address == NULL) ) {
+
+ struct in_addr bnd_cmp = ((struct sockaddr_in *) addr)->sin_addr;
t4 = GNUNET_malloc(sizeof(struct IPv4HttpAddress));
- /* Not skipping loopback addresses
- if (INADDR_LOOPBACK == ntohl(((struct sockaddr_in *) addr)->sin_addr.s_addr))
- {
+ // Not skipping loopback addresses
+
- return GNUNET_OK;
- }
- */
t4->ipv4_addr = ((struct sockaddr_in *) addr)->sin_addr.s_addr;
t4->u_port = htons (plugin->port_inbound);
- if (plugin->bind4_address != NULL)
- {
+ if (plugin->bind4_address != NULL) {
if (0 == memcmp(&plugin->bind4_address->sin_addr, &bnd_cmp, sizeof (struct in_addr)))
- {
- GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,plugin->ipv4_addr_tail,t4);
- plugin->env->notify_address(plugin->env->cls,
- PROTOCOL_PREFIX,
- t4, sizeof (struct IPv4HttpAddress),
- GNUNET_TIME_UNIT_FOREVER_REL);
- return GNUNET_OK;
- }
- GNUNET_free (t4);
- return GNUNET_OK;
- }
+ {
+ GNUNET_CONTAINER_DLL_insert(plugin->ipv4_addr_head,
+ plugin->ipv4_addr_tail,t4);
+ plugin->env->notify_address(plugin->env->cls,
+ PROTOCOL_PREFIX,
+ t4, sizeof (struct IPv4HttpAddress),
+ GNUNET_TIME_UNIT_FOREVER_REL);
+ return GNUNET_OK;
+ }
+ GNUNET_free (t4);
+ return GNUNET_OK;
+ }
else
- {
+ {
GNUNET_CONTAINER_DLL_insert (plugin->ipv4_addr_head,
plugin->ipv4_addr_tail,
t4);
t4, sizeof (struct IPv4HttpAddress),
GNUNET_TIME_UNIT_FOREVER_REL);
return GNUNET_OK;
- }
- }
- else if ( (af == AF_INET6) &&
+ }
+ }
+ if ((af == AF_INET6) &&
(plugin->use_ipv6 == GNUNET_YES) &&
- (plugin->bind4_address == NULL) )
- {
- struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
- if (IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
- {
- return GNUNET_OK;
- }
+ (plugin->bind4_address == NULL) ) {
+
+ struct in6_addr bnd_cmp6 = ((struct sockaddr_in6 *) addr)->sin6_addr;
+
t6 = GNUNET_malloc(sizeof(struct IPv6HttpAddress));
GNUNET_assert(t6 != NULL);
- if (plugin->bind6_address != NULL)
- {
+
+ if (plugin->bind6_address != NULL) {
if (0 == memcmp(&plugin->bind6_address->sin6_addr,
- &bnd_cmp6,
- sizeof (struct in6_addr)))
- {
+ &bnd_cmp6,
+ sizeof (struct in6_addr))) {
memcpy (&t6->ipv6_addr,
&((struct sockaddr_in6 *) addr)->sin6_addr,
sizeof (struct in6_addr));
GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,
plugin->ipv6_addr_tail,
t6);
- return GNUNET_OK;
- }
+ return GNUNET_OK;
+ }
GNUNET_free (t6);
return GNUNET_OK;
- }
+ }
memcpy (&t6->ipv6_addr,
- &((struct sockaddr_in6 *) addr)->sin6_addr,
- sizeof (struct in6_addr));
+ &((struct sockaddr_in6 *) addr)->sin6_addr,
+ sizeof (struct in6_addr));
t6->u6_port = htons (plugin->port_inbound);
GNUNET_CONTAINER_DLL_insert(plugin->ipv6_addr_head,plugin->ipv6_addr_tail,t6);
plugin->env->notify_address(plugin->env->cls,
PROTOCOL_PREFIX,
t6, sizeof (struct IPv6HttpAddress),
GNUNET_TIME_UNIT_FOREVER_REL);
- }
+ }
return GNUNET_OK;
}
plugin->env = env;
plugin->peers = NULL;
plugin->bind4_address = NULL;
+ plugin->bind6_address = NULL;
plugin->use_ipv6 = GNUNET_YES;
plugin->use_ipv4 = GNUNET_YES;
+ plugin->use_localaddresses = GNUNET_NO;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;
plugin->use_ipv4 = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
component_name,"USE_IPv4");
}
+ /* use local addresses? */
+
+ if (GNUNET_CONFIGURATION_have_value (env->cfg,
+ component_name, "USE_LOCALADDR"))
+ {
+ plugin->use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ component_name,
+ "USE_LOCALADDR");
+ }
/* Reading port number from config file */
if ((GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (env->cfg,
#include "gnunet_transport_plugin.h"
#include "transport.h"
-#define DEBUG_TCP GNUNET_YES
+#define DEBUG_TCP GNUNET_NO
-#define DEBUG_TCP_NAT GNUNET_NO
+#define DEBUG_TCP_NAT GNUNET_YES
/**
* How long until we give up on transmitting the welcome message?
*/
char *bind_address;
+ /**
+ * use local addresses?
+ */
+ int use_localaddresses;
+
/**
* List of our IP addresses.
*/
}
+static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
+{
+ uint32_t res = 0;
+ int local = GNUNET_NO;
+ int af = addr->sa_family;
+ switch (af)
+ {
+ case AF_INET:
+ {
+ uint32_t netmask = 0x7F000000;
+ uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
+ res = (address >> 24) ^ (netmask >> 24);
+ if (res != 0)
+ local = GNUNET_NO;
+ else
+ local = GNUNET_YES;
+#if DEBUG_TCP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+#endif
+ break;
+ }
+ case AF_INET6:
+ {
+ if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
+ IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ local = GNUNET_YES;
+ else
+ local = GNUNET_NO;
+#if DEBUG_TCP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+#endif
+ break;
+ }
+ }
+ return local;
+}
+
/**
* Add the IP of our network interface to the list of
* our internal IP addresses.
af = addr->sa_family;
arg_nat = NULL;
+
+ if (plugin->use_localaddresses == GNUNET_NO)
+ {
+ if (GNUNET_YES == check_localaddress (addr, addrlen))
+ {
+#if DEBUG_TCP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR,
+ "tcp",
+ "Not notifying transport of address `%s' (local address)\n",
+ GNUNET_a2s (addr, addrlen));
+#endif
+ return GNUNET_OK;
+ }
+ }
+
switch (af)
{
case AF_INET:
GNUNET_break (0);
return GNUNET_OK;
}
+ if (plugin->adv_port != 0)
+ {
#if DEBUG_TCP
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"tcp",
plugin->env->notify_address (plugin->env->cls,
"tcp",
arg, args, GNUNET_TIME_UNIT_FOREVER_REL);
+ }
if (arg_nat != NULL)
{
#if DEBUG_TCP_NAT
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"tcp"
- "Starting %s %s\n",
- "gnunet-nat-server",
- plugin->internal_address);
+ "Starting %s %s\n", "gnunet-nat-server", plugin->internal_address);
#endif
/* Start the server process */
plugin->server_proc = GNUNET_OS_start_process (NULL,
t4.t_port = htons(0);
GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
"tcp",
- "Notifying transport of address %s:%d\n",
+ "Notifying transport of address %s:%d\n",
plugin->external_address,
0);
}
int enable_nat_client;
int enable_nat_server;
int enable_upnp;
+ int use_localaddresses;
char *internal_address;
char *external_address;
char *bind_address;
return NULL;
}
+ use_localaddresses = GNUNET_NO;
+ if (GNUNET_CONFIGURATION_have_value (env->cfg,
+ "transport-tcp", "USE_LOCALADDR"))
+ {
+ use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "transport-tcp",
+ "USE_LOCALADDR");
+ }
+
if (aport == 0)
aport = bport;
if (bport == 0)
plugin->enable_nat_client = enable_nat_client;
plugin->enable_nat_server = enable_nat_server;
plugin->enable_upnp = enable_upnp;
+ plugin->use_localaddresses = use_localaddresses;
plugin->env = env;
plugin->lsock = NULL;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
#include "gnunet_transport_plugin.h"
#include "transport.h"
-#define DEBUG_UDP GNUNET_YES
+#define DEBUG_UDP GNUNET_NO
#define MAX_PROBES 20
*/
int only_nat_addresses;
+ /**
+ * use local addresses?
+ */
+ int use_localaddresses;
+
/**
* The process id of the server process (if behind NAT)
*/
return GNUNET_SYSERR;
}
+static int check_localaddress (const struct sockaddr *addr, socklen_t addrlen)
+{
+ uint32_t res = 0;
+ int local = GNUNET_NO;
+ int af = addr->sa_family;
+ switch (af)
+ {
+ case AF_INET:
+ {
+ uint32_t netmask = 0x7F000000;
+ uint32_t address = ntohl (((struct sockaddr_in *) addr)->sin_addr.s_addr);
+ res = (address >> 24) ^ (netmask >> 24);
+ if (res != 0)
+ local = GNUNET_NO;
+ else
+ local = GNUNET_YES;
+#if DEBUG_UDP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv4 address `%s': %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+#endif
+ break;
+ }
+ case AF_INET6:
+ {
+ if (IN6_IS_ADDR_LOOPBACK (&((struct sockaddr_in6 *) addr)->sin6_addr) ||
+ IN6_IS_ADDR_LINKLOCAL (&((struct sockaddr_in6 *) addr)->sin6_addr))
+ local = GNUNET_YES;
+ else
+ local = GNUNET_NO;
+#if DEBUG_UDP
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Checking IPv6 address `%s' : %s\n", GNUNET_a2s (addr, addrlen), (local==GNUNET_YES) ? "local" : "global");
+#endif
+ break;
+ }
+ }
+ return local;
+}
+
/**
* Add the IP of our network interface to the list of
addr_nat = NULL;
af = addr->sa_family;
+ if (plugin->use_localaddresses == GNUNET_NO)
+ {
+ if (GNUNET_YES == check_localaddress (addr, addrlen))
+ {
+#if DEBUG_UDP
+ GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
+ "udp",
+ "Not notifying transport of address `%s' (local address)\n",
+ GNUNET_a2s (addr, addrlen));
+#endif
+ return GNUNET_OK;
+ }
+ }
+
memset(buf, 0, INET6_ADDRSTRLEN);
if (af == AF_INET)
{
struct MessageQueue *pending_message;
struct MessageQueue *pending_message_temp;
uint16_t incoming_port;
-
+ struct GNUNET_TRANSPORT_ATS_Information distance[2];
if (memcmp(sender, plugin->env->my_identity, sizeof(struct GNUNET_PeerIdentity)) == 0)
{
#if DEBUG_UDP
/* If we receive these just ignore! */
break;
default:
+
#if DEBUG_UDP
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Sending message type %d to transport!\n",
ntohs(currhdr->type));
#endif
- struct GNUNET_TRANSPORT_ATS_Information distance[2];
+
distance[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
distance[0].value = htonl (UDP_DIRECT_DISTANCE);
distance[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
int behind_nat;
int allow_nat;
int only_nat_addresses;
+ int use_localaddresses;
char *internal_address;
char *external_address;
struct IPv4UdpAddress v4_address;
_("MTU %llu for `%s' is probably too low!\n"), mtu,
"UDP");
+ use_localaddresses = GNUNET_NO;
+ if (GNUNET_CONFIGURATION_have_value (env->cfg,
+ "transport-udp", "USE_LOCALADDR"))
+ {
+ use_localaddresses = GNUNET_CONFIGURATION_get_value_yesno (env->cfg,
+ "transport-udp",
+ "USE_LOCALADDR");
+ }
+
plugin = GNUNET_malloc (sizeof (struct Plugin));
plugin->external_address = external_address;
plugin->internal_address = internal_address;
plugin->allow_nat = allow_nat;
plugin->only_nat_addresses = only_nat_addresses;
plugin->env = env;
+ plugin->use_localaddresses = use_localaddresses;
api = GNUNET_malloc (sizeof (struct GNUNET_TRANSPORT_PluginFunctions));
api->cls = plugin;