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

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

commit 37d7a84d2747e0d890992d6322381c6b54d3e578
Author: Marco Casaroli <[email protected]>
AuthorDate: Sun Nov 22 17:56:00 2026 +0100

    net/tcp: Reset the retry count at each ACK of new data.
    
    With CONFIG_NET_TCP_WRITE_BUFFERS, tcp_input() set the retry count of
    the connection (conn->nrtx) to zero only when an ACK covered the last
    segment sent.  After a timeout, the write buffers retransmit all the
    data sent, so a peer that acknowledges only a part of it at each timeout
    never got there.  The count grew at each timeout although the
    connection made progress: the timeout doubled at each round, and
    tcp_timer() reset the connection after TCP_MAXRTX timeouts.
    
    Set the count to zero at each ACK of new data: RFC 1122, section
    4.2.3.5, counts the retransmissions of the same segment.  Do it after
    the RTT estimate, as without write buffers (tcp_appsend() sets it to
    zero there), so that the ACK of a retransmission gives no RTT sample
    (Karn's algorithm).  Before, the reset came just before the RTT
    estimate, so the ACK of a retransmission gave a sample.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 net/tcp/tcp_input.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c
index 6407c63ac1a..ecaa34d4b79 100644
--- a/net/tcp/tcp_input.c
+++ b/net/tcp/tcp_input.c
@@ -1361,7 +1361,6 @@ found:
                     tcp_getsequence(conn->sndseq), ackseq, unackseq,
                     (uint32_t)conn->tx_unacked);
               tcp_setsequence(conn->sndseq, ackseq);
-              conn->nrtx = 0;
             }
         }
 #endif
@@ -1390,6 +1389,20 @@ found:
         }
 #endif
 
+#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
+      /* The peer acknowledges new data: reset the retry count, also when
+       * it does not acknowledge all the data sent.  RFC 1122, section
+       * 4.2.3.5, counts the retransmissions of the same segment.  Do it
+       * after the RTT estimate: the ACK of a retransmission gives no RTT
+       * sample (Karn's algorithm).
+       */
+
+      if (conn->tx_unacked < lasttxunacked)
+        {
+          conn->nrtx = 0;
+        }
+#endif
+
       /* Set the acknowledged flag. */
 
       flags |= TCP_ACKDATA;

Reply via email to