|
|
|
@ -193,6 +193,17 @@ static void nat_detection_on_conn_down(struct ETCP_CONN* conn, int event, void* |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* Закрытие ОДНОГО линка (без разрыва conn): etcp_fire_link_status_cbk вызывается
|
|
|
|
|
|
|
|
* из etcp_link_close до u_free(link) — здесь link ещё валиден. Гасим NAT-чек этого |
|
|
|
|
|
|
|
* линка, иначе na->link останется висячим указателем. */ |
|
|
|
|
|
|
|
static void nat_detection_on_link_status(struct ETCP_CONN* conn, struct ETCP_LINK* link, |
|
|
|
|
|
|
|
int old_state, int old_status, void* arg) { |
|
|
|
|
|
|
|
(void)conn; (void)old_state; (void)old_status; |
|
|
|
|
|
|
|
struct NAT_DETECTION* nd = (struct NAT_DETECTION*)arg; |
|
|
|
|
|
|
|
if (!nd || !link) return; |
|
|
|
|
|
|
|
if (link->link_status == 0) route_ping_cancel_for_link(nd, link); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static void nat_detection_new_conn_cbk(struct ETCP_CONN* conn, void* arg) { |
|
|
|
static void nat_detection_new_conn_cbk(struct ETCP_CONN* conn, void* arg) { |
|
|
|
if (!conn || !conn->instance) return; |
|
|
|
if (!conn || !conn->instance) return; |
|
|
|
struct NAT_DETECTION* nd = (struct NAT_DETECTION*)arg; |
|
|
|
struct NAT_DETECTION* nd = (struct NAT_DETECTION*)arg; |
|
|
|
@ -273,6 +284,7 @@ struct NAT_DETECTION* nat_detection_create(struct UTUN_INSTANCE* inst) { |
|
|
|
nd->allow_nat_check_local = 0; |
|
|
|
nd->allow_nat_check_local = 0; |
|
|
|
etcp_bind(inst, ETCP_ID_NAT_DETECTION, nat_detection_receive_cbk); |
|
|
|
etcp_bind(inst, ETCP_ID_NAT_DETECTION, nat_detection_receive_cbk); |
|
|
|
etcp_add_new_conn_cbk(inst, nat_detection_new_conn_cbk, nd); |
|
|
|
etcp_add_new_conn_cbk(inst, nat_detection_new_conn_cbk, nd); |
|
|
|
|
|
|
|
etcp_add_link_status_cbk(inst, nat_detection_on_link_status, nd); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT detection initialized"); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT detection initialized"); |
|
|
|
return nd; |
|
|
|
return nd; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -281,6 +293,7 @@ void nat_detection_destroy(struct NAT_DETECTION* nd) { |
|
|
|
if (!nd) return; |
|
|
|
if (!nd) return; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT detection destroy"); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT detection destroy"); |
|
|
|
etcp_remove_new_conn_cbk(nd->inst, nat_detection_new_conn_cbk, nd); |
|
|
|
etcp_remove_new_conn_cbk(nd->inst, nat_detection_new_conn_cbk, nd); |
|
|
|
|
|
|
|
etcp_remove_link_status_cbk(nd->inst, nat_detection_on_link_status, nd); |
|
|
|
etcp_unbind(nd->inst, ETCP_ID_NAT_DETECTION); |
|
|
|
etcp_unbind(nd->inst, ETCP_ID_NAT_DETECTION); |
|
|
|
route_ping_destroy_pending(nd); |
|
|
|
route_ping_destroy_pending(nd); |
|
|
|
u_free(nd); |
|
|
|
u_free(nd); |
|
|
|
|