conn_mgr: fix all etcp_route_send calls (dgram was NULL) + improve error diagnostics
- conn_mgr.c: 5 call sites used queue_entry_new(data_size) with data[] instead of dgram — all etcp_route_send calls silently dropped. Fixed by switching to dgram-based allocation (queue_entry_new(0)+u_malloc) matching all other callers. - DIRCECT_REQ reuses already-allocated pkt as qe->dgram (no extra memcpy). - etcp_router.c:1078 — 'empty entry' now shows dgram=%p len=%u dst=0x... force=%d - etcp_connections.c:1139 — 'bad args' now shows all arg pointers to identify NULL - etcp_connections.c:1145 — 'no socket' now shows addr_family=%d - conn_mgr.c:633 — 'no candidates' now notes direct+reverse failed
This commit is contained in:
1 parent
2d93dd66c8
commit
e3b32cf4d3
3 files changed
+21
-15
No files matched your search
+15
-12
@@ -239,8 +239,8 @@ int conn_mgr_disconnect_node(struct CONN_MGR* mgr, uint64_t node_id) {
|
||||
pkt.cmd = ETCP_RT_ID_CONN_MGR;
|
||||
pkt.subcmd = CONN_MGR_SUBCMD_DISCONNECT;
|
||||
pkt.node_id = node_id;
|
||||
struct ll_entry* qe = queue_entry_new(sizeof(pkt));
|
||||
if (qe) { memcpy(qe->data, &pkt, sizeof(pkt)); etcp_route_send(mgr->instance, node_id, qe, 1); }
|
||||
struct ll_entry* qe = queue_entry_new(0);
|
||||
if (qe) { qe->dgram = u_malloc(sizeof(pkt)); memcpy(qe->dgram, &pkt, sizeof(pkt)); qe->len = sizeof(pkt); etcp_route_send(mgr->instance, node_id, qe, 1); }
|
||||
cm_clear_nodeinfo(mgr, node_id);
|
||||
cm_entry_destroy(entry);
|
||||
entry->state = CONN_MGR_STATE_DISCONNECTED;
|
||||
@@ -587,11 +587,10 @@ static void cm_start_phase_reverse(struct CONN_MGR_ENTRY* entry) {
|
||||
memcpy(p, &out_addrs[i].port, 2); p += 2;
|
||||
*p++ = out_addrs[i].socket_id;
|
||||
}
|
||||
struct ll_entry* qe = queue_entry_new(pkt_size);
|
||||
struct ll_entry* qe = queue_entry_new(0);
|
||||
if (!qe) { u_free(pkt); cm_deliver_result(entry, CONN_MGR_ERR_INTERNAL); return; }
|
||||
memcpy(qe->data, pkt, pkt_size);
|
||||
qe->dgram = pkt;
|
||||
qe->len = (uint16_t)pkt_size;
|
||||
u_free(pkt);
|
||||
etcp_route_send(entry->mgr->instance, entry->node_id, qe, 1);
|
||||
|
||||
struct cm_reverse_pending* rp = u_calloc(1, sizeof(struct cm_reverse_pending));
|
||||
@@ -630,7 +629,7 @@ static void cm_reverse_ready_cb(struct ETCP_CONN* conn, void* arg) {
|
||||
static int cm_start_phase_indirect(struct CONN_MGR_ENTRY* entry) {
|
||||
struct CONN_MGR* mgr = entry->mgr;
|
||||
if (mgr->best_candidate_count == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "conn_mgr: phase 3 (indirect) no candidates for 0x%016llx",
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_GENERAL, "conn_mgr: phase 3 (indirect) no candidates for 0x%016llx (direct+reverse failed)",
|
||||
(unsigned long long)entry->node_id);
|
||||
return CONN_MGR_ERR_UNREACHABLE;
|
||||
}
|
||||
@@ -645,9 +644,11 @@ static int cm_start_phase_indirect(struct CONN_MGR_ENTRY* entry) {
|
||||
req.candidate_count = mgr->best_candidate_count > 4 ? 4 : mgr->best_candidate_count;
|
||||
for (uint8_t i = 0; i < req.candidate_count; i++)
|
||||
req.candidates[i] = mgr->best_candidates[i];
|
||||
struct ll_entry* qe = queue_entry_new(sizeof(req));
|
||||
struct ll_entry* qe = queue_entry_new(0);
|
||||
if (!qe) return CONN_MGR_ERR_INTERNAL;
|
||||
memcpy(qe->data, &req, sizeof(req));
|
||||
qe->dgram = u_malloc(sizeof(req));
|
||||
memcpy(qe->dgram, &req, sizeof(req));
|
||||
qe->len = (uint16_t)sizeof(req);
|
||||
etcp_route_send(entry->mgr->instance, entry->node_id, qe, 1);
|
||||
entry->main.timer = uasync_set_timeout(mgr->instance->ua, CONN_MGR_INTERM_EXCHANGE_TIMEOUT_MS * 10,
|
||||
entry, cm_exchange_timeout_cb, "conn_mgr_interm_exch");
|
||||
@@ -715,8 +716,8 @@ static void cm_compute_intermediaries(struct CONN_MGR_ENTRY* entry, struct CONN_
|
||||
struct TOPO_NODEQ* nq = topo_node_find_by_id(topo_groups_get_default(entry->mgr->instance->topo_groups), all[i].node_id);
|
||||
if (nq) pkt.selected[i].rtt = cm_get_node_min_rtt(nq);
|
||||
}
|
||||
struct ll_entry* qe = queue_entry_new(sizeof(pkt));
|
||||
if (qe) { memcpy(qe->data, &pkt, sizeof(pkt)); etcp_route_send(entry->mgr->instance, entry->node_id, qe, 1); }
|
||||
struct ll_entry* qe = queue_entry_new(0);
|
||||
if (qe) { qe->dgram = u_malloc(sizeof(pkt)); memcpy(qe->dgram, &pkt, sizeof(pkt)); qe->len = sizeof(pkt); etcp_route_send(entry->mgr->instance, entry->node_id, qe, 1); }
|
||||
|
||||
entry->conn_type = CONN_TYPE_INDIRECT;
|
||||
entry->state = CONN_MGR_STATE_CONNECTED;
|
||||
@@ -894,9 +895,11 @@ static void cm_handle_interm_exchange_req(struct ETCP_CONN* conn,
|
||||
}
|
||||
size_t resp_size = offsetof(struct CONN_MGR_INTERM_EXCHANGE_RESP, your_candidates) +
|
||||
(size_t)resp.your_count * sizeof(struct CONN_MGR_CANDIDATE);
|
||||
struct ll_entry* qe = queue_entry_new(resp_size);
|
||||
struct ll_entry* qe = queue_entry_new(0);
|
||||
if (qe) {
|
||||
memcpy(qe->data, &resp, resp_size);
|
||||
qe->dgram = u_malloc(resp_size);
|
||||
memcpy(qe->dgram, &resp, resp_size);
|
||||
qe->len = (uint16_t)resp_size;
|
||||
etcp_route_send(mgr->instance, conn->peer_node_id, qe, 1);
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "conn_mgr: sent EXCHANGE_RESP to 0x%016llx my=%u your=%u",
|
||||
|
||||
@@ -1136,13 +1136,15 @@ int etcp_send_ping(struct UTUN_INSTANCE* instance, const uint8_t* peer_pubkey_bi
|
||||
etcp_ping_callback_t cb, void* user_arg,
|
||||
const uint8_t* user_data, size_t user_data_len) {
|
||||
if (!instance || !peer_pubkey_bin || !addr || timeout_ms <= 0 || !cb) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "bad args");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "bad args: inst=%p pubkey=%p addr=%p timeout=%d cb=%p udata=%p udata_len=%zu",
|
||||
(void*)instance, (void*)peer_pubkey_bin, (void*)addr, timeout_ms,
|
||||
(void*)(uintptr_t)cb, (void*)user_data, user_data_len);
|
||||
return -1;
|
||||
}
|
||||
struct ETCP_SOCKET* e_sock = instance->etcp_sockets;
|
||||
while (e_sock && e_sock->local_addr.ss_family != addr->ss_family) e_sock = e_sock->next;
|
||||
if (!e_sock) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "no socket");
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_BGP, "no socket for addr_family=%d", addr->ss_family);
|
||||
return -2;
|
||||
}
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_BGP, "ping N1 [%s]", sockaddr_storage_to_str(addr).str);
|
||||
|
||||
+2
-1
@@ -1075,7 +1075,8 @@ int etcp_route_send(struct UTUN_INSTANCE* inst, uint64_t dst_node_id, struct ll_
|
||||
if (entry) { queue_dgram_free(entry); queue_entry_free(entry); } return -1;
|
||||
}
|
||||
if (!entry->dgram || entry->len < 1) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "empty entry"); queue_dgram_free(entry); queue_entry_free(entry); return -1;
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCPROUTE, "empty entry: dgram=%p len=%u dst=0x%016llx force=%d",
|
||||
(void*)entry->dgram, entry->len, (unsigned long long)dst_node_id, force); queue_dgram_free(entry); queue_entry_free(entry); return -1;
|
||||
}
|
||||
uint8_t svc_id = entry->dgram[0];
|
||||
size_t payload_len = entry->len - 1;
|
||||
|
||||
Reference in new issue
Block a user