From: Guus Sliepen <guus@tinc-vpn.org>
Date: Thu, 18 Oct 2018 13:59:24 +0000 (+0200)
Subject: Check all Address statements when making outgoing connections.
X-Git-Tag: release-1.1pre18~48
X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=1cf2b56fcc57073d952928da2338bdaff2cb7889;p=tinc

Check all Address statements when making outgoing connections.

The logic in get_recent_address() caused tinc to only consider the first
Address statement that could be resolved to one or more IP addresses.
---

diff --git a/src/address_cache.c b/src/address_cache.c
index 445cd1c5..b6d48d02 100644
--- a/src/address_cache.c
+++ b/src/address_cache.c
@@ -151,7 +151,7 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) {
 		cache->cfg = lookup_config(cache->config_tree, "Address");
 	}
 
-	while(cache->cfg && !cache->ai) {
+	while(cache->cfg && !cache->aip) {
 		char *address, *port;
 
 		get_config_string(cache->cfg, &address);
@@ -167,6 +167,10 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) {
 			}
 		}
 
+		if(cache->ai) {
+			free_known_addresses(cache->ai);
+		}
+
 		cache->aip = cache->ai = str2addrinfo(address, port, SOCK_STREAM);
 
 		if(cache->ai) {