|
|
|
|
@ -744,6 +744,7 @@ static void scan_sources(struct STUN_NAT* mod) {
|
|
|
|
|
p->ports = u_calloc(1, sizeof(*p->ports)); |
|
|
|
|
if (!p->ports) { DEBUG_ERROR(DEBUG_CATEGORY_NAT, "STUN port history allocation failed"); u_free(p); continue; } |
|
|
|
|
p->ports->key = source.key; p->ports->next = mod->ports; mod->ports = p->ports; |
|
|
|
|
mod->inst->stun_port_history = mod->ports; |
|
|
|
|
} |
|
|
|
|
p->fd = SOCKET_INVALID; |
|
|
|
|
p->next = mod->probes; |
|
|
|
|
@ -790,6 +791,7 @@ int stun_nat_init(struct UTUN_INSTANCE* inst) {
|
|
|
|
|
struct STUN_NAT* mod = u_calloc(1, sizeof(*mod)); |
|
|
|
|
if (!mod) { DEBUG_ERROR(DEBUG_CATEGORY_NAT, "STUN module allocation failed"); return -1; } |
|
|
|
|
mod->inst = inst; |
|
|
|
|
mod->ports = inst->stun_port_history; |
|
|
|
|
inst->stun_nat = mod; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_NAT, "STUN initialized with %d servers; independent test sockets", inst->config->global.stun_server_count); |
|
|
|
|
scan_timer(mod); |
|
|
|
|
@ -803,11 +805,19 @@ void stun_nat_destroy(struct UTUN_INSTANCE* inst) {
|
|
|
|
|
inst->stun_nat = NULL; |
|
|
|
|
if (mod->scan_timer) uasync_cancel_timeout(inst->ua, mod->scan_timer); |
|
|
|
|
while (mod->probes) { struct stun_probe* next = mod->probes->next; destroy_probe(mod->probes); mod->probes = next; } |
|
|
|
|
while (mod->ports) { struct stun_ports* next = mod->ports->next; u_free(mod->ports); mod->ports = next; } |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_NAT, "STUN destroyed; test sockets/DNS/timers released"); |
|
|
|
|
u_free(mod); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void stun_nat_forget_ports(struct UTUN_INSTANCE* inst) { |
|
|
|
|
if (!inst) return; |
|
|
|
|
if (inst->stun_nat) { DEBUG_ERROR(DEBUG_CATEGORY_NAT, "STUN port history release requires stopped module"); return; } |
|
|
|
|
while (inst->stun_port_history) { |
|
|
|
|
struct stun_ports* next = inst->stun_port_history->next; |
|
|
|
|
u_free(inst->stun_port_history); inst->stun_port_history = next; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void stun_nat_recheck(struct UTUN_INSTANCE* inst) { |
|
|
|
|
if (!inst || !inst->stun_nat) return; |
|
|
|
|
struct STUN_NAT* mod = inst->stun_nat; |
|
|
|
|
|