diff --git a/README b/README index 0754a5209..17df7a466 100644 --- a/README +++ b/README @@ -693,6 +693,7 @@ Maps to **XLIO_TCP_TIMER_RESOLUTION_MSEC** environment variable. Control internal TCP timer resolution (fast timer) in milliseconds. Minimum value is the thread wakeup timer resolution configured in performance.threading.internal_handler.timer_msec. +Maximum is 500ms per RFC 1122 Section 4.2.3.2 (delayed ACK timer must not exceed 500ms). Default value is 100 network.protocols.tcp.timestamps diff --git a/src/core/config/descriptor_providers/xlio_config_schema.json b/src/core/config/descriptor_providers/xlio_config_schema.json index 10f3c7b4e..529513943 100644 --- a/src/core/config/descriptor_providers/xlio_config_schema.json +++ b/src/core/config/descriptor_providers/xlio_config_schema.json @@ -418,9 +418,10 @@ "timer_msec": { "type": "integer", "minimum": 0, + "maximum": 500, "default": 100, "title": "TCP timer interval (msec)", - "description": "Maps to XLIO_TCP_TIMER_RESOLUTION_MSEC environment variable.\nControl internal TCP timer resolution (fast timer) in milliseconds.\nMinimum value is the thread wakeup timer resolution configured in\nperformance.threading.internal_handler.timer_msec." + "description": "Maps to XLIO_TCP_TIMER_RESOLUTION_MSEC environment variable.\nControl internal TCP timer resolution (fast timer) in milliseconds.\nMinimum value is the thread wakeup timer resolution configured in\nperformance.threading.internal_handler.timer_msec.\nMaximum is 500ms per RFC 1122 Section 4.2.3.2 (delayed ACK timer must not exceed 500ms)." }, "mss": { "type": "integer", diff --git a/src/core/lwip/tcp.c b/src/core/lwip/tcp.c index 43e3bebcb..188598124 100644 --- a/src/core/lwip/tcp.c +++ b/src/core/lwip/tcp.c @@ -905,6 +905,11 @@ err_t tcp_recv_null(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err) return ERR_OK; } +static inline u32_t get_initial_rto(void) +{ + return (1000 + slow_tmr_interval - 1) / slow_tmr_interval; +} + void tcp_pcb_init(struct tcp_pcb *pcb, u8_t prio, void *container) { u32_t iss; @@ -927,9 +932,10 @@ void tcp_pcb_init(struct tcp_pcb *pcb, u8_t prio, void *container) pcb->mss = pcb->advtsd_mss; pcb->user_timeout_ms = 0; pcb->ticks_since_data_sent = -1; - pcb->rto = 3000 / slow_tmr_interval; + // Set initial RTO to 1 second as per RFC 6298 + pcb->rto = get_initial_rto(); pcb->sa = 0; - pcb->sv = 3000 / slow_tmr_interval; + pcb->sv = get_initial_rto(); pcb->rtime = -1; #if TCP_CC_ALGO_MOD switch (lwip_cc_algo_module) { @@ -985,9 +991,10 @@ void tcp_pcb_recycle(struct tcp_pcb *pcb) pcb->flags = 0; pcb->user_timeout_ms = 0; pcb->ticks_since_data_sent = -1; - pcb->rto = 3000 / slow_tmr_interval; + // Set initial RTO to 1 second as per RFC 6298 + pcb->rto = get_initial_rto(); pcb->sa = 0; - pcb->sv = 3000 / slow_tmr_interval; + pcb->sv = get_initial_rto(); pcb->nrtx = 0; pcb->dupacks = 0; pcb->rtime = -1; diff --git a/src/core/util/sys_vars.cpp b/src/core/util/sys_vars.cpp index e2b4b1d7a..1f862ba90 100644 --- a/src/core/util/sys_vars.cpp +++ b/src/core/util/sys_vars.cpp @@ -1621,6 +1621,16 @@ void mce_sys_var::get_env_params() tcp_timer_resolution_msec = timer_resolution_msec; } + // RFC 1122 Section 4.2.3.2: Delayed ACK timer must not exceed 500ms + // This limits TCP timer resolution to ensure protocol compliance and proper RTO calculations + if (tcp_timer_resolution_msec > 500) { + vlog_printf(VLOG_WARNING, + "TCP timer resolution [%s=%d] exceeds RFC 1122 maximum of 500ms. " + "Clamping to 500ms to ensure protocol compliance.\n", + SYS_VAR_TCP_TIMER_RESOLUTION_MSEC, tcp_timer_resolution_msec); + tcp_timer_resolution_msec = 500; + } + if ((env_ptr = getenv(SYS_VAR_INTERNAL_THREAD_CPUSET))) { snprintf(internal_thread_cpuset, FILENAME_MAX, "%s", env_ptr); } @@ -2744,6 +2754,16 @@ void mce_sys_var::configure_memory_limits(const config_registry ®istry) tcp_timer_resolution_msec = timer_resolution_msec; } + // RFC 1122 Section 4.2.3.2: Delayed ACK timer must not exceed 500ms + // This limits TCP timer resolution to ensure protocol compliance and proper RTO calculations + if (tcp_timer_resolution_msec > 500) { + vlog_printf(VLOG_WARNING, + "TCP timer resolution [%s=%d] exceeds RFC 1122 maximum of 500ms. " + "Clamping to 500ms to ensure protocol compliance.\n", + SYS_VAR_TCP_TIMER_RESOLUTION_MSEC, tcp_timer_resolution_msec); + tcp_timer_resolution_msec = 500; + } + if (registry.value_exists("performance.threading.cpuset")) { snprintf(internal_thread_cpuset, FILENAME_MAX, "%s", registry.get_value("performance.threading.cpuset").c_str());