From 415910897122da0073a862784d148802ca390020 Mon Sep 17 00:00:00 2001 From: Etienne Dechamps Date: Sun, 29 Jun 2014 11:01:24 +0100 Subject: [PATCH] Remove broadcast-based local discovery mechanism. The new local address based local discovery mechanism is technically superior to the old broadcast-based one. In fact, the old algorithm can technically make things worse by e.g. sending broadcasts over the VPN itself and then selecting the VPN address as the node's UDP address. This cannot happen with the new mechanism. Note that this means old nodes that don't send their local addresses in ADD_EDGE messages can't be discovered, because there is no address to send discovery packets to. Old nodes can still discover new nodes by sending them broadcasts, though. --- doc/tinc.conf.5.in | 5 +---- src/net.h | 1 - src/net_packet.c | 47 ++++------------------------------------------ src/net_setup.c | 10 ---------- 4 files changed, 5 insertions(+), 58 deletions(-) diff --git a/doc/tinc.conf.5.in b/doc/tinc.conf.5.in index d3c981d8..f208803a 100644 --- a/doc/tinc.conf.5.in +++ b/doc/tinc.conf.5.in @@ -341,10 +341,7 @@ This will allow direct communication using LAN addresses, even if both peers are and they only ConnectTo a third node outside the NAT, which normally would prevent the peers from learning each other's LAN address. .Pp -Currently, local discovery is implemented by sending some packets to the local address of the node during path MTU discovery. With older nodes that don't transmit their local address, it sends local broadcast packets instead. -.It Va LocalDiscoveryAddress Li = Ar address -If this variable is specified, broadcast packets used in local discovery are sent to the given -.Ar address . +Currently, local discovery is implemented by sending some packets to the local address of the node during path MTU discovery. This will not work with old nodes that don't transmit their local address. .It Va MACExpire Li = Ar seconds Pq 600 This option controls the amount of time MAC addresses are kept before they are removed. This only has effect when diff --git a/src/net.h b/src/net.h index 3b2cdf05..d8aa64cd 100644 --- a/src/net.h +++ b/src/net.h @@ -126,7 +126,6 @@ extern int seconds_till_retry; extern int addressfamily; extern unsigned replaywin; extern bool localdiscovery; -extern sockaddr_t localdiscovery_address; extern listen_socket_t listen_socket[MAXSOCKETS]; extern int listen_sockets; diff --git a/src/net_packet.c b/src/net_packet.c index 6d417471..36386b58 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -55,7 +55,6 @@ static void send_udppacket(node_t *, vpn_packet_t *); unsigned replaywin = 16; bool localdiscovery = false; -sockaddr_t localdiscovery_address; #define MAX_SEQNO 1073741824 @@ -598,6 +597,8 @@ static void choose_udp_address(const node_t *n, const sockaddr_t **sa, int *sock } static void choose_local_address(const node_t *n, const sockaddr_t **sa, int *sock) { + *sa = NULL; + /* Pick one of the edges from this node at random, then use its local address. */ int i = 0; @@ -615,46 +616,6 @@ static void choose_local_address(const node_t *n, const sockaddr_t **sa, int *so *sa = &candidate->local_address; *sock = rand() % listen_sockets; adapt_socket(*sa, sock); - return; - } - - /* No candidate? Use broadcasts instead. */ - - static sockaddr_t broadcast_ipv4 = { - .in = { - .sin_family = AF_INET, - .sin_addr.s_addr = -1, - } - }; - - static sockaddr_t broadcast_ipv6 = { - .in6 = { - .sin6_family = AF_INET6, - .sin6_addr.s6_addr[0x0] = 0xff, - .sin6_addr.s6_addr[0x1] = 0x02, - .sin6_addr.s6_addr[0xf] = 0x01, - } - }; - - *sock = rand() % listen_sockets; - - if(listen_socket[*sock].sa.sa.sa_family == AF_INET6) { - if(localdiscovery_address.sa.sa_family == AF_INET6) { - localdiscovery_address.in6.sin6_port = n->prevedge->address.in.sin_port; - *sa = &localdiscovery_address; - } else { - broadcast_ipv6.in6.sin6_port = n->prevedge->address.in.sin_port; - broadcast_ipv6.in6.sin6_scope_id = listen_socket[*sock].sa.in6.sin6_scope_id; - *sa = &broadcast_ipv6; - } - } else { - if(localdiscovery_address.sa.sa_family == AF_INET) { - localdiscovery_address.in.sin_port = n->prevedge->address.in.sin_port; - *sa = &localdiscovery_address; - } else { - broadcast_ipv4.in.sin_port = n->prevedge->address.in.sin_port; - *sa = &broadcast_ipv4; - } } } @@ -756,12 +717,12 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { /* Send the packet */ - const sockaddr_t *sa; + const sockaddr_t *sa = NULL; int sock; if(n->status.send_locally) choose_local_address(n, &sa, &sock); - else + if(!sa) choose_udp_address(n, &sa, &sock); #if defined(SOL_IP) && defined(IP_TOS) diff --git a/src/net_setup.c b/src/net_setup.c index e3c543c9..0a97e03f 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -532,16 +532,6 @@ bool setup_myself_reloadable(void) { get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly); get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery); - memset(&localdiscovery_address, 0, sizeof localdiscovery_address); - if(get_config_string(lookup_config(config_tree, "LocalDiscoveryAddress"), &address)) { - struct addrinfo *ai = str2addrinfo(address, myport, SOCK_DGRAM); - free(address); - if(!ai) - return false; - memcpy(&localdiscovery_address, ai->ai_addr, ai->ai_addrlen); - } - - if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) { if(!strcasecmp(rmode, "router")) routing_mode = RMODE_ROUTER; -- 2.20.1