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

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


The following commit(s) were added to refs/heads/master by this push:
     new a91c50243ef net/tcp: send reset when retransmitted number greater than 
TCP_MAXRTX
a91c50243ef is described below

commit a91c50243ef457aa1bc6f866e6c402b2c0df4a65
Author: zhanghongyu <[email protected]>
AuthorDate: Fri Nov 7 17:34:36 2025 +0800

    net/tcp: send reset when retransmitted number greater than TCP_MAXRTX
    
    in the current process, if tcpstate is at TCP_FIN_WAIT_1, TCP_CLOSING,
    and TCP_LAST_ACK, and the peer does not reply TCP_ACK, it will be
    retransmitted permanently. to avoid continuous occupation of resources,
    now when the retransmission equals TCP_MAXRTX, a reset message will be
    sent and the conn resources will be reclaimed in tcp_close_work.
    
    Signed-off-by: zhanghongyu <[email protected]>
---
 net/tcp/tcp_timer.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/net/tcp/tcp_timer.c b/net/tcp/tcp_timer.c
index be78056f191..d732a4e3af3 100644
--- a/net/tcp/tcp_timer.c
+++ b/net/tcp/tcp_timer.c
@@ -552,32 +552,26 @@ void tcp_timer(FAR struct net_driver_s *dev, FAR struct 
tcp_conn_s *conn)
 
               else if (
 #ifdef CONFIG_NET_TCP_WRITE_BUFFERS
-#  ifdef CONFIG_NET_SENDFILE
-                  (!conn->sendfile && conn->expired > 0) ||
-                  (conn->sendfile && conn->nrtx >= TCP_MAXRTX) ||
-#  else
                   conn->expired > 0 ||
-#  endif
-#else
-                  conn->nrtx >= TCP_MAXRTX ||
 #endif
+                  (conn->tcpstateflags != TCP_SYN_SENT &&
+                   conn->nrtx >= TCP_MAXRTX) ||
                   (conn->tcpstateflags == TCP_SYN_SENT &&
-                   conn->nrtx >= TCP_MAXSYNRTX)
-                 )
+                   conn->nrtx >= TCP_MAXSYNRTX))
                 {
                   conn->tcpstateflags = TCP_CLOSED;
                   ninfo("TCP state: TCP_CLOSED\n");
 
-                  /* We call tcp_callback() with TCP_TIMEDOUT to
+                  /* We send a reset packet to the remote host. */
+
+                  tcp_send(dev, conn, TCP_RST | TCP_ACK, hdrlen);
+
+                  /* We also call tcp_callback() with TCP_TIMEDOUT to
                    * inform the application that the connection has
                    * timed out.
                    */
 
                   tcp_callback(dev, conn, TCP_TIMEDOUT);
-
-                  /* We also send a reset packet to the remote host. */
-
-                  tcp_send(dev, conn, TCP_RST | TCP_ACK, hdrlen);
                   goto done;
                 }
 

Reply via email to