- if(e->weight != weight || e->options != options || sockaddrcmp(&e->address, &address)) {
- if(from == myself) {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(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);
- return 0;
- } else {
- if(debug_lvl >= DEBUG_PROTOCOL)
- syslog(LOG_WARNING, _("Got %s from %s (%s) which does not match existing entry"),
- "ADD_EDGE", c->name, c->hostname);
- edge_del(e);
- }
- } else
- return 0;
+ 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);
+ }