From 66db517a282721da66a3d1160173548fc37ee024 Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Wed, 8 Mar 2017 19:43:15 +0000 Subject: [PATCH] tcp: do not keep sending SYNs when getting ACKs If a locally generated TCP SYN packet is replied to with an ACK packet, lwIP immediately sends a RST packet followed by resending the SYN packet. This is expected, but on loopback interfaces the resent SYN packet may immediately get another ACK reply, typically when the other endpoint is in TIME_WAIT state (which ignores the RSTs). The result is an endless loop of SYN, ACK, RST packets. This patch applies the normal SYN retransmission limit in this scenario, such that the endless loop is limited to a brief storm. (cherry picked from commit 5827c168c28b43d98ffbf91f45c38a054e848eda) --- src/core/tcp_in.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/core/tcp_in.c b/src/core/tcp_in.c index 902b038b..ba879284 100644 --- a/src/core/tcp_in.c +++ b/src/core/tcp_in.c @@ -810,9 +810,12 @@ tcp_process(struct tcp_pcb *pcb) tcp_rst(ackno, seqno + tcplen, ip_current_dest_addr(), ip_current_src_addr(), tcphdr->dest, tcphdr->src); /* Resend SYN immediately (don't wait for rto timeout) to establish - connection faster */ - pcb->rtime = 0; - tcp_rexmit_rto(pcb); + connection faster, but do not send more SYNs than we otherwise would + have, or we might get caught in a loop on loopback interfaces. */ + if (pcb->nrtx < TCP_SYNMAXRTX) { + pcb->rtime = 0; + tcp_rexmit_rto(pcb); + } } break; case SYN_RCVD: