|
|
|
@ -47,6 +47,15 @@ static bool route_bgp_should_send_to(const struct NODEINFO_Q* nq, uint64_t targe |
|
|
|
static void route_bgp_send_full_table(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn); |
|
|
|
static void route_bgp_send_full_table(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn); |
|
|
|
static void route_bgp_handle_request_table(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn); |
|
|
|
static void route_bgp_handle_request_table(struct ROUTE_BGP* bgp, struct ETCP_CONN* conn); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void nodeinfo_dump_log(const uint8_t* data, size_t len) { |
|
|
|
|
|
|
|
if (!data || len < sizeof(struct BGP_NODEINFO_PACKET)) return; |
|
|
|
|
|
|
|
struct BGP_NODEINFO_PACKET* pkt = (struct BGP_NODEINFO_PACKET*)data; |
|
|
|
|
|
|
|
struct NODEINFO* ni = &pkt->node; |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "NODEINFO nid=%016llx ver=%u v4s=%u v4a=%u hops=%u", |
|
|
|
|
|
|
|
(unsigned long long)ni->node_id, ni->ver, |
|
|
|
|
|
|
|
ni->local_v4_sockets, ni->local_v4_addrs, ni->hop_count); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
static char* nodeinfo_format(const uint8_t* data, size_t len) { |
|
|
|
static char* nodeinfo_format(const uint8_t* data, size_t len) { |
|
|
|
if (!data || len < sizeof(struct BGP_NODEINFO_PACKET)) return NULL; |
|
|
|
if (!data || len < sizeof(struct BGP_NODEINFO_PACKET)) return NULL; |
|
|
|
struct BGP_NODEINFO_PACKET* pkt = (struct BGP_NODEINFO_PACKET*)data; |
|
|
|
struct BGP_NODEINFO_PACKET* pkt = (struct BGP_NODEINFO_PACKET*)data; |
|
|
|
@ -80,7 +89,18 @@ static char* nodeinfo_format(const uint8_t* data, size_t len) { |
|
|
|
return buf; |
|
|
|
return buf; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Old full table sending removed - now using NODEINFO broadcast now */ |
|
|
|
static const char* bgp_subcmd_name(uint8_t subcmd) { |
|
|
|
|
|
|
|
switch (subcmd) { |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_NODEINFO: return "NODEINFO"; |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_REQUEST_TABLE: return "REQ_TABLE"; |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_WITHDRAW: return "WITHDRAW"; |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_PING_REQ: return "PING_REQ"; |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_PING_RESP: return "PING_RESP"; |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_NAT_INFO: return "NAT_INFO"; |
|
|
|
|
|
|
|
case ROUTE_SUBCMD_NAT_CHECK_REQ: return "NAT_CHECK_REQ"; |
|
|
|
|
|
|
|
default: return "?"; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// ============================================================================
|
|
|
|
// Broadcast / Withdraw: node_id - удаляемый узел, wd_source - от кого получена команда удалить
|
|
|
|
// Broadcast / Withdraw: node_id - удаляемый узел, wd_source - от кого получена команда удалить
|
|
|
|
@ -147,11 +167,11 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry* |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Received BGP packet from %s, subcmd=%d, len=%zu", |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "BGP recv %s from %s len=%zu", |
|
|
|
from_conn->log_name, subcmd, entry->len); |
|
|
|
bgp_subcmd_name(subcmd), from_conn->log_name, entry->len); |
|
|
|
|
|
|
|
|
|
|
|
if (subcmd == ROUTE_SUBCMD_NODEINFO) { |
|
|
|
if (subcmd == ROUTE_SUBCMD_NODEINFO) { |
|
|
|
char* s = nodeinfo_format(data, entry->len); if (s) { DEBUG_INFO(DEBUG_CATEGORY_BGP, "%s from %s", s, from_conn->log_name); u_free(s); } |
|
|
|
nodeinfo_dump_log(data, entry->len); |
|
|
|
route_bgp_process_nodeinfo(bgp, from_conn, data, entry->len); |
|
|
|
route_bgp_process_nodeinfo(bgp, from_conn, data, entry->len); |
|
|
|
} else if (subcmd == ROUTE_SUBCMD_WITHDRAW) { |
|
|
|
} else if (subcmd == ROUTE_SUBCMD_WITHDRAW) { |
|
|
|
route_bgp_process_withdraw(bgp, from_conn, data, entry->len); |
|
|
|
route_bgp_process_withdraw(bgp, from_conn, data, entry->len); |
|
|
|
@ -180,8 +200,7 @@ static void route_bgp_receive_cbk(struct ETCP_CONN* from_conn, struct ll_entry* |
|
|
|
static void route_bgp_on_conn_up(struct ETCP_CONN* conn, void* arg) { |
|
|
|
static void route_bgp_on_conn_up(struct ETCP_CONN* conn, void* arg) { |
|
|
|
(void)arg; |
|
|
|
(void)arg; |
|
|
|
if (conn && conn->instance && conn->instance->bgp) { |
|
|
|
if (conn && conn->instance && conn->instance->bgp) { |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "BGP ON UP %s", conn->log_name); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "BGP peer UP: %s peer=%016llx", conn->log_name, (unsigned long long)conn->peer_node_id); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_BGP, "Connection %s on up ", conn->log_name); |
|
|
|
|
|
|
|
route_bgp_new_conn(conn); |
|
|
|
route_bgp_new_conn(conn); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -189,8 +208,7 @@ static void route_bgp_on_conn_up(struct ETCP_CONN* conn, void* arg) { |
|
|
|
static void route_bgp_on_conn_down(struct ETCP_CONN* conn, void* arg) { |
|
|
|
static void route_bgp_on_conn_down(struct ETCP_CONN* conn, void* arg) { |
|
|
|
(void)arg; |
|
|
|
(void)arg; |
|
|
|
if (conn && conn->instance && conn->instance->bgp) { |
|
|
|
if (conn && conn->instance && conn->instance->bgp) { |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "BGP ON DOWN %s", conn->log_name); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "BGP peer DOWN: %s peer=%016llx", conn->log_name, (unsigned long long)conn->peer_node_id); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_BGP, "Connection %s on down ", conn->log_name); |
|
|
|
|
|
|
|
route_bgp_remove_conn(conn); |
|
|
|
route_bgp_remove_conn(conn); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -199,8 +217,7 @@ static void route_bgp_on_conn_down(struct ETCP_CONN* conn, void* arg) { |
|
|
|
static void route_bgp_etcp_conn_cbk(struct ETCP_CONN* conn, void* arg) { |
|
|
|
static void route_bgp_etcp_conn_cbk(struct ETCP_CONN* conn, void* arg) { |
|
|
|
(void)arg; |
|
|
|
(void)arg; |
|
|
|
if (conn && conn->instance && conn->instance->bgp) { |
|
|
|
if (conn && conn->instance && conn->instance->bgp) { |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_DEBUG, "BGP SET CBKS %s", conn->log_name); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "BGP set callbacks: %s", conn->log_name); |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_BGP, "Set ETCP ready callback for connection %s", conn->log_name); |
|
|
|
|
|
|
|
etcp_conn_set_up_cbk(conn, route_bgp_on_conn_up, conn->instance->bgp); |
|
|
|
etcp_conn_set_up_cbk(conn, route_bgp_on_conn_up, conn->instance->bgp); |
|
|
|
etcp_conn_set_down_cbk(conn, route_bgp_on_conn_down, conn->instance->bgp); |
|
|
|
etcp_conn_set_down_cbk(conn, route_bgp_on_conn_down, conn->instance->bgp); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -401,6 +418,7 @@ void route_bgp_remove_conn(struct ETCP_CONN* conn) { |
|
|
|
|
|
|
|
|
|
|
|
// Remove this connection from all nodes' path lists
|
|
|
|
// Remove this connection from all nodes' path lists
|
|
|
|
bool need_withdraw = false; |
|
|
|
bool need_withdraw = false; |
|
|
|
|
|
|
|
int nodes_removed = 0; |
|
|
|
struct ll_entry* node_entry = bgp->nodes ? bgp->nodes->head : NULL; |
|
|
|
struct ll_entry* node_entry = bgp->nodes ? bgp->nodes->head : NULL; |
|
|
|
while (node_entry) { |
|
|
|
while (node_entry) { |
|
|
|
struct ll_entry* next = node_entry->next; |
|
|
|
struct ll_entry* next = node_entry->next; |
|
|
|
@ -414,7 +432,8 @@ void route_bgp_remove_conn(struct ETCP_CONN* conn) { |
|
|
|
uint64_t key = nq->node.node_id; |
|
|
|
uint64_t key = nq->node.node_id; |
|
|
|
struct ll_entry* entry = node_entry; |
|
|
|
struct ll_entry* entry = node_entry; |
|
|
|
if (entry) { queue_remove_data(bgp->nodes, entry); queue_entry_free(entry); } |
|
|
|
if (entry) { queue_remove_data(bgp->nodes, entry); queue_entry_free(entry); } |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Removed node %016llx after link down", (unsigned long long)key); |
|
|
|
nodes_removed++; |
|
|
|
|
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Removed node %016llx after link down", (unsigned long long)key); |
|
|
|
} |
|
|
|
} |
|
|
|
node_entry = next; |
|
|
|
node_entry = next; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -435,7 +454,8 @@ void route_bgp_remove_conn(struct ETCP_CONN* conn) { |
|
|
|
route_bgp_broadcast_withdraw(bgp, conn->peer_node_id, conn->instance->node_id, NULL); |
|
|
|
route_bgp_broadcast_withdraw(bgp, conn->peer_node_id, conn->instance->node_id, NULL); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Connection removed, paths updated"); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "BGP peer removed: %s nodes=%d withdraw=%d", |
|
|
|
|
|
|
|
conn->log_name, nodes_removed, need_withdraw); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -590,7 +610,9 @@ static void nat_link_check_cb(int success, uint16_t avg_rtt, uint8_t count_sent, |
|
|
|
uint8_t socket_id = link->remote_socket_id; |
|
|
|
uint8_t socket_id = link->remote_socket_id; |
|
|
|
route_bgp_send_nat_info(link->etcp, socket_id, na->nat_ip, na->nat_port, nat_type); |
|
|
|
route_bgp_send_nat_info(link->etcp, socket_id, na->nat_ip, na->nat_port, nat_type); |
|
|
|
} |
|
|
|
} |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "nat check result: type=%s for node %s", success ? "OPEN" : "RESTRICTED", link->etcp->log_name); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT check result: type=%s for conn=%s nat=%s:%u", |
|
|
|
|
|
|
|
success ? "EIM" : "STRICT", link->etcp->log_name, |
|
|
|
|
|
|
|
ip_to_str(&na->nat_ip, AF_INET).str, na->nat_port); |
|
|
|
u_free(na); |
|
|
|
u_free(na); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -705,17 +727,15 @@ int route_bgp_process_nodeinfo(struct ROUTE_BGP* bgp, struct ETCP_CONN* from, co |
|
|
|
struct NODEINFO_Q* nodeinfo1 = route_bgp_get_node(bgp, node_id); |
|
|
|
struct NODEINFO_Q* nodeinfo1 = route_bgp_get_node(bgp, node_id); |
|
|
|
uint8_t new_ver = ni->ver; |
|
|
|
uint8_t new_ver = ni->ver; |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NODEINFO from %s node=%016llx new_ver=%d local_ver=%d local_node=%p nodeinfo1=%p", |
|
|
|
|
|
|
|
from->log_name, (unsigned long long)node_id, new_ver, |
|
|
|
|
|
|
|
nodeinfo1 ? nodeinfo1->last_ver : 0, |
|
|
|
|
|
|
|
(void*)bgp->local_node, (void*)nodeinfo1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nodeinfo1 && (int8_t)(nodeinfo1->last_ver-new_ver)>=0) { |
|
|
|
if (nodeinfo1 && (int8_t)(nodeinfo1->last_ver-new_ver)>=0) { |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_BGP, "NODEINFO from %s ignored (old ver %d <= %d)", |
|
|
|
DEBUG_TRACE(DEBUG_CATEGORY_BGP, "NODEINFO ignored old ver: node=%016llx ver=%d<=%d from=%s", |
|
|
|
from->log_name, new_ver, nodeinfo1->last_ver); |
|
|
|
(unsigned long long)node_id, new_ver, nodeinfo1->last_ver, from->log_name); |
|
|
|
return 0; |
|
|
|
return 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NODEINFO: node=%016llx ver=%d v4s=%d v4a=%d hops=%d from=%s", |
|
|
|
|
|
|
|
(unsigned long long)node_id, new_ver, ni->local_v4_sockets, ni->local_v4_addrs, ni->hop_count, from->log_name); |
|
|
|
|
|
|
|
|
|
|
|
int new_data_size=sizeof(struct NODEINFO_Q) - sizeof(struct ll_entry) + dyn_size + 8; |
|
|
|
int new_data_size=sizeof(struct NODEINFO_Q) - sizeof(struct ll_entry) + dyn_size + 8; |
|
|
|
struct ll_queue* paths=NULL; |
|
|
|
struct ll_queue* paths=NULL; |
|
|
|
int need_alloc=0; |
|
|
|
int need_alloc=0; |
|
|
|
@ -751,8 +771,6 @@ int route_bgp_process_nodeinfo(struct ROUTE_BGP* bgp, struct ETCP_CONN* from, co |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/* Если это наш local_node (по node_id), обновляем его данные */ |
|
|
|
/* Если это наш local_node (по node_id), обновляем его данные */ |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Checking local_node update: node_id=%016llx my_id=%016llx local_node=%p", |
|
|
|
|
|
|
|
(unsigned long long)node_id, (unsigned long long)bgp->instance->node_id, (void*)bgp->local_node); |
|
|
|
|
|
|
|
if (node_id == bgp->instance->node_id && bgp->local_node) { |
|
|
|
if (node_id == bgp->instance->node_id && bgp->local_node) { |
|
|
|
uint8_t* dyn_src = (uint8_t*)&nodeinfo1->node + sizeof(struct NODEINFO); |
|
|
|
uint8_t* dyn_src = (uint8_t*)&nodeinfo1->node + sizeof(struct NODEINFO); |
|
|
|
uint8_t* dyn_dst = (uint8_t*)&bgp->local_node->node + sizeof(struct NODEINFO); |
|
|
|
uint8_t* dyn_dst = (uint8_t*)&bgp->local_node->node + sizeof(struct NODEINFO); |
|
|
|
@ -766,7 +784,7 @@ int route_bgp_process_nodeinfo(struct ROUTE_BGP* bgp, struct ETCP_CONN* from, co |
|
|
|
memcpy(dyn_dst, dyn_src, dyn_sz); |
|
|
|
memcpy(dyn_dst, dyn_src, dyn_sz); |
|
|
|
bgp->local_node->node.ver = nodeinfo1->node.ver; |
|
|
|
bgp->local_node->node.ver = nodeinfo1->node.ver; |
|
|
|
bgp->local_node->last_ver = new_ver; |
|
|
|
bgp->local_node->last_ver = new_ver; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Updated local_node from NODEINFO for node %016llx", (unsigned long long)node_id); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Updated local_node from remote NODEINFO: node=%016llx", (unsigned long long)node_id); |
|
|
|
} |
|
|
|
} |
|
|
|
nodeinfo1->paths = paths; |
|
|
|
nodeinfo1->paths = paths; |
|
|
|
nodeinfo1->last_ver = new_ver; |
|
|
|
nodeinfo1->last_ver = new_ver; |
|
|
|
@ -796,7 +814,7 @@ int route_bgp_process_nodeinfo(struct ROUTE_BGP* bgp, struct ETCP_CONN* from, co |
|
|
|
int found=0; |
|
|
|
int found=0; |
|
|
|
for (int i=0; i<hop_count; i++) if (hop_list[i]==id) found=1; |
|
|
|
for (int i=0; i<hop_count; i++) if (hop_list[i]==id) found=1; |
|
|
|
if (found==0) route_bgp_send_nodeinfo(nodeinfo1, item->conn); |
|
|
|
if (found==0) route_bgp_send_nodeinfo(nodeinfo1, item->conn); |
|
|
|
else DEBUG_INFO(DEBUG_CATEGORY_BGP, "Skip send NODEINFO to node %016llx",id); |
|
|
|
else DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Skip send NODEINFO to node %016llx (loop prevention)",id); |
|
|
|
} |
|
|
|
} |
|
|
|
e = e->next; |
|
|
|
e = e->next; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -847,7 +865,7 @@ void route_bgp_send_nodeinfo(struct NODEINFO_Q* node, struct ETCP_CONN* conn) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending NODEINFO to %s", conn->log_name); |
|
|
|
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "Sending NODEINFO to %s", conn->log_name); |
|
|
|
|
|
|
|
|
|
|
|
int dyn = nodeinfo_dyn_size(&node->node); |
|
|
|
int dyn = nodeinfo_dyn_size(&node->node); |
|
|
|
|
|
|
|
|
|
|
|
@ -893,7 +911,7 @@ static void route_bgp_add_to_senders(struct ROUTE_BGP* bgp, struct ETCP_CONN* co |
|
|
|
if (item_entry) { |
|
|
|
if (item_entry) { |
|
|
|
((struct ROUTE_BGP_CONN_ITEM*)item_entry->data)->conn = conn; |
|
|
|
((struct ROUTE_BGP_CONN_ITEM*)item_entry->data)->conn = conn; |
|
|
|
queue_data_put(bgp->senders_list, item_entry); |
|
|
|
queue_data_put(bgp->senders_list, item_entry); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Added to senders_list"); |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Added to senders_list: %s", conn->log_name); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -921,11 +939,11 @@ static void route_bgp_send_full_table(struct ROUTE_BGP* bgp, struct ETCP_CONN* c |
|
|
|
while (e) { |
|
|
|
while (e) { |
|
|
|
struct NODEINFO_Q* nq = (struct NODEINFO_Q*)e; |
|
|
|
struct NODEINFO_Q* nq = (struct NODEINFO_Q*)e; |
|
|
|
if (nq->node.hop_count == 0) { |
|
|
|
if (nq->node.hop_count == 0) { |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "local node in learned list"); |
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_BGP, "local node in learned list"); |
|
|
|
e = e->next; continue; |
|
|
|
e = e->next; continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (!nq->paths) { |
|
|
|
if (!nq->paths) { |
|
|
|
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "node has no paths"); |
|
|
|
DEBUG_WARN(DEBUG_CATEGORY_BGP, "node has no paths"); |
|
|
|
e = e->next; continue; |
|
|
|
e = e->next; continue; |
|
|
|
} |
|
|
|
} |
|
|
|
if (route_bgp_should_send_to(nq, target)) { |
|
|
|
if (route_bgp_should_send_to(nq, target)) { |
|
|
|
@ -951,9 +969,6 @@ static void route_bgp_handle_nat_info(struct ROUTE_BGP* bgp, struct ETCP_CONN* f |
|
|
|
(info->nat_ip[2] << 8) | info->nat_ip[3]; |
|
|
|
(info->nat_ip[2] << 8) | info->nat_ip[3]; |
|
|
|
uint16_t nat_port = ntohs(info->nat_port); |
|
|
|
uint16_t nat_port = ntohs(info->nat_port); |
|
|
|
uint8_t socket_id = info->socket_id; |
|
|
|
uint8_t socket_id = info->socket_id; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT_INFO recv: ip_bytes=0x%02x%02x%02x%02x ip_host=0x%08x port_net=%u port_host=%u socket_id=%u type=%d", |
|
|
|
|
|
|
|
info->nat_ip[0], info->nat_ip[1], info->nat_ip[2], info->nat_ip[3], |
|
|
|
|
|
|
|
nat_ip, info->nat_port, nat_port, socket_id, info->nat_type); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Обновить тип в socket meta
|
|
|
|
// Обновить тип в socket meta
|
|
|
|
uint8_t* dynamic = (uint8_t*)&bgp->local_node->node + sizeof(struct NODEINFO); |
|
|
|
uint8_t* dynamic = (uint8_t*)&bgp->local_node->node + sizeof(struct NODEINFO); |
|
|
|
@ -980,14 +995,11 @@ static void route_bgp_handle_nat_info(struct ROUTE_BGP* bgp, struct ETCP_CONN* f |
|
|
|
while (es) { |
|
|
|
while (es) { |
|
|
|
if (es->sock_id == socket_id) { |
|
|
|
if (es->sock_id == socket_id) { |
|
|
|
if (verified_type == NAT_VERIFIED_STRICT) { |
|
|
|
if (verified_type == NAT_VERIFIED_STRICT) { |
|
|
|
// STRICT: не добавляем NAT адрес в список (бесполезен для probing)
|
|
|
|
|
|
|
|
// но обновляем nat_addr в сокете для информации
|
|
|
|
|
|
|
|
struct sockaddr_in* nat_sin = (struct sockaddr_in*)&es->nat_addr; |
|
|
|
struct sockaddr_in* nat_sin = (struct sockaddr_in*)&es->nat_addr; |
|
|
|
nat_sin->sin_family = AF_INET; |
|
|
|
nat_sin->sin_family = AF_INET; |
|
|
|
nat_sin->sin_addr.s_addr = nat_ip; |
|
|
|
nat_sin->sin_addr.s_addr = nat_ip; |
|
|
|
nat_sin->sin_port = htons(nat_port); |
|
|
|
nat_sin->sin_port = htons(nat_port); |
|
|
|
es->nat_type = verified_type; |
|
|
|
es->nat_type = verified_type; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT_INFO: socket %d is STRICT, not adding to addr list", socket_id); |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
struct sockaddr_in* nat_sin = (struct sockaddr_in*)&es->nat_addr; |
|
|
|
struct sockaddr_in* nat_sin = (struct sockaddr_in*)&es->nat_addr; |
|
|
|
uint32_t old_nat_ip = nat_sin->sin_addr.s_addr; |
|
|
|
uint32_t old_nat_ip = nat_sin->sin_addr.s_addr; |
|
|
|
@ -997,7 +1009,6 @@ static void route_bgp_handle_nat_info(struct ROUTE_BGP* bgp, struct ETCP_CONN* f |
|
|
|
nat_sin->sin_port = htons(nat_port); |
|
|
|
nat_sin->sin_port = htons(nat_port); |
|
|
|
if (old_nat_ip != nat_ip || old_nat_port != nat_port) data_changed = 1; |
|
|
|
if (old_nat_ip != nat_ip || old_nat_port != nat_port) data_changed = 1; |
|
|
|
es->nat_type = verified_type; |
|
|
|
es->nat_type = verified_type; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT_INFO: socket %d type=%d ip=%08x port=%u", socket_id, verified_type, nat_ip, nat_port); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -1087,9 +1098,6 @@ void route_bgp_send_nat_info(struct ETCP_CONN* conn, uint8_t socket_id, uint32_t |
|
|
|
pkt->nat_ip[3] = nat_ip & 0xFF; |
|
|
|
pkt->nat_ip[3] = nat_ip & 0xFF; |
|
|
|
pkt->nat_port = htons(nat_port); |
|
|
|
pkt->nat_port = htons(nat_port); |
|
|
|
pkt->nat_type = nat_type; |
|
|
|
pkt->nat_type = nat_type; |
|
|
|
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT_INFO send: ip_host=0x%08x ip_bytes=0x%02x%02x%02x%02x port_host=%u port_net=%u", |
|
|
|
|
|
|
|
nat_ip, pkt->nat_ip[0], pkt->nat_ip[1], pkt->nat_ip[2], pkt->nat_ip[3], |
|
|
|
|
|
|
|
nat_port, pkt->nat_port); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct ll_entry* e = queue_entry_new(0); |
|
|
|
struct ll_entry* e = queue_entry_new(0); |
|
|
|
if (!e) { |
|
|
|
if (!e) { |
|
|
|
|