X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprotocol_edge.c;h=1d7212275c7652d6bc86fb30dfe81c94887ebd2d;hb=3bf3d7d3e7d51034bda873861c52578f3abe6b5d;hp=c000ec0595ee44e496c1a5bc2cbf1f9b8ad150b5;hpb=3c54765bcdf8bd6114da0cb31f45404950089e3a;p=tinc diff --git a/src/protocol_edge.c b/src/protocol_edge.c index c000ec05..1d721227 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -132,7 +132,13 @@ bool add_edge_h(connection_t *c, const char *request) { e = lookup_edge(from, to); if(e) { - if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) { + // 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 + bool new_local_address = local_address.sa.sa_family && local_address.sa.sa_family != AF_UNKNOWN && + sockaddrcmp(&e->local_address, &local_address); + + if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address) || new_local_address) { if(from == myself) { logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) for ourself which does not match existing entry", "ADD_EDGE", c->name, c->hostname); @@ -142,38 +148,22 @@ bool add_edge_h(connection_t *c, const char *request) { } else { logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) which does not match existing entry", "ADD_EDGE", c->name, c->hostname); - edge_del(e); - graph(); - } - } else if(sockaddrcmp(&e->local_address, &local_address)) { - if(from == myself) { - if(e->local_address.sa.sa_family && local_address.sa.sa_family) { - // Someone has the wrong local address for ourself. Correct then. - 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; + e->options = options; + if(sockaddrcmp(&e->address, &address)) { + sockaddrfree(&e->address); + e->address = address; + } + if(new_local_address) { + sockaddrfree(&e->local_address); + e->local_address = local_address; + } + if(e->weight != weight) { + splay_node_t *node = splay_unlink(edge_weight_tree, e); + e->weight = weight; + splay_insert_node(edge_weight_tree, node); } - // Otherwise, just ignore it. - sockaddrfree(&local_address); - return true; - } 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; - - // Tell others about it. - if(!tunnelserver) - forward_request(c, request); - return true; - } else { - sockaddrfree(&local_address); - return true; + goto done; } } else { sockaddrfree(&local_address); @@ -201,6 +191,7 @@ bool add_edge_h(connection_t *c, const char *request) { e->weight = weight; edge_add(e); +done: /* Tell the rest about the new edge */ if(!tunnelserver)