Prevent tinc from forgeting e->local_address
authorthorkill <thkr@hannover.ccc.de>
Tue, 7 Jul 2015 21:14:08 +0000 (23:14 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Sun, 12 Jul 2015 11:32:38 +0000 (13:32 +0200)
If ADD_EDGE came from tinc version 1.0.x local_address.sa.sa_family is set to 0.
If it came from tinc version 1.1.x forwarded for older verion it will be 255 - AF_UNKNOWN.

src/protocol_edge.c

index 1924ee3..c000ec0 100644 (file)
@@ -158,8 +158,11 @@ bool add_edge_h(connection_t *c, const char *request) {
                                // Otherwise, just ignore it.
                                sockaddrfree(&local_address);
                                return true;
-                       } else if(local_address.sa.sa_family) {
+                       } else if(local_address.sa.sa_family && local_address.sa.sa_family != AF_UNKNOWN) {
                                // We learned a new local address for this edge.
+                               // local_address.sa.sa_family will be 0 if we got it from older tinc versions
+                               // local_address.sa.sa_family will be 255 (AF_UNKNOWN) if we got it from newer versions
+                               // but for edge which does not have local_address
                                sockaddrfree(&e->local_address);
                                e->local_address = local_address;
 
@@ -169,6 +172,7 @@ bool add_edge_h(connection_t *c, const char *request) {
 
                                return true;
                        } else {
+                               sockaddrfree(&local_address);
                                return true;
                        }
                } else {