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 <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu
2025-11-07 17:34:36 +08:00
committed by Xiang Xiao
parent 11ea1de01d
commit a91c50243e
+8 -14
View File
@@ -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;
}