This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 8acce32bca1d3a23e0fc5ea841cb2a75ec5a5b10
Author: Marco Casaroli <[email protected]>
AuthorDate: Sat Nov 21 17:21:50 2026 +0100

    net/tcp: Do not send received data back with the ACK.
    
    tcp_input() did not clear dev->d_sndlen, the length of the data that a
    connection callback queues for the response.  It still holds the length
    of the data that the device sent last: over the loopback device, the
    length of the segment that tcp_input() now handles.  The paths for
    ESTABLISHED, SYN_RCVD, SYN_SENT and CLOSE_WAIT clear it before they call
    the callbacks; the paths for data in FIN_WAIT_1 and FIN_WAIT_2 and for a
    FIN in ESTABLISHED do not.  tcp_appsend() then sent that many bytes of
    the input buffer, the data that just came from the peer, back to the
    peer as new data, after our FIN.
    
    A client that shuts down writing and then reads the answer of the server
    sent each segment of the answer back.  Its sequence numbers then went
    beyond its FIN: the server dropped its ACKs, sent the last segment of
    the answer again at each retransmission timeout, and stayed in
    CLOSE_WAIT with that segment in its write buffers; the client never got
    the FIN of the server.
    
    Clear d_sndlen where tcp_input() sets the length of the received data,
    as udp_input() does.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/tcp/tcp_input.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c
index e3068fce26f..8998c4c2fd7 100644
--- a/net/tcp/tcp_input.c
+++ b/net/tcp/tcp_input.c
@@ -1195,6 +1195,15 @@ found:
 
   dev->d_len -= (len + iplen);
 
+  /* No data is queued for the response yet.  d_sndlen can still hold the
+   * length of the last segment that the device sent (over the loopback
+   * device: the segment that is this input).  The paths below that do not
+   * clear it (FIN_WAIT_1, FIN_WAIT_2, a FIN in ESTABLISHED) would then send
+   * that many bytes of the input buffer back to the peer as our data.
+   */
+
+  dev->d_sndlen = 0;
+
 #if defined(CONFIG_NET_STATISTICS) && \
     defined(CONFIG_NET_TCP_DEBUG_DROP_RECV)
 

Reply via email to