|
|
|
|
@ -1181,15 +1181,25 @@ uint64_t nat_detection_probe_delay(struct NAT_DETECTION *detector) {
|
|
|
|
|
return delay > 10000 ? 10000 : delay; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int nat_detection_observe_allowed(struct NAT_DETECTION *detector, struct ETCP_SOCKET *socket, |
|
|
|
|
const uint8_t peer_key[32], const uint8_t *tag, size_t length) { |
|
|
|
|
if (!detector || !socket || socket->probe_only || !tag || length != ROUTE_OBSERVE_TAG_SIZE || memcmp(tag, "NAT3UDP!", 8)) return 1; |
|
|
|
|
int nat_detection_ping_allowed(struct NAT_DETECTION *detector, struct ETCP_SOCKET *socket, |
|
|
|
|
const uint8_t peer_key[32], const struct sockaddr_storage *source, |
|
|
|
|
uint8_t flags, const uint8_t *tag, size_t length) { |
|
|
|
|
if (!detector || !socket || socket->probe_only || (flags & ETCP_PING_FLAG_ADDRESS_CHECK)) return 1; |
|
|
|
|
nat_detection_probe_delay(detector); |
|
|
|
|
struct nat_socket *state = socket_state(detector, socket, 0); |
|
|
|
|
if (!state || !state->reservation_fingerprint || state->cold_until <= get_time_tb() || |
|
|
|
|
(!detector->automatic && !state->phase && !state->forced) || |
|
|
|
|
(state->measured_profile.source == ADDRESS_SOURCE_ETCP && state->measured_profile.mapping && state->measured_profile.inbound)) return 1; |
|
|
|
|
uint64_t peer = sc_derive_node_id_from_pubkey(peer_key), group_id = read64(tag + 25), round = read64(tag + 17), owner = peer; |
|
|
|
|
uint64_t peer = sc_derive_node_id_from_pubkey(peer_key); |
|
|
|
|
if (!(flags & ETCP_PING_FLAG_OBSERVE)) { |
|
|
|
|
history_load(state); |
|
|
|
|
if (contacted(state, source)) return 1; |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_NAT, "NAT background PING reply deferred socket=%s peer=%016llx source=%s", |
|
|
|
|
socket->name, (unsigned long long)peer, sockaddr_storage_to_str(source).str); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
if (!tag || length != ROUTE_OBSERVE_TAG_SIZE || memcmp(tag, "NAT3UDP!", 8)) return 1; |
|
|
|
|
uint64_t group_id = read64(tag + 25), round = read64(tag + 17), owner = peer; |
|
|
|
|
if (state->phase && state->group_id == group_id && state->round == round && (state->helper == peer || state->observer == peer)) return 1; |
|
|
|
|
for (struct nat_binding *binding = detector->bindings; binding; binding = binding->next) |
|
|
|
|
if (binding->group_id == group_id && binding->round == round && binding->helper == peer && binding->expires > get_time_tb()) { |
|
|
|
|
|