From 30acde7b182e2b724fd063a72f5349d9f46a07dd Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 4 Jun 2026 01:13:15 +0300 Subject: [PATCH] debug: add ERROR-level logs for INIT padding calc (req+resp) Shows mtu, s_rand, s_max, offset/xoffset, and whether capped. RESP: removed old hardcoded 1472+26 cap, replaced by formula. Both paths use consistent formula based on #defines. --- src/etcp_connections.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/etcp_connections.c b/src/etcp_connections.c index f9b64f20..e4427987 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -134,7 +134,8 @@ static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset) { // padding int s = rand() % (link->handshake_maxsize - link->handshake_minsize) + link->handshake_minsize; int s_max = (int)(link->mtu) - 3 - (int)SC_TAG_SIZE + (int)UDP_SC_HDR_SIZE - (int)SC_PUBKEY_ENC_SIZE; - if (s > s_max) s = s_max; + DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "INIT_REQ: mtu=%d s=%d s_max=%d offset=%zu", (int)link->mtu, s, s_max, offset); + if (s > s_max) { DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "INIT_REQ capped s=%d -> %d", s, s_max); s = s_max; } if (s < 0) s = 0; int to_add=s-offset-UDP_HDR_SIZE - UDP_SC_HDR_SIZE; @@ -1531,9 +1532,12 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { int xoffset=sizeof(*ack_repl_hdr); // padding int s = rand() % (link->handshake_maxsize - link->handshake_minsize) + link->handshake_minsize; - if (s > link->mtu) s = link->mtu; - // Cap s: final encrypted = s - 26 for RESPONSE (noencrypt=0) - if (s > 1472 + 26) s = 1472 + 26; // s ≤ 1498 + int s_max = (int)(link->mtu) - 3 - (int)SC_TAG_SIZE + (int)UDP_SC_HDR_SIZE; + DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "INIT_RESP: mtu=%d s=%d s_max=%d xoffset=%d", (int)link->mtu, s, s_max, xoffset); + if (s > s_max) { DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "INIT_RESP capped s=%d -> %d", s, s_max); s = s_max; } + if (s < 0) s = 0; + // Remove old hardcoded caps + // if (s > 1472 + 26) s = 1472 + 26; int to_add=s - xoffset - UDP_HDR_SIZE - UDP_SC_HDR_SIZE; if (to_add<0) to_add=0;