X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fgraph.c;h=8f601c2170f7db497df4e375907f058b9c41ea25;hb=5217c16db4babd64580c2fd7aa36180bb9bd838c;hp=396e35a3e68d2e9373a6dde4a753402ad7d4228f;hpb=57991e264202ad83e2c1b663777b358bf5573652;p=tinc diff --git a/src/graph.c b/src/graph.c index 396e35a3..8f601c21 100644 --- a/src/graph.c +++ b/src/graph.c @@ -176,9 +176,13 @@ static void sssp_bfs(void) { && (e->to->distance != n->distance + 1 || e->weight >= e->to->prevedge->weight)) continue; + // Only update nexthop if it doesn't increase the path length + + if(!e->to->status.visited || (e->to->distance == n->distance + 1 && e->weight >= e->to->prevedge->weight)) + e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop; + e->to->status.visited = true; e->to->status.indirect = indirect; - e->to->nexthop = (n->nexthop == myself) ? e->to : n->nexthop; e->to->prevedge = e; e->to->via = indirect ? n->via : e->to; e->to->options = e->options; @@ -200,6 +204,9 @@ static void sssp_bfs(void) { static void check_reachability(void) { /* Check reachability status. */ + int reachable_count = 0; + int became_reachable_count = 0; + int became_unreachable_count = 0; for splay_each(node_t, n, node_tree) { if(n->status.visited != n->status.reachable) { n->status.reachable = !n->status.reachable; @@ -208,9 +215,13 @@ static void check_reachability(void) { if(n->status.reachable) { logger(DEBUG_TRAFFIC, LOG_DEBUG, "Node %s (%s) became reachable", n->name, n->hostname); + if (n != myself) + became_reachable_count++; } else { logger(DEBUG_TRAFFIC, LOG_DEBUG, "Node %s (%s) became unreachable", n->name, n->hostname); + if (n != myself) + became_unreachable_count++; } if(experimental && OPTION_VERSION(n->options) >= 2) @@ -273,6 +284,16 @@ static void check_reachability(void) { } } } + + if(n->status.reachable && n != myself) + reachable_count++; + } + + if (device_standby) { + if (reachable_count == 0 && became_unreachable_count > 0) + device_disable(); + else if (reachable_count == became_reachable_count) + device_enable(); } }