Don't keep an address cache in an outgoing_t.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 17 Jul 2019 23:33:38 +0000 (01:33 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 17 Jul 2019 23:33:38 +0000 (01:33 +0200)
Address caches are associated with nodes, so just use the address cache
in the node_t struct. Also ensure we always have opened an address cache in
setup_outgoing_connection().

Thanks to admincheg for finding this issue.

src/net.h
src/net_socket.c
src/protocol_misc.c

index 8a74d859d5ff1e5f5bb4a34e1f022df284d8e898..cf0ddc795312fc4e7eddcb88bf6aa2efa4fea2e1 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -121,7 +121,6 @@ typedef struct listen_socket_t {
 typedef struct outgoing_t {
        struct node_t *node;
        int timeout;
-       struct address_cache_t *address_cache;
        timeout_t ev;
 } outgoing_t;
 
index a69612790852b2d7379ae8d781360c6722a852c6..206321cd52425d9cfc4bfbc887d59310d5612dc6 100644 (file)
@@ -527,7 +527,7 @@ bool do_outgoing_connection(outgoing_t *outgoing) {
        int result;
 
 begin:
-       sa = get_recent_address(outgoing->address_cache);
+       sa = get_recent_address(outgoing->node->address_cache);
 
        if(!sa) {
                logger(DEBUG_CONNECTIONS, LOG_ERR, "Could not set up a meta connection to %s", outgoing->node->name);
@@ -632,6 +632,10 @@ void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) {
 
        node_t *n = outgoing->node;
 
+       if(!n->address_cache) {
+               n->address_cache = open_address_cache(n);
+       }
+
        if(n->connection) {
                logger(DEBUG_CONNECTIONS, LOG_INFO, "Already connected to %s", n->name);
 
@@ -643,10 +647,6 @@ void setup_outgoing_connection(outgoing_t *outgoing, bool verbose) {
                }
        }
 
-       if(!outgoing->address_cache) {
-               outgoing->address_cache = open_address_cache(n);
-       }
-
        do_outgoing_connection(outgoing);
        return;
 
@@ -787,11 +787,6 @@ void handle_new_unix_connection(void *data, int flags) {
 
 static void free_outgoing(outgoing_t *outgoing) {
        timeout_del(&outgoing->ev);
-
-       if(outgoing->address_cache) {
-               close_address_cache(outgoing->address_cache);
-       }
-
        free(outgoing);
 }
 
index a4fcd6f7ba7871d706783198cea9203c5450cff2..050e30a0e3908f7bdaafeb8869689a49bf783b16 100644 (file)
@@ -71,9 +71,9 @@ bool pong_h(connection_t *c, const char *request) {
 
        /* Successful connection, reset timeout if this is an outgoing connection. */
 
-       if(c->outgoing) {
+       if(c->outgoing && c->outgoing->timeout) {
                c->outgoing->timeout = 0;
-               reset_address_cache(c->outgoing->address_cache, &c->address);
+               reset_address_cache(c->outgoing->node->address_cache, &c->address);
        }
 
        return true;