NODEINFO: Add nat_addr/nat_port fields, use interface_addr for addr/port

This commit is contained in:
Evgeny committed 2026-04-23 23:21:12 +03:00
1 parent f02603f8ac
commit a3063ea47a
5 files changed
+49 -23

No files matched your search

+4 -4
View File
@@ -364,13 +364,13 @@ int main(void) {
int found = 0;
for (int i = 0; i < sock_count; i++) {
if (sockets[i].id == sock_c1->sock_id) {
uint32_t s_ip = (sockets[i].addr[0] << 24) | (sockets[i].addr[1] << 16) |
(sockets[i].addr[2] << 8) | sockets[i].addr[3];
if (s_ip != link_sc1->nat_ip || sockets[i].port != link_sc1->nat_port ||
uint32_t s_ip = (sockets[i].nat_addr[0] << 24) | (sockets[i].nat_addr[1] << 16) |
(sockets[i].nat_addr[2] << 8) | sockets[i].nat_addr[3];
if (s_ip != link_sc1->nat_ip || sockets[i].nat_port != link_sc1->nat_port ||
sockets[i].type != NAT_VERIFIED_OPEN) {
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "FAIL: local_node socket not updated on C1: "
"s_ip=0x%08x nat_ip=0x%08x s_port=%u nat_port=%u s_type=%u expected=%u",
s_ip, link_sc1->nat_ip, sockets[i].port, link_sc1->nat_port,
s_ip, link_sc1->nat_ip, sockets[i].nat_port, link_sc1->nat_port,
sockets[i].type, NAT_VERIFIED_OPEN);
goto cleanup;
}
+10 -2
View File
@@ -267,8 +267,16 @@ int main(void) {
const struct NODEINFO_IPV4_SOCKET* sockets;
int sc = get_node_v4_sockets(nq, &sockets);
if (sc > 0) {
memcpy(&target_ip, sockets[0].addr, 4); /* network byte order */
target_port = sockets[0].port; /* уже в host order */
/* Используем NAT адрес если есть, иначе interface адрес */
uint32_t nat_ip = (sockets[0].nat_addr[0] << 24) | (sockets[0].nat_addr[1] << 16) |
(sockets[0].nat_addr[2] << 8) | sockets[0].nat_addr[3];
if (nat_ip != 0 && sockets[0].nat_port != 0) {
memcpy(&target_ip, sockets[0].nat_addr, 4); /* network byte order */
target_port = sockets[0].nat_port; /* уже в host order */
} else {
memcpy(&target_ip, sockets[0].addr, 4); /* network byte order */
target_port = sockets[0].port; /* уже в host order */
}
}
}
if (target_ip == 0 || target_port == 0) {