X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Faddress_cache.c;h=f28dbf902d003d9fee443c0494bbeef95af13478;hb=c6a15e27d934e90a1f3a26438dddb395bdc9de19;hp=b6d48d02be12485466b60815bc29e3e7dc164018;hpb=1cf2b56fcc57073d952928da2338bdaff2cb7889;p=tinc diff --git a/src/address_cache.c b/src/address_cache.c index b6d48d02..f28dbf90 100644 --- a/src/address_cache.c +++ b/src/address_cache.c @@ -25,14 +25,14 @@ #include "netutl.h" #include "xalloc.h" -static const unsigned int NOT_CACHED = -1; +static const unsigned int NOT_CACHED = UINT_MAX; // Find edges pointing to this node, and use them to build a list of unique, known addresses. static struct addrinfo *get_known_addresses(node_t *n) { struct addrinfo *ai = NULL; struct addrinfo *oai = NULL; - for splay_each(edge_t, e, n->edge_tree) { + for splay_each(edge_t, e, &n->edge_tree) { if(!e->reverse) { continue; } @@ -67,6 +67,7 @@ static struct addrinfo *get_known_addresses(node_t *n) { static void free_known_addresses(struct addrinfo *ai) { for(struct addrinfo *aip = ai, *next; aip; aip = next) { next = aip->ai_next; + free(aip->ai_addr); free(aip); } } @@ -89,6 +90,8 @@ void add_recent_address(address_cache_t *cache, const sockaddr_t *sa) { return; } + logger(DEBUG_CONNECTIONS, LOG_DEBUG, "Caching recent address for %s", cache->node->name); + // Shift everything, move/add the address to the first slot if(pos == NOT_CACHED) { if(cache->data.used < MAX_CACHED_ADDRESSES) { @@ -146,7 +149,7 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) { // Otherwise, check if there are any known Address statements if(!cache->config_tree) { - init_configuration(&cache->config_tree); + cache->config_tree = create_configuration(); read_host_config(cache->config_tree, cache->node->name, false); cache->cfg = lookup_config(cache->config_tree, "Address"); } @@ -212,8 +215,10 @@ const sockaddr_t *get_recent_address(address_cache_t *cache) { } // We're all out of addresses. - exit_configuration(&cache->config_tree); - return false; + exit_configuration(cache->config_tree); + cache->config_tree = NULL; + + return NULL; } address_cache_t *open_address_cache(node_t *node) { @@ -248,13 +253,10 @@ address_cache_t *open_address_cache(node_t *node) { return cache; } -void reset_address_cache(address_cache_t *cache, const sockaddr_t *sa) { - if(sa) { - add_recent_address(cache, sa); - } - +void reset_address_cache(address_cache_t *cache) { if(cache->config_tree) { - exit_configuration(&cache->config_tree); + exit_configuration(cache->config_tree); + cache->config_tree = NULL; } if(cache->ai) { @@ -270,7 +272,8 @@ void reset_address_cache(address_cache_t *cache, const sockaddr_t *sa) { void close_address_cache(address_cache_t *cache) { if(cache->config_tree) { - exit_configuration(&cache->config_tree); + exit_configuration(cache->config_tree); + cache->config_tree = NULL; } if(cache->ai) {