From 1b3c4552fb9ccd549f4f87f2c0a5529aadbd60f5 Mon Sep 17 00:00:00 2001 From: evgeny Date: Fri, 23 Oct 2026 10:24:29 +0200 Subject: [PATCH] Account for transmission IDs in MTU and packet diagnostics --- src/transport_layer/etcp.c | 2 +- src/transport_layer/etcp_debug.c | 6 +++--- src/transport_layer/pkt_normalizer.c | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/transport_layer/etcp.c b/src/transport_layer/etcp.c index 99cad98a..8dd1da07 100644 --- a/src/transport_layer/etcp.c +++ b/src/transport_layer/etcp.c @@ -1674,7 +1674,7 @@ void etcp_update_mtu(struct ETCP_CONN* etcp) { 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 - ETCP_SESSION_HEADER_SIZE; + etcp->normalizer->frag_size = etcp->mtu - max_udp - SC_ENCRYPT_OVERHEAD - ETCP_PAYLOAD_HEADER_SIZE - ACK_REZERV; } } } diff --git a/src/transport_layer/etcp_debug.c b/src/transport_layer/etcp_debug.c index ee5f8518..c299cf6f 100644 --- a/src/transport_layer/etcp_debug.c +++ b/src/transport_layer/etcp_debug.c @@ -47,7 +47,7 @@ void etcp_dump_pkt_sections(struct ETCP_DGRAM* pkt, struct ETCP_LINK* link, int ((uint32_t)data[offset + 4] << 16) | ((uint32_t)data[offset + 5] << 24); uint16_t ack_rx_dup = data[offset + 6] | (data[offset + 7] << 8); pos += snprintf(buf + pos, sizeof(buf) - pos, " ack=%u/%d dup=%u", ack_last_delivered, ack_count, ack_rx_dup); - offset += 8 + ack_count * 8; + offset += ETCP_ACK_BASE_SIZE + ack_count * ETCP_ACK_ENTRY_SIZE; break; } case ETCP_SECTION_TIMESTAMP: { @@ -60,10 +60,10 @@ void etcp_dump_pkt_sections(struct ETCP_DGRAM* pkt, struct ETCP_LINK* link, int break; } case ETCP_SECTION_PAYLOAD: { - if (offset + 5 > len) { offset = len; break; } + if (offset + ETCP_PAYLOAD_HEADER_SIZE > len) { offset = len; break; } payload_seq = (uint32_t)data[offset + 1] | ((uint32_t)data[offset + 2] << 8) | ((uint32_t)data[offset + 3] << 16) | ((uint32_t)data[offset + 4] << 24); - payload_size = len - offset - 5; + payload_size = len - offset - ETCP_PAYLOAD_HEADER_SIZE; has_payload = 1; pos += snprintf(buf + pos, sizeof(buf) - pos, " payload=%u(seq=%u)", payload_size, payload_seq); offset = len; diff --git a/src/transport_layer/pkt_normalizer.c b/src/transport_layer/pkt_normalizer.c index a03dce41..7ed37e37 100644 --- a/src/transport_layer/pkt_normalizer.c +++ b/src/transport_layer/pkt_normalizer.c @@ -42,8 +42,8 @@ struct PKTNORM* pn_init(struct ETCP_CONN* etcp) { 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 - ETCP_SESSION_HEADER_SIZE; - int min_frag = max_udp + UDP_SC_HDR_SIZE + ACK_REZERV; + pn->frag_size = etcp->mtu - max_udp - SC_ENCRYPT_OVERHEAD - ETCP_PAYLOAD_HEADER_SIZE - ACK_REZERV; + int min_frag = max_udp + SC_ENCRYPT_OVERHEAD + ETCP_PAYLOAD_HEADER_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;