From f71e94c9d8c8fa67e3dc918ecfd5b32e67ea73b1 Mon Sep 17 00:00:00 2001 From: evgeny Date: Mon, 12 Oct 2026 19:17:06 +0200 Subject: [PATCH] Trace the first UDP contacts that affect cold NAT classification --- src/routing_layer/nat_detection.c | 7 +++++++ tests/test_nat_detection.c | 5 +++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/routing_layer/nat_detection.c b/src/routing_layer/nat_detection.c index 96c0bd38..478b2359 100644 --- a/src/routing_layer/nat_detection.c +++ b/src/routing_layer/nat_detection.c @@ -384,6 +384,13 @@ void nat_detection_note_send(struct NAT_DETECTION *detector, struct ETCP_SOCKET uint8_t local[ROUTE_ADDR_WIRE_SIZE], remote[ROUTE_ADDR_WIRE_SIZE]; if (route_ping_addr_encode(local, &state->local) || route_ping_addr_encode(remote, destination)) return; for (unsigned i = 0; i < state->contact_count; i++) if (!memcmp(state->contacts[i], remote, 17)) return; + DEBUG_DEBUG(DEBUG_CATEGORY_NAT, "NAT first UDP contact node=%016llx socket=%s id=%u generation=%016llx phase=%u group=%016llx" + " round=%016llx destination=%s reserved=%u cold_remaining_tb=%llu", + (unsigned long long)detector->instance->node_id, socket->name, socket->sock_id, + (unsigned long long)socket->generation, state->phase, (unsigned long long)state->group_id, + (unsigned long long)state->round, sockaddr_storage_to_str(destination).str, + state->reservation_fingerprint != 0, + (unsigned long long)(state->cold_until > get_time_tb() ? state->cold_until - get_time_tb() : 0)); if (state->contact_count == NAT_MAX_CONTACTS) { if (state->history_complete) DEBUG_WARN(DEBUG_CATEGORY_NAT, "NAT contact history full socket=%s", socket->name); if (!state->history_incomplete) history_mark_incomplete(state); diff --git a/tests/test_nat_detection.c b/tests/test_nat_detection.c index 30cb6819..d99cb687 100644 --- a/tests/test_nat_detection.c +++ b/tests/test_nat_detection.c @@ -12,8 +12,8 @@ static void wait_profile(struct nat_fixture *fixture, struct ETCP_SOCKET *socket } struct nat_check_status status = {0}; nat_detection_get_status(socket->instance->nat_det, socket, &status); - DEBUG_ERROR(DEBUG_CATEGORY_NAT, "profile wait failed socket=%s mapping=%s inbound=%s phase=%u reason=%s", - socket->name, address_mapping_name(socket->address_profile.mapping), + DEBUG_ERROR(DEBUG_CATEGORY_NAT, "profile wait failed node=%016llx socket=%s mapping=%s inbound=%s phase=%u reason=%s", + (unsigned long long)socket->instance->node_id, socket->name, address_mapping_name(socket->address_profile.mapping), address_inbound_name(socket->address_profile.inbound), status.phase, nat_check_reason_name(status.reason)); abort(); } @@ -50,6 +50,7 @@ static void check_snapshot(struct UTUN_INSTANCE *owner, struct ETCP_SOCKET *sock int main(void) { debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); debug_set_category_level(DEBUG_CATEGORY_NAT, DEBUG_LEVEL_DEBUG); + debug_set_category_level(DEBUG_CATEGORY_BGP, DEBUG_LEVEL_DEBUG); struct nat_fixture fixture; nat_fixture_init(&fixture); struct SC_MYKEYS first, second; assert(sc_generate_keypair(&first) == SC_OK && sc_generate_keypair(&second) == SC_OK);