From 4c85805be0709138babb41b09f574bd73cb68ceb Mon Sep 17 00:00:00 2001 From: liqinhui Date: Wed, 11 Sep 2024 20:50:27 +0800 Subject: [PATCH] net/tcp: Reset the conn when receiving a ACK in the SYN_SENT state. According to RFC793, Section 3.4, Page 33. In the SYN_SENT state, if receive a ACK without the SYN, we should reset the connection and retransmit the SYN. Signed-off-by: liqinhui --- net/tcp/tcp_input.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/net/tcp/tcp_input.c b/net/tcp/tcp_input.c index 723cacf467..8b5bcffa29 100644 --- a/net/tcp/tcp_input.c +++ b/net/tcp/tcp_input.c @@ -1174,6 +1174,27 @@ found: seq = tcp_getsequence(tcp->seqno); rcvseq = tcp_getsequence(conn->rcvseq); + /* According to RFC793, Section 3.4, Page 33. + * In the SYN_SENT state, if receive a ACK without SYN, + * we should reset the connection and retransmit the SYN. + */ + + if (((conn->tcpstateflags & TCP_STATE_MASK) == TCP_SYN_SENT) && + ((tcp->flags & TCP_SYN) == 0 && (tcp->flags & TCP_ACK) != 0)) + { + /* Send the RST to close the half-open connection. */ + + tcp_reset(dev, conn); + + /* Retransmit the SYN as soon as possible in order to establish + * the tcp connection. + */ + + tcp_update_retrantimer(conn, 1); + + return; + } + if (seq != rcvseq) { /* Trim the head of the segment */