|
|
|
|
@ -424,7 +424,7 @@ void route_bgp_new_conn(struct ETCP_CONN* conn) {
|
|
|
|
|
while (c) { |
|
|
|
|
struct ETCP_LINK* l = c->links; |
|
|
|
|
while (l) { |
|
|
|
|
if (l->initialized && l->conn && l->nat_check_status == NAT_CHECK_NONE) { |
|
|
|
|
if (l->initialized && l->conn && l->nat_check_status < NAT_CHECK_IN_PROGRESS) { |
|
|
|
|
route_bgp_start_link_nat_check(bgp, l); |
|
|
|
|
} |
|
|
|
|
l = l->next; |
|
|
|
|
@ -687,9 +687,10 @@ static void route_bgp_start_link_nat_check(struct ROUTE_BGP* bgp, struct ETCP_LI
|
|
|
|
|
// Find third node to send ping through
|
|
|
|
|
struct ETCP_CONN* third_conn = route_bgp_find_third_node(bgp, link->etcp); |
|
|
|
|
if (!third_conn) { |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "route_bgp_start_link_nat_check: no third node found for link"); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "no third node found for link"); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Get target address - use nat_ip/nat_port if set, otherwise use remote_addr
|
|
|
|
|
uint32_t target_ip; |
|
|
|
|
uint16_t target_port; |
|
|
|
|
@ -701,6 +702,9 @@ static void route_bgp_start_link_nat_check(struct ROUTE_BGP* bgp, struct ETCP_LI
|
|
|
|
|
target_ip = ntohl(sin->sin_addr.s_addr); |
|
|
|
|
target_port = ntohs(sin->sin_port); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (is_local_subnet(target_ip)) { DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "local ip: %s, skip nat check", ip_to_str(&target_ip, AF_INET).str); return; } |
|
|
|
|
|
|
|
|
|
// Allocate callback arg
|
|
|
|
|
struct nat_check_arg* arg = u_calloc(1, sizeof(struct nat_check_arg)); |
|
|
|
|
if (!arg) return; |
|
|
|
|
@ -711,7 +715,7 @@ static void route_bgp_start_link_nat_check(struct ROUTE_BGP* bgp, struct ETCP_LI
|
|
|
|
|
const uint8_t* pubkey = link->etcp->crypto_ctx.peer_key_set ? link->etcp->crypto_ctx.peer_public_key : NULL; |
|
|
|
|
if (!pubkey) { |
|
|
|
|
u_free(arg); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "route_bgp_start_link_nat_check: no peer pubkey for link=%p", (void*)link); |
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "no peer pubkey for link=%p", (void*)link); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
// Send ping via third node - embed peer pubkey for NAT detection
|
|
|
|
|
@ -720,11 +724,11 @@ static void route_bgp_start_link_nat_check(struct ROUTE_BGP* bgp, struct ETCP_LI
|
|
|
|
|
pubkey); |
|
|
|
|
if (ret == 0) { |
|
|
|
|
link->nat_check_status = NAT_CHECK_IN_PROGRESS; |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "route_bgp_start_link_nat_check: started for link=%p via=%s", |
|
|
|
|
(void*)link, third_conn->log_name); |
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "ping remote request via=%s (%s:%d)", |
|
|
|
|
(void*)link, third_conn->log_name, ip_to_str(&target_ip, AF_INET).str, target_port); |
|
|
|
|
} else { |
|
|
|
|
u_free(arg); |
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_BGP, "route_bgp_start_link_nat_check: failed to start for link=%p", |
|
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_BGP, "failed to start for link=%p", |
|
|
|
|
(void*)link); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|