* [PATCH] tcp: Retransmit the same SYN or SYN-ACK on handshake timeout
@ 2026-12-02 20:21 Jon Maloy
2026-12-03 0:24 ` Stefano Brivio
0 siblings, 1 reply; 2+ messages in thread
From: Jon Maloy @ 2026-12-02 20:21 UTC (permalink / raw)
To: sbrivio, jmaloy, passt-dev
Commit 0e8df13c96be ("tcp: Resend SYN for inbound connections") lets
tcp_timer_handler() retry the handshake for connections that are
taking too long to establish, by sending a new, bare SYN at each retry.
However, this approach has two issues:
- For connections initiated by the guest (TAP_SYN_RCVD), we send a
SYN-ACK, not a SYN, so the retry carries the wrong flags, and lacks
the ACK
- As tcp_prepare_flags() advances seq_to_tap for every SYN we send,
every retry uses a different sequence number, and, once the
handshake completes, we start sending data from the ISN plus the
number of retries, instead of ISN + 1
If the guest acknowledges our original SYN-ACK (or SYN) after one or
more retries, for example because the ACK was held in a queue, we send
data with sequence numbers shifted by the number of retries, and, once
the retransmission timer rewinds to the acknowledged sequence, the
same data again, so that the guest assembles a corrupted stream.
Retransmit what we originally sent instead: a SYN-ACK if the guest
initiated the connection, a SYN otherwise, and reset seq_to_tap to the
initial sequence number first, which is still stored in
seq_ack_from_tap at this point.
If the guest initiated the connection, i.e. the TAP_SYN_RCVD flag is
set, we set the ACK flag in each retry, otherwise not. In both cases,
we rewind the sequence number to ISN before retransmitting.
Link: https://bugs.passt.top/show_bug.cgi?id=229
Fixes: 0e8df13c96be ("tcp: Resend SYN for inbound connections")
Signed-off-by: Jon Maloy <jmaloy@redhat.com>
---
tcp.c | 13 ++++++++++++-
1 file changed, 12 insertions(+), 1 deletion(-)
diff --git a/tcp.c b/tcp.c
index 409f4ce1..7dfb1490 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2729,8 +2729,19 @@ void tcp_timer_handler(const struct ctx *c, union epoll_ref ref,
flow_dbg(conn, "handshake timeout");
tcp_rst(c, conn, now);
} else {
+ int flags = SYN;
+
flow_trace(conn, "SYN timeout, retry");
- if (tcp_send_flag(c, conn, SYN, now)) {
+
+ /* Retransmit what we sent: a SYN-ACK if the
+ * guest initiated the connection, a SYN
+ * otherwise. Rewind to ISN at each retry.
+ */
+ if (conn->events & TAP_SYN_RCVD)
+ flags |= ACK;
+ conn->seq_to_tap = conn->seq_ack_from_tap;
+
+ if (tcp_send_flag(c, conn, flags, now)) {
tcp_rst(c, conn, now);
return;
}
--
2.56.1
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] tcp: Retransmit the same SYN or SYN-ACK on handshake timeout
2026-12-02 20:21 [PATCH] tcp: Retransmit the same SYN or SYN-ACK on handshake timeout Jon Maloy
@ 2026-12-03 0:24 ` Stefano Brivio
0 siblings, 0 replies; 2+ messages in thread
From: Stefano Brivio @ 2026-12-03 0:24 UTC (permalink / raw)
To: Jon Maloy; +Cc: passt-dev, Fumin
On Wed, 2 Dec 2026 15:21:03 -0500
Jon Maloy <jmaloy@redhat.com> wrote:
> Commit 0e8df13c96be ("tcp: Resend SYN for inbound connections") lets
> tcp_timer_handler() retry the handshake for connections that are
> taking too long to establish, by sending a new, bare SYN at each retry.
>
> However, this approach has two issues:
>
> - For connections initiated by the guest (TAP_SYN_RCVD), we send a
> SYN-ACK, not a SYN, so the retry carries the wrong flags, and lacks
> the ACK
>
> - As tcp_prepare_flags() advances seq_to_tap for every SYN we send,
> every retry uses a different sequence number, and, once the
> handshake completes, we start sending data from the ISN plus the
> number of retries, instead of ISN + 1
>
> If the guest acknowledges our original SYN-ACK (or SYN) after one or
> more retries, for example because the ACK was held in a queue, we send
> data with sequence numbers shifted by the number of retries, and, once
> the retransmission timer rewinds to the acknowledged sequence, the
> same data again, so that the guest assembles a corrupted stream.
>
> Retransmit what we originally sent instead: a SYN-ACK if the guest
> initiated the connection, a SYN otherwise, and reset seq_to_tap to the
> initial sequence number first, which is still stored in
> seq_ack_from_tap at this point.
>
> If the guest initiated the connection, i.e. the TAP_SYN_RCVD flag is
> set, we set the ACK flag in each retry, otherwise not. In both cases,
> we rewind the sequence number to ISN before retransmitting.
>
> Link: https://bugs.passt.top/show_bug.cgi?id=229
> Fixes: 0e8df13c96be ("tcp: Resend SYN for inbound connections")
> Signed-off-by: Jon Maloy <jmaloy@redhat.com>
>
> ---
> tcp.c | 13 ++++++++++++-
> 1 file changed, 12 insertions(+), 1 deletion(-)
>
> diff --git a/tcp.c b/tcp.c
> index 409f4ce1..7dfb1490 100644
> --- a/tcp.c
> +++ b/tcp.c
> @@ -2729,8 +2729,19 @@ void tcp_timer_handler(const struct ctx *c, union epoll_ref ref,
> flow_dbg(conn, "handshake timeout");
> tcp_rst(c, conn, now);
> } else {
> + int flags = SYN;
> +
> flow_trace(conn, "SYN timeout, retry");
> - if (tcp_send_flag(c, conn, SYN, now)) {
> +
> + /* Retransmit what we sent: a SYN-ACK if the
> + * guest initiated the connection, a SYN
> + * otherwise. Rewind to ISN at each retry.
> + */
> + if (conn->events & TAP_SYN_RCVD)
> + flags |= ACK;
> + conn->seq_to_tap = conn->seq_ack_from_tap;
> +
> + if (tcp_send_flag(c, conn, flags, now)) {
> tcp_rst(c, conn, now);
> return;
> }
Applied.
--
Stefano
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-12-03 0:24 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-12-02 20:21 [PATCH] tcp: Retransmit the same SYN or SYN-ACK on handshake timeout Jon Maloy
2026-12-03 0:24 ` Stefano Brivio
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).