|
|
|
|
@ -1295,6 +1295,10 @@ static void send_init_response(struct ETCP_SOCKET* e_sock, struct ETCP_DGRAM* pk
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
/* Self-detection: if my IP is non-local, I'm on a public IP */ |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_NAT, "self-detect check: socket=%s type=%d nat_type=%d if_addr=%s local_addr=%s", |
|
|
|
|
e_sock->name, e_sock->type, e_sock->nat_type, |
|
|
|
|
sockaddr_storage_to_str(&e_sock->interface_addr).str, |
|
|
|
|
sockaddr_storage_to_str(&e_sock->local_addr).str); |
|
|
|
|
if (e_sock->nat_type != NAT_VERIFIED_DIRECT && e_sock->interface_addr.ss_family == AF_INET) { |
|
|
|
|
uint32_t my_ip = ((struct sockaddr_in*)&e_sock->interface_addr)->sin_addr.s_addr; |
|
|
|
|
if (my_ip != 0 && !is_local_subnet(my_ip)) { |
|
|
|
|
@ -1317,8 +1321,9 @@ static void send_init_response(struct ETCP_SOCKET* e_sock, struct ETCP_DGRAM* pk
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Self-detected PUBLIC IP: %s on socket %s (id=%d)", |
|
|
|
|
ip_to_str(&my_ip, AF_INET).str, e_sock->name, e_sock->sock_id); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_NAT, "Self-detected PUBLIC: socket=%s ip=%s port=%u sock_id=%d", |
|
|
|
|
e_sock->name, ip_to_str(&my_ip, AF_INET).str, |
|
|
|
|
ntohs(nat_sin->sin_port), e_sock->sock_id); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
pkt->noencrypt_len=0; |
|
|
|
|
@ -1423,11 +1428,17 @@ static int handle_init_response_client(struct ETCP_SOCKET* e_sock, struct ETCP_D
|
|
|
|
|
|
|
|
|
|
// Update socket NAT address (only if not already verified)
|
|
|
|
|
{ |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_NAT, "init_resp nat: socket=%s nat_type=%d new_ip=%s new_port=%u", |
|
|
|
|
e_sock->name, e_sock->nat_type, |
|
|
|
|
ip_to_str(&new_nat_ip, AF_INET).str, new_nat_port); |
|
|
|
|
if (e_sock->nat_type < NAT_VERIFIED_UNKNOWN) { |
|
|
|
|
struct sockaddr_in* sin = (struct sockaddr_in*)&e_sock->nat_addr; |
|
|
|
|
sin->sin_family = AF_INET; |
|
|
|
|
sin->sin_addr.s_addr = new_nat_ip; |
|
|
|
|
sin->sin_port = htons(new_nat_port); |
|
|
|
|
} else { |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_NAT, "init_resp nat update SKIPPED (already verified): socket=%s nat_type=%d", |
|
|
|
|
e_sock->name, e_sock->nat_type); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
|