tinc-gui: Reformat codebase according to PEP8
[tinc] / src / protocol_edge.c
index 7478aae..c000ec0 100644 (file)
@@ -137,6 +137,7 @@ bool add_edge_h(connection_t *c, const char *request) {
                                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
                                                   "ADD_EDGE", c->name, c->hostname);
                                send_add_edge(c, e);
+                               sockaddrfree(&local_address);
                                return true;
                        } else {
                                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) which does not match existing entry",
@@ -151,12 +152,17 @@ bool add_edge_h(connection_t *c, const char *request) {
                                        logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry",
                                                           "ADD_EDGE", c->name, c->hostname);
                                        send_add_edge(c, e);
+                                       sockaddrfree(&local_address);
                                        return true;
                                }
                                // 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;
 
@@ -165,9 +171,14 @@ bool add_edge_h(connection_t *c, const char *request) {
                                        forward_request(c, request);
 
                                return true;
+                       } else {
+                               sockaddrfree(&local_address);
+                               return true;
                        }
-               } else
+               } else {
+                       sockaddrfree(&local_address);
                        return true;
+               }
        } else if(from == myself) {
                logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not exist",
                                   "ADD_EDGE", c->name, c->hostname);
@@ -177,6 +188,7 @@ bool add_edge_h(connection_t *c, const char *request) {
                e->to = to;
                send_del_edge(c, e);
                free_edge(e);
+               sockaddrfree(&local_address);
                return true;
        }