WIP: debug byte order diagnostics
This commit is contained in:
1 parent
6a971389b6
commit
77fd7c19de
21 files changed
+1389
-131
No files matched your search
@@ -0,0 +1,4 @@
|
||||
Minimal fix applied to test_etcp_two_instances.c (removed duplicate init_connections calls before utun_instance_init).
|
||||
Test should no longer hit 'Address already in use' on second bind.
|
||||
Full test run requires fixing Makefile.am dependencies or rebuilding all src objects.
|
||||
Run 'make check' after fixing build to verify.
|
||||
+13
-28
@@ -52,8 +52,6 @@ static struct {
|
||||
uint16_t avg_rtt;
|
||||
uint8_t count_sent;
|
||||
uint8_t count_ok;
|
||||
uint32_t recv_ip;
|
||||
uint16_t recv_port;
|
||||
} nat_ping_result;
|
||||
|
||||
static int write_config(const char* path, const char* content) {
|
||||
@@ -177,19 +175,15 @@ static void test_timeout_cb(void* arg) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "test_nat_detection: overall test timeout");
|
||||
}
|
||||
|
||||
static void nat_ping_resp_cb(int success, uint16_t avg_rtt, uint8_t count_sent, uint8_t count_ok,
|
||||
uint32_t recv_ip, uint16_t recv_port, void* arg) {
|
||||
static void nat_ping_resp_cb(int success, uint16_t avg_rtt, uint8_t count_sent, uint8_t count_ok, void* arg) {
|
||||
(void)arg;
|
||||
nat_ping_result.done = 1;
|
||||
nat_ping_result.success = success;
|
||||
nat_ping_result.avg_rtt = avg_rtt;
|
||||
nat_ping_result.count_sent = count_sent;
|
||||
nat_ping_result.count_ok = count_ok;
|
||||
nat_ping_result.recv_ip = recv_ip;
|
||||
nat_ping_result.recv_port = recv_port;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "nat_ping_resp_cb: success=%d avg_rtt=%u sent=%u ok=%u recv_ip=%08x recv_port=%u",
|
||||
success, (unsigned)avg_rtt, (unsigned)count_sent, (unsigned)count_ok,
|
||||
(unsigned)recv_ip, (unsigned)recv_port);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "nat_ping_resp_cb: success=%d avg_rtt=%u sent=%u ok=%u",
|
||||
success, (unsigned)avg_rtt, (unsigned)count_sent, (unsigned)count_ok);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@@ -218,6 +212,9 @@ int main(void) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// Разрешаем NAT check для localhost (для теста)
|
||||
if (inst_s->bgp) route_bgp_set_nat_check_local(inst_s->bgp, 1);
|
||||
|
||||
if (init_connections(inst_s) != 0 || init_connections(inst_c1) != 0 || init_connections(inst_c2) != 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "Failed to init connections");
|
||||
goto cleanup;
|
||||
@@ -421,7 +418,9 @@ int main(void) {
|
||||
}
|
||||
|
||||
memset(&nat_ping_result, 0, sizeof(nat_ping_result));
|
||||
int ret = route_ping_send_req_addr(inst_s->bgp, conn_sc2, NODE_ID_C1,
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "TEST: sending ping with pubkey, nat_ip=0x%08x nat_port=%u",
|
||||
link_sc1->nat_ip, link_sc1->nat_port);
|
||||
int ret = route_ping_send_req_addr(inst_s->bgp, conn_sc2,
|
||||
link_sc1->nat_ip, link_sc1->nat_port,
|
||||
3, 10, 200, 3000, nat_ping_resp_cb, NULL,
|
||||
node_c1->node.public_key);
|
||||
@@ -444,19 +443,7 @@ int main(void) {
|
||||
nat_ping_result.success, (unsigned)nat_ping_result.count_ok);
|
||||
goto cleanup;
|
||||
}
|
||||
if (nat_ping_result.recv_ip == 0 || nat_ping_result.recv_port == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "FAIL: STUN recv_ip/port zero (ip=%08x port=%u)",
|
||||
(unsigned)nat_ping_result.recv_ip, (unsigned)nat_ping_result.recv_port);
|
||||
goto cleanup;
|
||||
}
|
||||
// recv_ip should match C2's socket address (127.0.0.1)
|
||||
if (nat_ping_result.recv_ip != 0x7F000001) {
|
||||
DEBUG_WARN(DEBUG_CATEGORY_BGP, "STUN recv_ip=%08x (expected 127.0.0.1), tolerating",
|
||||
(unsigned)nat_ping_result.recv_ip);
|
||||
}
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "STUN check PASSED: recv_ip=%08x recv_port=%u",
|
||||
(unsigned)nat_ping_result.recv_ip, (unsigned)nat_ping_result.recv_port);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "STUN check PASSED");
|
||||
|
||||
// 7. Test route_ping_send_req_addr WITHOUT embedded pubkey (C2 should resolve pubkey from node_id)
|
||||
// First wait for C2 to learn C1's nodeinfo via BGP exchange from S
|
||||
@@ -477,7 +464,9 @@ int main(void) {
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Testing route ping without embedded pubkey...");
|
||||
memset(&nat_ping_result, 0, sizeof(nat_ping_result));
|
||||
ret = route_ping_send_req_addr(inst_s->bgp, conn_sc2, NODE_ID_C1,
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "TEST: sending ping NO pubkey, nat_ip=0x%08x nat_port=%u",
|
||||
link_sc1->nat_ip, link_sc1->nat_port);
|
||||
ret = route_ping_send_req_addr(inst_s->bgp, conn_sc2,
|
||||
link_sc1->nat_ip, link_sc1->nat_port,
|
||||
3, 10, 200, 3000, nat_ping_resp_cb, NULL,
|
||||
NULL);
|
||||
@@ -500,10 +489,6 @@ int main(void) {
|
||||
nat_ping_result.success, (unsigned)nat_ping_result.count_ok);
|
||||
goto cleanup;
|
||||
}
|
||||
if (nat_ping_result.recv_ip == 0 || nat_ping_result.recv_port == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "FAIL: no-pubkey ping STUN fields zero");
|
||||
goto cleanup;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "No-pubkey ping check PASSED");
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "NAT detection test PASSED");
|
||||
|
||||
+33
-15
@@ -177,17 +177,15 @@ static void test_timeout_cb(void* arg) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "test_route_ping: overall test timeout");
|
||||
}
|
||||
|
||||
static void ping_resp_cb(int success, uint16_t avg_rtt, uint8_t count_sent, uint8_t count_ok,
|
||||
uint32_t recv_ip, uint16_t recv_port, void* arg) {
|
||||
(void)arg; (void)recv_ip; (void)recv_port;
|
||||
static void ping_resp_cb(int success, uint16_t avg_rtt, uint8_t count_sent, uint8_t count_ok, void* arg) {
|
||||
(void)arg;
|
||||
ping_result.done = 1;
|
||||
ping_result.success = success;
|
||||
ping_result.avg_rtt = avg_rtt;
|
||||
ping_result.count_sent = count_sent;
|
||||
ping_result.count_ok = count_ok;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "ping_resp_cb: success=%d avg_rtt=%u sent=%u ok=%u recv_ip=%08x recv_port=%u",
|
||||
success, (unsigned)avg_rtt, (unsigned)count_sent, (unsigned)count_ok,
|
||||
(unsigned)recv_ip, (unsigned)recv_port);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "ping_resp_cb: success=%d avg_rtt=%u sent=%u ok=%u",
|
||||
success, (unsigned)avg_rtt, (unsigned)count_sent, (unsigned)count_ok);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
@@ -253,22 +251,42 @@ int main(void) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
// 3. Send route ping request from A to B for node C
|
||||
// 3. Get target info for C and send route ping request from A to B
|
||||
struct ETCP_CONN* conn_ab = find_conn_to_peer(inst_a, NODE_ID_B);
|
||||
if (!conn_ab) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "A has no connection to B");
|
||||
goto cleanup;
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending route ping request A->B for C");
|
||||
|
||||
/* Получаем target IP:port из nodeinfo узла C */
|
||||
uint32_t target_ip = 0;
|
||||
uint16_t target_port = 0;
|
||||
struct NODEINFO_Q* nq = inst_b->bgp ? route_bgp_get_node(inst_b->bgp, NODE_ID_C) : NULL;
|
||||
if (nq) {
|
||||
const struct NODEINFO_IPV4_SOCKET* sockets;
|
||||
int sc = get_node_v4_sockets(nq, &sockets);
|
||||
if (sc > 0) {
|
||||
memcpy(&target_ip, sockets[0].addr, 4);
|
||||
target_port = sockets[0].port;
|
||||
}
|
||||
}
|
||||
if (target_ip == 0 || target_port == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "Cannot resolve target for node C");
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_BGP, "Sending route ping request A->B for C (%s:%u)",
|
||||
ip_to_str(&target_ip, AF_INET).str, (unsigned)target_port);
|
||||
memset(&ping_result, 0, sizeof(ping_result));
|
||||
int ret = route_ping_send_req(inst_a->bgp, conn_ab, NODE_ID_C,
|
||||
3, // count
|
||||
10, // interval_ms
|
||||
200, // timeout_ms
|
||||
5000,// wait_timeout_ms
|
||||
ping_resp_cb, NULL);
|
||||
int ret = route_ping_send_req_addr(inst_a->bgp, conn_ab, target_ip, target_port,
|
||||
3, // count
|
||||
10, // interval_ms
|
||||
200, // timeout_ms
|
||||
5000,// wait_timeout_ms
|
||||
ping_resp_cb, NULL,
|
||||
nq ? nq->node.public_key : NULL);
|
||||
if (ret != 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "route_ping_send_req failed: %d", ret);
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "route_ping_send_req_addr failed: %d", ret);
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user