Test deduplicated STUN groups and fallback promotion through real ETCP
This commit is contained in:
1 parent
164a3a1f0f
commit
f433413c49
2 files changed
+128
-9
No files matched your search
@@ -163,7 +163,10 @@ static void finish_probe(struct stun_probe* p) {
|
||||
else if (r->server_count < 2 || r->mapping == STUN_MAP_UNKNOWN || r->filtering == STUN_FILTER_UNKNOWN) r->status = STUN_NAT_PARTIAL;
|
||||
else r->status = STUN_NAT_COMPLETE;
|
||||
}
|
||||
if (r->status == STUN_NAT_COMPLETE || r->status == STUN_NAT_PARTIAL) p->cached = *r;
|
||||
if (r->mapping_reason == STUN_REASON_UNSTABLE || r->filtering_reason == STUN_REASON_UNSTABLE)
|
||||
memset(&p->cached, 0, sizeof(p->cached));
|
||||
if (r->status == STUN_NAT_COMPLETE || (r->status == STUN_NAT_PARTIAL &&
|
||||
(r->mapping != STUN_MAP_UNKNOWN || r->filtering != STUN_FILTER_UNKNOWN))) p->cached = *r;
|
||||
p->due = r->status == STUN_NAT_COMPLETE ? r->measured_at_tb + STUN_REFRESH_TB : r->measured_at_tb + STUN_RETRY_TB;
|
||||
if (r->status == STUN_NAT_SKIPPED) p->due = UINT64_MAX;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NAT,
|
||||
@@ -591,7 +594,9 @@ static int source_snapshot(const struct ETCP_SOCKET* sock, struct stun_source* s
|
||||
source->key.netif_index = sock->netif_index;
|
||||
source->skipped = sock->is_tcp || sock->probe_only || sock->socks_udp || sock->only_local;
|
||||
const struct sockaddr_storage* addr = &sock->local_addr;
|
||||
if (addr->ss_family != AF_INET || !((const struct sockaddr_in*)addr)->sin_addr.s_addr) addr = &sock->local_addr;
|
||||
if ((addr->ss_family == AF_INET && !((const struct sockaddr_in*)addr)->sin_addr.s_addr) ||
|
||||
(addr->ss_family == AF_INET6 && !memcmp(&((const struct sockaddr_in6*)addr)->sin6_addr, &in6addr_any, 16)) ||
|
||||
(addr->ss_family != AF_INET && addr->ss_family != AF_INET6)) addr = &sock->interface_addr;
|
||||
if (addr->ss_family == AF_INET6) {
|
||||
source->key.family = 6;
|
||||
memcpy(source->key.address, &((const struct sockaddr_in6*)addr)->sin6_addr, 16);
|
||||
@@ -826,7 +831,7 @@ int stun_nat_get_socket_result(const struct UTUN_INSTANCE* inst, const struct ET
|
||||
struct stun_source source;
|
||||
if (source_snapshot(socket, &source)) return -1;
|
||||
for (const struct stun_probe* p = inst->stun_nat->probes; p; p = p->next) {
|
||||
if (!key_equal(&p->source.key, &source.key) || !policy_equal(&p->source, &source)) continue;
|
||||
if (!key_equal(&p->source.key, &source.key) || (!p->conflict && !policy_equal(&p->source, &source))) continue;
|
||||
uint64_t now = get_time_tb();
|
||||
int fresh = p->cached.measured_at_tb && now >= p->cached.measured_at_tb && now - p->cached.measured_at_tb < STUN_TTL_TB;
|
||||
*result = fresh ? p->cached : p->result;
|
||||
|
||||
Reference in new issue
Block a user