From: Stefano Brivio <sbrivio@redhat.com>
To: Jon Maloy <jmaloy@redhat.com>
Cc: passt-dev@passt.top, Fumin <awawfumin@gmail.com>
Subject: Re: [PATCH] tcp: Retransmit the same SYN or SYN-ACK on handshake timeout
Date: Thu, 03 Dec 2026 01:24:04 +0100 (CET) [thread overview]
Message-ID: <20261203012403.4c97b686@elisabeth> (raw)
In-Reply-To: <20261202202103.2840787-1-jmaloy@redhat.com>
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
prev parent reply other threads:[~2026-12-03 0:24 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 20:21 Jon Maloy
2026-12-03 0:24 ` Stefano Brivio [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261203012403.4c97b686@elisabeth \
--to=sbrivio@redhat.com \
--cc=awawfumin@gmail.com \
--cc=jmaloy@redhat.com \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).