diff --git a/src/etcp.c b/src/etcp.c index ce3daed4..29f60dc5 100644 --- a/src/etcp.c +++ b/src/etcp.c @@ -216,10 +216,14 @@ void etcp_connection_close(struct ETCP_CONN* etcp) { } // Clear links list safely + DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "connection_close: %s links=%p clearing_links", + etcp->log_name, (void*)etcp->links); if (etcp->links) { struct ETCP_LINK* link = etcp->links; while (link) { struct ETCP_LINK* next = link->next; + DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "connection_close: closing link=%p nat_status=%d", + (void*)link, link->nat_check_status); etcp_link_close(link); link = next; } diff --git a/src/route_bgp.c b/src/route_bgp.c index 31eae0b2..f23bc080 100644 --- a/src/route_bgp.c +++ b/src/route_bgp.c @@ -384,8 +384,19 @@ void route_bgp_remove_conn(struct ETCP_CONN* conn) { (unsigned long long)conn->peer_node_id); // Cancel pending NAT checks for this connection's links - route_ping_cancel_for_conn(bgp, conn); + int link_count = 0; struct ETCP_LINK* lnk = conn->links; + while (lnk) { + link_count++; + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "remove_conn: link=%p nat_status=%d", + (void*)lnk, lnk->nat_check_status); + lnk = lnk->next; + } + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "remove_conn: total links=%d for %s", link_count, conn->log_name); + + route_ping_cancel_for_conn(bgp, conn); + + lnk = conn->links; while (lnk) { if (lnk->nat_check_status == NAT_CHECK_IN_PROGRESS) { lnk->nat_check_status = NAT_CHECK_NONE; diff --git a/src/route_ping.c b/src/route_ping.c index 0bf8319e..07a60d66 100644 --- a/src/route_ping.c +++ b/src/route_ping.c @@ -103,12 +103,26 @@ void route_ping_handle_resp(struct ROUTE_BGP* bgp, struct ETCP_CONN* from_conn, void route_ping_cancel_for_conn(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn) { if (!bgp || !conn) return; - struct route_ping_pending** cur = &bgp->ping_pending; + + if (!bgp->ping_pending) { + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "cancel_for_conn: ping_pending is NULL for %s", conn->log_name); + return; + } + + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "cancel_for_conn: checking pending for %s", conn->log_name); + int cancelled = 0; + struct route_ping_pending** cur = &bgp->ping_pending; while (*cur) { struct route_ping_pending* p = *cur; struct nat_check_arg* na = (struct nat_check_arg*)p->arg; - if (na && na->link && na->link->conn == conn) { + + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, " checking pending req_id=%016llx arg=%p na=%p link=%p link->etcp=%s", + (unsigned long long)p->request_id, p->arg, na, + na ? na->link : NULL, + (na && na->link && na->link->etcp) ? na->link->etcp->log_name : "NULL"); + + if (na && na->link && na->link->etcp == conn) { *cur = p->next; if (p->timeout_timer) { uasync_cancel_timeout(bgp->instance->ua, p->timeout_timer); @@ -118,13 +132,15 @@ void route_ping_cancel_for_conn(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn) { na->link = NULL; u_free(p); cancelled++; + DEBUG_INFO(DEBUG_CATEGORY_BGP, "cancel_for_conn: cancelled req_id=%016llx", + (unsigned long long)p->request_id); } else { cur = &(*cur)->next; } } - if (cancelled > 0) { - DEBUG_INFO(DEBUG_CATEGORY_BGP, "Cancelled %d pending NAT checks for conn %s", - cancelled, conn->log_name); + + if (cancelled == 0) { + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "cancel_for_conn: no pending found for %s", conn->log_name); } } @@ -187,6 +203,12 @@ int route_ping_send_req_addr(struct ROUTE_BGP* bgp, struct ETCP_CONN* to_conn, pending->next = bgp->ping_pending; bgp->ping_pending = pending; + struct nat_check_arg* na_dbg = (struct nat_check_arg*)arg; + DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "pending created req_id=%016llx arg=%p link=%p link->etcp=%s", + (unsigned long long)pending->request_id, pending->arg, + na_dbg ? na_dbg->link : NULL, + (na_dbg && na_dbg->link && na_dbg->link->etcp) ? na_dbg->link->etcp->log_name : "NULL"); + pending->timeout_timer = uasync_set_timeout(bgp->instance->ua, wait_timeout_ms * 10, pending, route_ping_pending_timeout, "route_ping"); DEBUG_INFO(DEBUG_CATEGORY_BGP, "request_id=%016llx ip=%s port=%u pubkey=%s",