Browse Source

Trace the first UDP contacts that affect cold NAT classification

master
evgeny 7 days ago
parent
commit
f71e94c9d8
  1. 7
      src/routing_layer/nat_detection.c
  2. 5
      tests/test_nat_detection.c

7
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]; 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; 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; 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->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_complete) DEBUG_WARN(DEBUG_CATEGORY_NAT, "NAT contact history full socket=%s", socket->name);
if (!state->history_incomplete) history_mark_incomplete(state); if (!state->history_incomplete) history_mark_incomplete(state);

5
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}; struct nat_check_status status = {0};
nat_detection_get_status(socket->instance->nat_det, socket, &status); 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", DEBUG_ERROR(DEBUG_CATEGORY_NAT, "profile wait failed node=%016llx socket=%s mapping=%s inbound=%s phase=%u reason=%s",
socket->name, address_mapping_name(socket->address_profile.mapping), (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)); address_inbound_name(socket->address_profile.inbound), status.phase, nat_check_reason_name(status.reason));
abort(); abort();
} }
@ -50,6 +50,7 @@ static void check_snapshot(struct UTUN_INSTANCE *owner, struct ETCP_SOCKET *sock
int main(void) { int main(void) {
debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); debug_set_category_level(DEBUG_CATEGORY_NAT, DEBUG_LEVEL_DEBUG); 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 nat_fixture fixture; nat_fixture_init(&fixture);
struct SC_MYKEYS first, second; struct SC_MYKEYS first, second;
assert(sc_generate_keypair(&first) == SC_OK && sc_generate_keypair(&second) == SC_OK); assert(sc_generate_keypair(&first) == SC_OK && sc_generate_keypair(&second) == SC_OK);

Loading…
Cancel
Save