encrypt overhead fix (33→36, noencrypt_len), mtu default 1280, connmonitor window, total_decrypted for TCP, check.sh
This commit is contained in:
1 parent
9846599086
commit
ca176e1f24
41 files changed
+643
-91
No files matched your search
@@ -103,6 +103,12 @@ int chat_core_update_local_attrs(const char* ch_id, uint64_t ts,
|
||||
/* Сбор статуса (NTP + connections) и отправка в GUI */
|
||||
void chat_core_collect_status_trampoline(void* arg);
|
||||
|
||||
/* Сбор списка ETCP-соединений и отправка в GUI (binary packet) */
|
||||
void chat_core_collect_conn_list_trampoline(void* arg);
|
||||
|
||||
/* Сбор полных метрик одного соединения (arg = u_malloc uint64_t peer_node_id) */
|
||||
void chat_core_collect_conn_metrics_trampoline(void* arg);
|
||||
|
||||
/* ── Headless CLI API ── */
|
||||
|
||||
/** Вариант для сборки без UTUN_INSTANCE (использует sqlite3* и node_id) */
|
||||
|
||||
@@ -33,8 +33,10 @@ void chat_event_post(int type, const uint8_t* data, int len) {
|
||||
[12]="SERVICE_STARTED", [13]="SERVICE_STOPPED",
|
||||
[14]="ATTACHMENT_DOWNLOADED", [15]="DOWNLOAD_PROGRESS",
|
||||
[16]="NODEINFO_UPDATED", [17]="LINK_STATUS_CHANGED",
|
||||
[18]="INVITE_RECEIVED", [19]="LOCAL_SOCKETS",
|
||||
[20]="CONN_LIST", [21]="CONN_METRICS",
|
||||
};
|
||||
const char* n = (type >= 1 && type <= 17) ? names[type] : "?";
|
||||
const char* n = (type >= 1 && type <= 21) ? names[type] : "?";
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "chat_event: %s(%d) data=%d bytes", n, type, len);
|
||||
if (data && len > 0) log_dump(DEBUG_LEVEL_DEBUG, DEBUG_CATEGORY_DEBUG, " ", data, len);
|
||||
}
|
||||
@@ -38,6 +38,8 @@ extern "C" {
|
||||
#define CHAT_EVT_LINK_STATUS_CHANGED 17 /* [peer_id:8][link_id:1][state:1][status:1][links_up:1][initialized:1] */
|
||||
#define CHAT_EVT_INVITE_RECEIVED 18 /* [ch_id_len:1][ch_id][name_len:1][name][inviter_node_id:8][inviter_name_len:1][inviter_name] */
|
||||
#define CHAT_EVT_LOCAL_SOCKETS 19 /* JSON: [{"si":id,"nm":"...","ad":"...","po":port,"pt":"TCP|UDP","st":0|1|2,"lk":n},...] */
|
||||
#define CHAT_EVT_CONN_LIST 20 /* [count:2][entry:46B]* — список ETCP-соединений */
|
||||
#define CHAT_EVT_CONN_METRICS 21 /* текст — полный дамп метрик выбранного соединения */
|
||||
|
||||
typedef void (*chat_event_handler_fn)(int type, const uint8_t* data, int len);
|
||||
|
||||
|
||||
@@ -10,9 +10,11 @@
|
||||
#include "../utun_instance.h"
|
||||
#include "../ntp_time.h"
|
||||
#include "../../lib/ll_queue.h"
|
||||
#include "../../lib/mem.h"
|
||||
#include "../../lib/platform_compat.h"
|
||||
#include "../transport_layer/etcp.h"
|
||||
#include "../transport_layer/etcp_connections.h"
|
||||
#include "../transport_layer/pkt_normalizer.h"
|
||||
|
||||
static const char* nat_type_str(uint8_t t) {
|
||||
switch (t) { case 0: return "UNKNOWN"; case 1: return "EIM"; case 2: return "STRICT"; case 3: return "DIRECT"; default: return "?"; }
|
||||
@@ -112,7 +114,177 @@ static void chat_core_collect_status(void) {
|
||||
chat_event_post(CHAT_EVT_STATUS_REFRESH, (const uint8_t*)buf, off);
|
||||
}
|
||||
|
||||
/* ── Бинарный список соединений: [count:2][entry:46B]* ── */
|
||||
/* entry: peer_node_id:8 flags:1 link_count:1 rtt:2 inflight_kb:2 name:32 */
|
||||
#define CONN_LIST_ENTRY_SIZE 46
|
||||
|
||||
static void collect_conn_list(void) {
|
||||
if (!g_cc.initialized || !g_cc.inst || !g_cc.inst->connections) return;
|
||||
|
||||
uint16_t count = 0;
|
||||
struct ll_entry* entry = g_cc.inst->connections->head;
|
||||
while (entry) { count++; entry = entry->next; }
|
||||
if (count > 250) count = 250;
|
||||
|
||||
size_t buf_sz = 2 + (size_t)count * CONN_LIST_ENTRY_SIZE;
|
||||
uint8_t* buf = (uint8_t*)u_malloc(buf_sz);
|
||||
if (!buf) return;
|
||||
|
||||
uint16_t* hdr = (uint16_t*)buf;
|
||||
*hdr = count;
|
||||
uint8_t* p = buf + 2;
|
||||
|
||||
entry = g_cc.inst->connections->head;
|
||||
for (uint16_t i = 0; i < count && entry; i++, entry = entry->next) {
|
||||
struct conn_queue_entry* ce = (struct conn_queue_entry*)entry->data;
|
||||
if (!ce || !ce->conn) { memset(p, 0, CONN_LIST_ENTRY_SIZE); p += CONN_LIST_ENTRY_SIZE; continue; }
|
||||
struct ETCP_CONN* conn = ce->conn;
|
||||
|
||||
memcpy(p, &ce->peer_node_id, 8); p += 8;
|
||||
|
||||
uint8_t flags = 0;
|
||||
if (conn->links_up) flags |= 1;
|
||||
if (conn->initialized) flags |= 2;
|
||||
*p++ = flags;
|
||||
|
||||
uint8_t lc = 0;
|
||||
struct ETCP_LINK* tl = conn->links; while (tl) { lc++; tl = tl->next; }
|
||||
*p++ = lc;
|
||||
|
||||
uint16_t rtt = 0;
|
||||
if (conn->links) rtt = conn->links->rtt_last;
|
||||
memcpy(p, &rtt, 2); p += 2;
|
||||
|
||||
uint16_t inflight_kb = (uint16_t)(conn->unacked_bytes / 1024);
|
||||
memcpy(p, &inflight_kb, 2); p += 2;
|
||||
|
||||
char name[32]; memset(name, 0, 32);
|
||||
get_node_name(ce->peer_node_id, name, 31);
|
||||
if (!name[0]) snprintf(name, 32, "%016llX", (unsigned long long)ce->peer_node_id);
|
||||
memcpy(p, name, 32); p += 32;
|
||||
}
|
||||
|
||||
chat_event_post(CHAT_EVT_CONN_LIST, buf, (int)buf_sz);
|
||||
u_free(buf);
|
||||
}
|
||||
|
||||
/* ── Полный текстовый дамп одного соединения ── */
|
||||
static void collect_conn_metrics(uint64_t peer_node_id) {
|
||||
char buf[8192]; int off = 0;
|
||||
|
||||
if (!g_cc.initialized || !g_cc.inst || !g_cc.inst->connections) {
|
||||
off = snprintf(buf, sizeof(buf), "uTun not initialized\n");
|
||||
chat_event_post(CHAT_EVT_CONN_METRICS, (const uint8_t*)buf, off);
|
||||
return;
|
||||
}
|
||||
|
||||
struct ll_entry* e = queue_find_data_by_index(g_cc.inst->connections, (const uint8_t*)&peer_node_id);
|
||||
if (!e) {
|
||||
off = snprintf(buf, sizeof(buf), "Connection %016llX not found\n", (unsigned long long)peer_node_id);
|
||||
chat_event_post(CHAT_EVT_CONN_METRICS, (const uint8_t*)buf, off);
|
||||
return;
|
||||
}
|
||||
struct conn_queue_entry* ce = (struct conn_queue_entry*)e->data;
|
||||
if (!ce || !ce->conn) {
|
||||
off = snprintf(buf, sizeof(buf), "Connection %016llX has null data\n", (unsigned long long)peer_node_id);
|
||||
chat_event_post(CHAT_EVT_CONN_METRICS, (const uint8_t*)buf, off);
|
||||
return;
|
||||
}
|
||||
struct ETCP_CONN* conn = ce->conn;
|
||||
uint64_t my_id = g_cc.inst->node_id;
|
||||
|
||||
char peername[64]; get_node_name(peer_node_id, peername, sizeof(peername));
|
||||
if (!peername[0]) snprintf(peername, sizeof(peername), "%016llX", (unsigned long long)peer_node_id);
|
||||
|
||||
/* Count links */
|
||||
int link_count = 0, links_up_count = 0;
|
||||
struct ETCP_LINK* tl = conn->links; while (tl) { if (tl->link_status) links_up_count++; link_count++; tl = tl->next; }
|
||||
|
||||
off += snprintf(buf + off, sizeof(buf) - off,
|
||||
"=== PEER: %04llX\u2192%04llX [%s] ===\n"
|
||||
"Status: %s Links: %d/%d Initialized: %s Session: 0x%X MTU: %d\n"
|
||||
"Reinit: %u Reset: %u Tx_state: %d Routing_exchange: %d\n"
|
||||
"\n--- ETCP ---\n"
|
||||
"RTT last/avg10: %.1f/%.1f ms Jitter: %.1f ms\n"
|
||||
"Bytes sent: %u Retrans: %u ACKs: %u\n"
|
||||
"Unacked bytes: %u Max inflight: %u\n"
|
||||
"RX dup: %u TX dup: %u\n"
|
||||
"IDs: next_tx=%u last_rx=%u last_del=%u rx_ack_till=%u\n"
|
||||
"\n--- Queues ---\n",
|
||||
(unsigned long long)(my_id & 0xFFFF), (unsigned long long)(peer_node_id & 0xFFFF), peername,
|
||||
conn->links_up ? "UP" : "DOWN", links_up_count, link_count,
|
||||
conn->initialized ? "yes" : "no", conn->session_id, conn->mtu,
|
||||
conn->reinit_count, conn->reset_count, conn->tx_state, conn->routing_exchange_active,
|
||||
conn->rtt_last / 10.0f, conn->rtt_avg_10 / 10.0f, conn->jitter / 10.0f,
|
||||
conn->bytes_sent_total, conn->retransmissions_count, conn->ack_packets_count,
|
||||
conn->unacked_bytes, conn->max_inflight,
|
||||
conn->rx_dup_count, conn->tx_dup_count,
|
||||
conn->next_tx_id, conn->last_rx_id, conn->last_delivered_id, conn->rx_ack_till);
|
||||
|
||||
if (conn->input_queue) off += snprintf(buf + off, sizeof(buf) - off, "input_q: %uB/%dp ", (unsigned)queue_total_bytes(conn->input_queue), queue_entry_count(conn->input_queue));
|
||||
if (conn->input_send_q) off += snprintf(buf + off, sizeof(buf) - off, "send_q: %uB/%dp ", (unsigned)queue_total_bytes(conn->input_send_q), queue_entry_count(conn->input_send_q));
|
||||
if (conn->input_wait_ack) off += snprintf(buf + off, sizeof(buf) - off, "wait_ack: %uB/%dp\n", (unsigned)queue_total_bytes(conn->input_wait_ack), queue_entry_count(conn->input_wait_ack));
|
||||
if (conn->ack_q) off += snprintf(buf + off, sizeof(buf) - off, "ack_q: %uB/%dp ", (unsigned)queue_total_bytes(conn->ack_q), queue_entry_count(conn->ack_q));
|
||||
if (conn->recv_q) off += snprintf(buf + off, sizeof(buf) - off, "recv_q: %uB/%dp ", (unsigned)queue_total_bytes(conn->recv_q), queue_entry_count(conn->recv_q));
|
||||
if (conn->output_queue) off += snprintf(buf + off, sizeof(buf) - off, "out_q: %uB/%dp\n", (unsigned)queue_total_bytes(conn->output_queue), queue_entry_count(conn->output_queue));
|
||||
|
||||
off += snprintf(buf + off, sizeof(buf) - off, "\n--- ACK Debug ---\n"
|
||||
"hit_inf=%u hit_sndq=%u miss=%u link_wait=%u\n",
|
||||
conn->cnt_ack_hit_inf, conn->cnt_ack_hit_sndq, conn->cnt_ack_miss, conn->cnt_link_wait);
|
||||
|
||||
/* Normalizer */
|
||||
if (conn->normalizer) {
|
||||
struct PKTNORM* pn = conn->normalizer;
|
||||
off += snprintf(buf + off, sizeof(buf) - off,
|
||||
"\n--- Normalizer ---\n"
|
||||
"in: %llu pkts / %llu B out: %llu pkts / %llu B\n"
|
||||
"frag_size=%u data_ptr=%u data_size=%u alloc_err=%u logic_err=%u\n",
|
||||
(unsigned long long)pn->in_total_pkts, (unsigned long long)pn->in_total_bytes,
|
||||
(unsigned long long)pn->out_total_pkts, (unsigned long long)pn->out_total_bytes,
|
||||
pn->frag_size, pn->data_ptr, pn->data_size, pn->alloc_errors, pn->logic_errors);
|
||||
}
|
||||
|
||||
/* Links */
|
||||
int link_idx = 0;
|
||||
struct ETCP_LINK* link = conn->links;
|
||||
while (link) {
|
||||
const char* is_tcp_str = link->is_tcp ? "TCP" : "UDP";
|
||||
char local_str[54], remote_str[54];
|
||||
strncpy(local_str, link->conn ? sockaddr_storage_to_str(&link->conn->local_addr).str : "stcp", sizeof(local_str) - 1);
|
||||
strncpy(remote_str, sockaddr_storage_to_str(&link->remote_addr).str, sizeof(remote_str) - 1);
|
||||
off += snprintf(buf + off, sizeof(buf) - off,
|
||||
"\n--- LINK#%d: %s %s NAT=%s ---\n"
|
||||
"addr: %s -> %s\n"
|
||||
"RTT: %.1f ms TT: %.1f ms\n"
|
||||
"Keepalive: sent=%u recv=%u period=%ums\n"
|
||||
"Inflight: %u / %u B (%u pkts)\n"
|
||||
"Encrypt: sent=%zu err=%zu Decrypt: rcvd=%zu err=%zu\n",
|
||||
link_idx, link->link_status ? "UP" : "DOWN", is_tcp_str, nat_type_str(link->nat_type),
|
||||
local_str, remote_str,
|
||||
link->rtt_last / 10.0f, link->tt_last / 10.0f,
|
||||
link->keepalive_sent_count, link->keepalive_recv_count, link->keepalive_interval,
|
||||
link->inflight_bytes, link->inflight_lim_bytes, link->inflight_packets,
|
||||
link->total_encrypted, link->encrypt_errors, link->total_decrypted, link->decrypt_errors);
|
||||
|
||||
link = link->next; link_idx++;
|
||||
}
|
||||
|
||||
chat_event_post(CHAT_EVT_CONN_METRICS, (const uint8_t*)buf, off);
|
||||
}
|
||||
|
||||
void chat_core_collect_status_trampoline(void* arg) {
|
||||
(void)arg;
|
||||
chat_core_collect_status();
|
||||
}
|
||||
|
||||
void chat_core_collect_conn_list_trampoline(void* arg) {
|
||||
(void)arg;
|
||||
collect_conn_list();
|
||||
}
|
||||
|
||||
void chat_core_collect_conn_metrics_trampoline(void* arg) {
|
||||
uint64_t peer_id;
|
||||
memcpy(&peer_id, arg, sizeof(peer_id));
|
||||
u_free(arg);
|
||||
collect_conn_metrics(peer_id);
|
||||
}
|
||||
+3
-1
@@ -846,7 +846,8 @@ static struct utun_config* parse_config_internal(FILE *fp, const char *filename)
|
||||
|
||||
// Set default values
|
||||
cfg->global.name[0] = '\0';
|
||||
cfg->global.keepalive_timeout = 2000; // Default 2 seconds
|
||||
cfg->global.mtu = 1280; // Default MTU: safe for IPv6 tunnels
|
||||
cfg->global.keepalive_timeout = 2000; // Default 2 seconds
|
||||
cfg->global.keepalive_interval = 200; // Default 0.2 s
|
||||
cfg->global.keepalive_adaptive = 1; // Default: adaptive enabled
|
||||
cfg->global.bbr_max_cwnd = 1048576; // Default 1MB (was INFLIGHT_LIM_MAX)
|
||||
@@ -1131,6 +1132,7 @@ struct utun_config* parse_config_from_buf(const char *buf, size_t len, const cha
|
||||
struct utun_config *cfg = u_calloc(1, sizeof(struct utun_config));
|
||||
if (!cfg) { DEBUG_ERROR(DEBUG_CATEGORY_SYS, "failed to allocate memory for config structure"); return NULL; }
|
||||
cfg->global.name[0] = '\0';
|
||||
cfg->global.mtu = 1280;
|
||||
cfg->global.keepalive_timeout = 2000;
|
||||
cfg->global.keepalive_interval = 200;
|
||||
cfg->global.keepalive_adaptive = 1;
|
||||
|
||||
@@ -510,7 +510,7 @@ void topo_group_remove_conn(struct TOPO_GROUP* group, struct ETCP_CONN* conn) {
|
||||
struct ETCP_CONN* topo_group_find_conn_for_node(struct TOPO_GROUP* group, uint64_t node_id) {
|
||||
if (!group) return NULL;
|
||||
struct TOPO_GROUP_NODE* nq = topo_node_find_by_id(group, node_id);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_DEBUG, "find_conn_for_node %016llx: nq=%p paths=%p head=%p",
|
||||
DEBUG_TRACE(DEBUG_CATEGORY_DEBUG, "find_conn_for_node %016llx: nq=%p paths=%p head=%p",
|
||||
(unsigned long long)node_id, (void*)nq, nq ? (void*)nq->paths : NULL, (nq && nq->paths) ? (void*)nq->paths->head : NULL);
|
||||
if (!nq || !nq->paths || !nq->paths->head) return NULL;
|
||||
struct ll_entry* e = nq->paths->head;
|
||||
|
||||
@@ -204,7 +204,7 @@ static int create_iface_udp_socket(struct AUTO_SOCKET* as, uint32_t ifindex, con
|
||||
server.type = type;
|
||||
server.netif_index = ifindex;
|
||||
server.transport = 0;
|
||||
server.mtu = inst->config ? inst->config->global.mtu : 1500;
|
||||
server.mtu = inst->config ? inst->config->global.mtu : 1280;
|
||||
|
||||
if (family == AF_INET) {
|
||||
struct sockaddr_in* sin = (struct sockaddr_in*)&server.ip;
|
||||
|
||||
@@ -1832,7 +1832,12 @@ void etcp_update_mtu(struct ETCP_CONN* etcp) {
|
||||
if (!has_links) new_mtu = ETCP_RFC791_MIN_MTU;
|
||||
if (new_mtu != etcp->mtu) {
|
||||
etcp->mtu = new_mtu;
|
||||
if (etcp->normalizer) etcp->normalizer->frag_size = etcp->mtu - ACK_REZERV - UDP_HDR_SIZE - UDP_SC_HDR_SIZE;
|
||||
if (etcp->normalizer) {
|
||||
int max_udp = IP_UDP_OVERHEAD_V4;
|
||||
for (struct ETCP_LINK* l = etcp->links; l; l = l->next)
|
||||
if (l->remote_addr.ss_family == AF_INET6) max_udp = IP_UDP_OVERHEAD_V6;
|
||||
etcp->normalizer->frag_size = etcp->mtu - ACK_REZERV - max_udp - UDP_SC_HDR_SIZE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -924,7 +924,7 @@ struct ETCP_LINK* etcp_link_new(struct ETCP_CONN* etcp, struct ETCP_SOCKET* conn
|
||||
int mtu;
|
||||
mtu = conn ? conn->mtu : STCP_MAX_MSG_SIZE;
|
||||
if (is_tcp) { mtu = STCP_MAX_MSG_SIZE; link->mtu_local = mtu; link->mtu = mtu; link->inflight_lim_bytes = mtu * 4; link->handshake_minsize = 100; link->handshake_maxsize = mtu; }
|
||||
else { if (mtu == 0) mtu = 1500; if (mtu > PACKET_DATA_MAX_MTU) mtu = PACKET_DATA_MAX_MTU; link->mtu_local = mtu; link->mtu = mtu; link->inflight_lim_bytes = mtu * 4; link->handshake_minsize = 100; link->handshake_maxsize = mtu; }
|
||||
else { if (mtu == 0) mtu = 1280; if (mtu > PACKET_DATA_MAX_MTU) mtu = PACKET_DATA_MAX_MTU; link->mtu_local = mtu; link->mtu = mtu; link->inflight_lim_bytes = mtu * 4; link->handshake_minsize = 100; link->handshake_maxsize = mtu; }
|
||||
/* mtu init moved above */
|
||||
etcp_update_mtu(etcp);
|
||||
link->initialized = 0;
|
||||
@@ -1155,6 +1155,7 @@ static int etcp_tcp_send(struct ETCP_DGRAM* dgram) {
|
||||
if (link->send_hook) rc = (int)link->send_hook(0, dgram->data, dgram->data_len, NULL, 0, link, link->send_hook_ctx);
|
||||
else if (link->tcp_link) rc = stcp_link_send(link->tcp_link, dgram->data, dgram->data_len) == 0 ? (int)dgram->data_len : -1;
|
||||
else rc = -1;
|
||||
if (rc > 0) link->total_encrypted += (size_t)rc;
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_ETCP, "[%s] TCP send: link=%d dlen=%d rc=%d via=%s",
|
||||
link->etcp->log_name, link->local_link_id, dgram->data_len, rc,
|
||||
link->send_hook ? "hook" : (link->tcp_link ? "stcp" : "NONE"));
|
||||
@@ -1182,9 +1183,10 @@ int etcp_encrypt_send(struct ETCP_DGRAM* dgram) {
|
||||
// Размер зашифрованной части не должен превышать UDP payload = MTU - заголовки
|
||||
int errcode=0;
|
||||
sc_context_t* sc = &dgram->link->etcp->crypto_ctx;
|
||||
int len=dgram->data_len-dgram->noencrypt_len;// не забываем добавить timestamp (2 bytes)
|
||||
int wire_ov = WIRE_OVERHEAD(dgram->link->remote_addr.ss_family);
|
||||
if (len<0 || len>dgram->link->mtu - wire_ov) { dgram->link->send_errors++; errcode=1; goto es_err; }
|
||||
int len=dgram->data_len-dgram->noencrypt_len;
|
||||
int udp_ov = (dgram->link->remote_addr.ss_family == AF_INET6) ? IP_UDP_OVERHEAD_V6 : IP_UDP_OVERHEAD_V4;
|
||||
int wire_ov = udp_ov + SC_ENCRYPT_OVERHEAD;
|
||||
if (len<0 || len + (int)dgram->noencrypt_len > (int)(dgram->link->mtu - wire_ov)) { dgram->link->send_errors++; errcode=1; goto es_err; }
|
||||
uint8_t enc_buf[1600];
|
||||
size_t enc_buf_len=0;
|
||||
dgram->timestamp=get_current_timestamp();
|
||||
@@ -1195,8 +1197,8 @@ int etcp_encrypt_send(struct ETCP_DGRAM* dgram) {
|
||||
if (enc_buf_len == 0) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "eencryption failed for node %016llx", (unsigned long long)dgram->link->etcp->instance->node_id);
|
||||
dgram->link->send_errors++; errcode=2; goto es_err; }
|
||||
if (enc_buf_len + dgram->noencrypt_len > (size_t)(dgram->link->mtu - UDP_HDR_SIZE)) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "packet too long len=%d ne_len=%d", enc_buf_len, dgram->noencrypt_len);
|
||||
if (enc_buf_len + dgram->noencrypt_len > (size_t)(dgram->link->mtu - udp_ov)) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "packet too long enc=%zu ne=%d mtu=%d", enc_buf_len, dgram->noencrypt_len, dgram->link->mtu);
|
||||
dgram->link->send_errors++; errcode=3; goto es_err; }
|
||||
memcpy(enc_buf+enc_buf_len, dgram->data+len, dgram->noencrypt_len);
|
||||
|
||||
@@ -1229,7 +1231,7 @@ static int etcp_send_ping_raw(struct ETCP_DGRAM* dgram, socket_t fd, sc_context_
|
||||
return -1;
|
||||
}
|
||||
int len = dgram->data_len - dgram->noencrypt_len;
|
||||
if (len < 0 || len > PACKET_DATA_SIZE - UDP_HDR_SIZE) {
|
||||
if (len < 0 || len > PACKET_DATA_SIZE - IP_UDP_OVERHEAD_V4) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "ping packet data invalid len=%d", len);
|
||||
return -1;
|
||||
}
|
||||
@@ -1242,7 +1244,7 @@ static int etcp_send_ping_raw(struct ETCP_DGRAM* dgram, socket_t fd, sc_context_
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "encryption failed for ping");
|
||||
return -1;
|
||||
}
|
||||
if (enc_buf_len + dgram->noencrypt_len > (size_t)(PACKET_DATA_SIZE - UDP_HDR_SIZE)) {
|
||||
if (enc_buf_len + dgram->noencrypt_len > (size_t)(PACKET_DATA_SIZE - IP_UDP_OVERHEAD_V4)) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "ping packet too long enc=%zu ne=%d", enc_buf_len, dgram->noencrypt_len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -16,12 +16,11 @@ extern "C" {
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#define UDP_HDR_SIZE 28// размер udp header + ethernet заголовков (ipv4) [для ipv6 = 48 байт]
|
||||
#define UDP_SC_HDR_SIZE (13+8+4 + 5)// 13+8+4 - sc_nonce+tag size+crc, 5 - payload hdr
|
||||
#define ACK_REZERV 100// сколько байт резервировать под ack и прочие заголовки
|
||||
#define SC_ENCRYPT_OVERHEAD (3 + SC_TAG_SIZE) // timestamp(2)+flag_up(1)+AES-CCM tag(16) — поверх plaintext
|
||||
#define IP_UDP_OVERHEAD_V4 (20 + 8) // IP(20)+UDP(8)
|
||||
#define IP_UDP_OVERHEAD_V6 (40 + 8) // IP(40)+UDP(8)
|
||||
#define SC_ENCRYPT_OVERHEAD (ETCP_ENCRYPTED_HDR_SIZE + SC_NONCE_SIZE + SC_CRC32_SIZE + SC_TAG_SIZE) // 3+13+4+16=36
|
||||
#define UDP_SC_HDR_SIZE (SC_NONCE_SIZE + SC_TAG_SIZE + SC_CRC32_SIZE + 5) // 13+16+4+5=38 — sc overhead без ETCP_HDR + etcp framing
|
||||
#define ACK_REZERV 100// сколько байт резервировать под ack и прочие заголовки
|
||||
#define WIRE_OVERHEAD(fam) ((fam) == AF_INET6 ? IP_UDP_OVERHEAD_V6 + SC_ENCRYPT_OVERHEAD : IP_UDP_OVERHEAD_V4 + SC_ENCRYPT_OVERHEAD)
|
||||
|
||||
#define INFLIGHT_LIM_MIN 8192 // 8K
|
||||
|
||||
@@ -885,7 +885,7 @@ void node_conn_direct_force_close(struct NODE_CONN_DIRECT* h) {
|
||||
h->entry = NULL; u_free(h); return;
|
||||
}
|
||||
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close node=0x%016llx remaining=%d",
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close node=0x%016llx remaining=%d",
|
||||
(unsigned long long)node_id, entry->handle_count);
|
||||
|
||||
if (entry->handle_count == 0) {
|
||||
@@ -898,28 +898,28 @@ void node_conn_direct_force_close(struct NODE_CONN_DIRECT* h) {
|
||||
if (entry->connect_timer) { uasync_cancel_timeout(entry->ua, entry->connect_timer); entry->connect_timer = NULL; }
|
||||
if (entry->fin_wait_timer) { uasync_cancel_timeout(entry->ua, entry->fin_wait_timer); entry->fin_wait_timer = NULL; }
|
||||
if (conn && conn->state != 2 && conn->instance) {
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: cleaning conn=%p", conn);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: cleaning conn=%p", conn);
|
||||
conn->fin_wait = 0;
|
||||
conn->fin_wait_clear_cb = NULL; conn->fin_wait_clear_arg = NULL;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing ncd_init_cb");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing ncd_init_cb");
|
||||
etcp_conn_remove_cbk(conn, ncd_init_cb, entry);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing ncd_up_cb");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing ncd_up_cb");
|
||||
etcp_conn_remove_cbk(conn, ncd_up_cb, entry);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing ncd_down_cb");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing ncd_down_cb");
|
||||
etcp_conn_remove_cbk(conn, ncd_down_cb, entry);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: scheduling deferred close");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: scheduling deferred close");
|
||||
if (conn->state != 2) uasync_call_soon(entry->ua, conn, ncd_deferred_close_conn);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing from registry");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: removing from registry");
|
||||
ncd_registry_remove(conn->instance, entry);
|
||||
}
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: freeing entry=%p", entry);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: freeing entry=%p", entry);
|
||||
u_free(entry);
|
||||
}
|
||||
|
||||
h->entry = NULL;
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: freeing h=%p", h);
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: freeing h=%p", h);
|
||||
u_free(h);
|
||||
DEBUG_INFO(DEBUG_CATEGORY_NCD, "[ncd] force_close: done");
|
||||
DEBUG_DEBUG(DEBUG_CATEGORY_NCD, "[ncd] force_close: done");
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -39,8 +39,11 @@ struct PKTNORM* pn_init(struct ETCP_CONN* etcp) {
|
||||
|
||||
pn->etcp = etcp;
|
||||
pn->ua = etcp->instance->ua;
|
||||
pn->frag_size = etcp->mtu - ACK_REZERV - UDP_HDR_SIZE - UDP_SC_HDR_SIZE;
|
||||
int min_frag = UDP_HDR_SIZE + UDP_SC_HDR_SIZE + ACK_REZERV;
|
||||
int max_udp = IP_UDP_OVERHEAD_V4;
|
||||
for (struct ETCP_LINK* l = etcp->links; l; l = l->next)
|
||||
if (l->remote_addr.ss_family == AF_INET6) max_udp = IP_UDP_OVERHEAD_V6;
|
||||
pn->frag_size = etcp->mtu - ACK_REZERV - max_udp - UDP_SC_HDR_SIZE;
|
||||
int min_frag = max_udp + UDP_SC_HDR_SIZE + ACK_REZERV;
|
||||
if (etcp->mtu < min_frag || pn->frag_size > etcp->mtu) {
|
||||
DEBUG_ERROR(DEBUG_CATEGORY_ETCP, "MTU %d too small (min %d)", etcp->mtu, min_frag);
|
||||
pn->frag_size = etcp->mtu;
|
||||
|
||||
@@ -54,6 +54,7 @@ static void link_rx_cb(struct ll_queue *q, void *arg) {
|
||||
struct ETCP_LINK *l = link->etcp_link;
|
||||
if (e->len >= 3) { uint16_t pp = e->dgram[1] | ((uint16_t)e->dgram[2] << 8); l->keepalive_timeout = (uint32_t)pp * KA_TIMEOUT_MULT; }
|
||||
l->recv_keepalive = 1; l->remote_keepalive = 1; l->link_status = 1; l->keepalive_recv_count++;
|
||||
l->total_decrypted += e->len;
|
||||
l->last_recv_local_time = get_time_tb();
|
||||
queue_dgram_free(e); queue_entry_free(e);
|
||||
} else {
|
||||
@@ -62,6 +63,7 @@ static void link_rx_cb(struct ll_queue *q, void *arg) {
|
||||
if (pkt) {
|
||||
pkt->link = link->etcp_link; pkt->data_len = (uint16_t)e->len; pkt->noencrypt_len = 0;
|
||||
if (e->len > 0) memcpy(pkt->data, e->dgram, e->len);
|
||||
link->etcp_link->total_decrypted += e->len;
|
||||
etcp_conn_input(pkt);
|
||||
}
|
||||
queue_dgram_free(e); queue_entry_free(e);
|
||||
|
||||
Reference in new issue
Block a user