From 21da640ebe7bf52b240d117190b2cea267524d92 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Tue, 30 Jun 2026 14:59:09 +0300 Subject: [PATCH] route_bgp: find_conn_for_node prefers live links_up path, fallback to best any --- src/route_bgp.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/route_bgp.c b/src/route_bgp.c index 420ecf3b..43144e01 100644 --- a/src/route_bgp.c +++ b/src/route_bgp.c @@ -495,14 +495,23 @@ struct ETCP_CONN* route_bgp_find_conn_for_node(struct ROUTE_BGP* bgp, uint64_t n struct NODEINFO_Q* nq = nodeinfo_find_by_id(bgp, node_id); if (!nq || !nq->paths || !nq->paths->head) return NULL; struct ll_entry* e = nq->paths->head; - struct NODEINFO_PATH* best = NULL; - uint8_t best_hops = 255; + struct NODEINFO_PATH* best_live = NULL; + uint8_t best_live_hops = 255; + struct NODEINFO_PATH* best_any = NULL; + uint8_t best_any_hops = 255; while (e) { struct NODEINFO_PATH* path = (struct NODEINFO_PATH*)e; - if (path->conn && path->hop_count < best_hops) { best = path; best_hops = path->hop_count; } + if (path->conn) { + if (path->conn->links_up && path->hop_count < best_live_hops) { best_live = path; best_live_hops = path->hop_count; } + if (path->hop_count < best_any_hops) { best_any = path; best_any_hops = path->hop_count; } + } e = e->next; } - return best ? best->conn : NULL; + if (!best_live && best_any) { + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "find_conn_for_node %016llx: no live paths, fallback to best (hops=%d links_up=%d)", + (unsigned long long)node_id, best_any_hops, best_any->conn->links_up); + } + return best_live ? best_live->conn : (best_any ? best_any->conn : NULL); } int route_bgp_add_path(struct NODEINFO_Q* nq, struct ETCP_CONN* conn, uint64_t* hop_list, uint8_t hop_count) {