public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>, passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 2/2] tcp: Don't special case the handling of the ack of a syn
Date: Mon, 27 Mar 2023 14:56:34 +1100	[thread overview]
Message-ID: <20230327035634.1432064-3-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20230327035634.1432064-1-david@gibson.dropbear.id.au>

TCP treats the SYN packets as though they occupied 1 byte in the logical
data stream described by the sequence numbers.  That is, the very first ACK
(or SYN-ACK) each side sends should acknowledge a sequence number one
greater than the initial sequence number given in the SYN or SYN-ACK it's
responding to.

In passt we were tracking that by advancing conn->seq_to_tap by one when
we send a SYN or SYN-ACK (in tcp_send_flag()).  However, we also
initialized conn->seq_ack_from_tap, representing the acks we've already
seen from the tap side, to ISN+1, meaning we treated it has having
acknowledged the SYN before it actually did.

There were apparently reasons for this in earlier versions, but it causes
problems now.  Because of this when we actually did receive the initial ACK
or SYN-ACK, we wouldn't see the acknoweldged serial number as advancing,
and so wouldn't clear the ACK_FROM_TAP_DUE flag.

In most cases we'd get away because subsequent packets would clear the
flag.  However if one (or both) sides didn't send any data, the other side
would (correctly) keep sending ISN+1 as the acknowledged sequence number,
meaning we would never clear the ACK_FROM_TAP_DUE flag.  That would mean
we'd treat the connection as if we needed to retransmit (although we had
0 bytes to retransmit), and eventaully (after around 30s) reset the
connection due to too many retransmits.  Specifically this could cause the
iperf3 throughput tests in the testsuite to fail if set for a long enough
test period.

Correct this by initializing conn->seq_ack_from_tap to the ISN and only
advancing it when we actually get the first ACK (or SYN-ACK).

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 tcp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tcp.c b/tcp.c
index d82c62e..bbdee60 100644
--- a/tcp.c
+++ b/tcp.c
@@ -2096,7 +2096,7 @@ static void tcp_conn_from_tap(struct ctx *c, int af, const void *addr,
 	conn->seq_ack_to_tap = conn->seq_from_tap;
 
 	tcp_seq_init(c, conn, now);
-	conn->seq_ack_from_tap = conn->seq_to_tap + 1;
+	conn->seq_ack_from_tap = conn->seq_to_tap;
 
 	tcp_hash_insert(c, conn);
 
@@ -2754,7 +2754,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c, union epoll_ref ref,
 	tcp_seq_init(c, conn, now);
 	tcp_hash_insert(c, conn);
 
-	conn->seq_ack_from_tap = conn->seq_to_tap + 1;
+	conn->seq_ack_from_tap = conn->seq_to_tap;
 
 	conn->wnd_from_tap = WINDOW_DEFAULT;
 
-- 
@@ -2096,7 +2096,7 @@ static void tcp_conn_from_tap(struct ctx *c, int af, const void *addr,
 	conn->seq_ack_to_tap = conn->seq_from_tap;
 
 	tcp_seq_init(c, conn, now);
-	conn->seq_ack_from_tap = conn->seq_to_tap + 1;
+	conn->seq_ack_from_tap = conn->seq_to_tap;
 
 	tcp_hash_insert(c, conn);
 
@@ -2754,7 +2754,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c, union epoll_ref ref,
 	tcp_seq_init(c, conn, now);
 	tcp_hash_insert(c, conn);
 
-	conn->seq_ack_from_tap = conn->seq_to_tap + 1;
+	conn->seq_ack_from_tap = conn->seq_to_tap;
 
 	conn->wnd_from_tap = WINDOW_DEFAULT;
 
-- 
2.39.2


  parent reply	other threads:[~2023-03-27  3:56 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-27  3:56 [PATCH 0/2] tcp: Correct handling of first ACK (or SYN-ACK) packet David Gibson
2023-03-27  3:56 ` [PATCH 1/2] tcp: Clarify allowed state for tcp_data_from_tap() David Gibson
2023-03-27  3:56 ` David Gibson [this message]
2023-03-27  9:15 ` [PATCH 0/2] tcp: Correct handling of first ACK (or SYN-ACK) packet Stefano Brivio

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=20230327035634.1432064-3-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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).