X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fprotocol_edge.c;h=92089b1c6a13d93c3ccfcf09fb6bb4a07f6ae69e;hb=06b820133285f83f7e1a839cccbed13358b84081;hp=1924ee35e3733316654c915b1d25207e18f32134;hpb=1e7ef381980a5c4c84d699522265290dde5ac728;p=tinc diff --git a/src/protocol_edge.c b/src/protocol_edge.c index 1924ee35..92089b1c 100644 --- a/src/protocol_edge.c +++ b/src/protocol_edge.c @@ -132,49 +132,52 @@ 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)) { - 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); - 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", - "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; - } - // Otherwise, just ignore it. - sockaddrfree(&local_address); - return true; - } else if(local_address.sa.sa_family) { - // We learned a new local address for this edge. - sockaddrfree(&e->local_address); - e->local_address = local_address; - - // Tell others about it. - if(!tunnelserver) - forward_request(c, request); - - return true; - } else { - return true; - } - } else { + bool new_address = 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 && !new_address && !new_local_address) { + sockaddrfree(&address); + sockaddrfree(&local_address); + return true; + } + + 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); + send_add_edge(c, e); + sockaddrfree(&address); sockaddrfree(&local_address); return true; } + + logger(DEBUG_PROTOCOL, LOG_WARNING, "Got %s from %s (%s) which does not match existing entry", + "ADD_EDGE", c->name, c->hostname); + + e->options = options; + + if(new_address) { + sockaddrfree(&e->address); + e->address = address; + } else { + sockaddrfree(&address); + } + + if(new_local_address) { + sockaddrfree(&e->local_address); + e->local_address = local_address; + } else { + sockaddrfree(&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); + } } 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); @@ -184,19 +187,20 @@ bool add_edge_h(connection_t *c, const char *request) { e->to = to; send_del_edge(c, e); free_edge(e); + sockaddrfree(&address); sockaddrfree(&local_address); return true; + } else { + e = new_edge(); + e->from = from; + e->to = to; + e->address = address; + e->local_address = local_address; + e->options = options; + e->weight = weight; + edge_add(e); } - e = new_edge(); - e->from = from; - e->to = to; - e->address = address; - e->local_address = local_address; - e->options = options; - e->weight = weight; - edge_add(e); - /* Tell the rest about the new edge */ if(!tunnelserver)