From 4dfc0ce947afa0e776b73d80c07f34be0427a3d2 Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 4 Jun 2026 01:31:39 +0300 Subject: [PATCH] =?UTF-8?q?fix:=20correct=20INIT=20padding=20=E2=80=94=20i?= =?UTF-8?q?nclude=20SC=5FNONCE=5FSIZE=20+=20SC=5FCRC32=5FSIZE=20in=20formu?= =?UTF-8?q?la?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit REQUEST: s_max = mtu - SC_NONCE_SIZE - 3 - SC_CRC32_SIZE - SC_TAG_SIZE - SC_PUBKEY_ENC_SIZE + UDP_SC_HDR_SIZE (= mtu-78, was mtu-61) RESPONSE: s_max = mtu (noencrypt=0, simple cap) Removed debug logs. --- src/etcp_connections.c | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/src/etcp_connections.c b/src/etcp_connections.c index 8c29084e..6be1298a 100644 --- a/src/etcp_connections.c +++ b/src/etcp_connections.c @@ -133,9 +133,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; - 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; } + int s_max = (int)(link->mtu) - (int)SC_NONCE_SIZE - 3 - (int)SC_CRC32_SIZE - (int)SC_TAG_SIZE - (int)SC_PUBKEY_ENC_SIZE + (int)UDP_SC_HDR_SIZE; + if (s > s_max) s = s_max; if (s < 0) s = 0; int to_add=s-offset-UDP_HDR_SIZE - UDP_SC_HDR_SIZE; @@ -162,8 +161,6 @@ static void etcp_link_send_init(struct ETCP_LINK* link, uint8_t reset) { dgram->data_len = offset; - DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "INIT_REQ final: offset=%zu s=%d to_add=%d data_len=%d noenc=%d", - offset, s, to_add, (int)dgram->data_len, (int)dgram->noencrypt_len); DEBUG_INFO(DEBUG_CATEGORY_CONNECTION, "Sending INIT request to link, node_id=%016llx, retry=%d", (unsigned long long)node_id, link->init_retry_count); @@ -1534,12 +1531,8 @@ 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; - 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 > (int)(link->mtu)) s = (int)(link->mtu); 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; @@ -1548,9 +1541,6 @@ void etcp_connections_read_callback_socket(socket_t sock, void* arg) { for (int i=0; idata[xoffset++]=rand();// fill pad // padding end pkt->data_len=xoffset; - DEBUG_ERROR(DEBUG_CATEGORY_CONNECTION, "INIT_RESP final: xoffset=%d s=%d to_add=%d data_len=%d noenc=%d", - xoffset, s, to_add, (int)pkt->data_len, (int)pkt->noencrypt_len); - DEBUG_DEBUG(DEBUG_CATEGORY_CONNECTION, "Sending INIT RESPONSE, link=%p, local_link_id=%d, remote_link_id=%d", link, link->local_link_id, link->remote_link_id); DEBUG_INFO(DEBUG_CATEGORY_ETCP, "[ETCP DEBUG] Send INIT RESPONSE"); etcp_encrypt_send(pkt);