public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Anshu Kumari <anskuma@redhat.com>
To: sbrivio@redhat.com, passt-dev@passt.top, ada.urbaniec+bugzilla@gmail.com
Cc: anskuma@redhat.com
Subject: [PATCH] tcp: Limit fast retransmit to one per loss event
Date: Thu, 19 Nov 2026 18:27:52 +0530	[thread overview]
Message-ID: <20261119125752.1418394-1-anskuma@redhat.com> (raw)

Every duplicate ACK unconditionally triggered a fast retransmit,
even when the ACK sequence hadn't advanced.

Add a retransmitting flag to track whether we are counting duplicate
ACKs or actively retransmitting. we trigger fast retransmit after
three duplicates ACKs (per RFC 5681, section 3.2). Clear both
retransmitting and retries when the ACK sequence advances.

Link: https://bugs.passt.top/show_bug.cgi?id=224
Signed-off-by: Anshu Kumari <anskuma@redhat.com>
---
 tcp.c      | 33 +++++++++++++++++++++++++++------
 tcp_conn.h |  8 ++++++--
 2 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/tcp.c b/tcp.c
index 95f4f3e1..ff5d34fa 100644
--- a/tcp.c
+++ b/tcp.c
@@ -238,11 +238,12 @@
  *     - on zero read, send FIN to tap/guest, set TAP_FIN_SENT
  *   - on ACK from tap/guest:
  *     - set @ts_ack_from_tap
- *     - check if it's the second duplicated ACK
+ *     - count duplicate ACKs (same ack_seq and window, no data/FIN)
  *     - consume buffer by difference between new ack_seq and @seq_ack_from_tap
  *     - update @seq_ack_from_tap from ack_seq in header
- *     - on two duplicated ACKs, reset @seq_to_tap to @seq_ack_from_tap, and
- *       resend with steps listed above
+ *     - after three duplicate ACKs (RFC 5681), reset @seq_to_tap to
+ *       @seq_ack_from_tap, and resend with steps listed above, once per
+ *       loss event
  *
  * - from tap/guest to socket:
  *   - on packet from tap/guest:
@@ -1264,6 +1265,7 @@ static void tcp_update_seqack_from_tap(const struct ctx *c,
 			conn_flag(c, conn, ACK_FROM_TAP_DUE, now);
 
 		conn->retries = 0;
+		conn->retransmitting = 0;
 		conn->seq_ack_from_tap = seq;
 	}
 }
@@ -2082,7 +2084,13 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn,
 
 	tcp_tap_window_update(c, conn, max_ack_seq_wnd, now);
 
-	if (retr) {
+	if (retr && !conn->retransmitting)
+		conn->retries++;
+
+	if (retr && !conn->retransmitting && conn->retries > 3) {
+		conn->retransmitting = 1;
+		conn->retries = 0;
+
 		flow_trace(conn,
 			   "fast re-transmit, ACK: %u, previous sequence: %u",
 			   conn->seq_ack_from_tap, conn->seq_to_tap);
@@ -2443,7 +2451,13 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
 			tcp_update_seqack_from_tap(c, conn, ntohl(th->ack_seq),
 						   now);
 
-		if (retr) {
+		if (retr && !conn->retransmitting)
+			conn->retries++;
+
+		if (retr && !conn->retransmitting && conn->retries > 3) {
+			conn->retransmitting = 1;
+			conn->retries = 0;
+
 			flow_trace(conn,
 				   "fast re-transmit, ACK: %u, previous sequence: %u",
 				   ntohl(th->ack_seq), conn->seq_to_tap);
@@ -2453,7 +2467,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
 		}
 
 		if (tcp_tap_window_update(c, conn, ntohs(th->window), now) ||
-		    retr)
+		    (retr && conn->retransmitting))
 			tcp_data_from_sock(c, conn, now);
 
 		if (conn->seq_ack_from_tap == conn->seq_to_tap) {
@@ -2737,6 +2751,11 @@ void tcp_timer_handler(const struct ctx *c, union epoll_ref ref,
 			if (!conn->wnd_from_tap)
 				conn->wnd_from_tap = 1; /* Zero-window probe */
 
+			if (!conn->retransmitting) {
+				conn->retries = 0;
+				conn->retransmitting = 1;
+			}
+
 			conn->retries++;
 			if (tcp_rewind_seq(c, conn, now))
 				return;
@@ -3550,6 +3569,7 @@ int tcp_flow_migrate_source(int fd, struct tcp_tap_conn *conn)
 {
 	struct tcp_tap_transfer t = {
 		.retries		= conn->retries,
+		.retransmitting		= conn->retransmitting,
 		.ws_from_tap		= conn->ws_from_tap,
 		.ws_to_tap		= conn->ws_to_tap,
 		.events			= conn->events,
@@ -3826,6 +3846,7 @@ int tcp_flow_migrate_target(struct ctx *c, int fd)
 	conn = FLOW_SET_TYPE(flow, FLOW_TCP, tcp);
 
 	conn->retries			= t.retries;
+	conn->retransmitting		= t.retransmitting;
 	conn->ws_from_tap		= t.ws_from_tap;
 	conn->ws_to_tap			= t.ws_to_tap;
 	conn->events			= t.events;
diff --git a/tcp_conn.h b/tcp_conn.h
index 3173ddb9..e8e2edf0 100644
--- a/tcp_conn.h
+++ b/tcp_conn.h
@@ -16,12 +16,13 @@
 /**
  * struct tcp_tap_conn - Descriptor for a TCP connection (not spliced)
  * @f:			Generic flow information
- * @retries:		Number of retries occurred due to timeouts
+ * @retries:		Number of retries or duplicate ACKs, see @retransmitting
  * @ws_from_tap:	Window scaling factor advertised from tap/guest
  * @ws_to_tap:		Window scaling factor advertised to tap/guest
  * @tap_mss:		MSS advertised by tap/guest, rounded to 2 ^ TCP_MSS_BITS
  * @tapinactive:	No tao activity within the current KEEPALIVE_INTERVAL
  * @inactive:		No activity within the current INACTIVITY_INTERVAL
+ * @retransmitting:	0 if counting duplicate ACKs, 1 if retransmitting
  * @sock:		Socket descriptor number
  * @events:		Connection events, implying connection states
  * @timer:		timerfd descriptor for timeout events
@@ -72,6 +73,7 @@ struct tcp_tap_conn {
 
 	bool		tap_inactive	:1;
 	bool		inactive	:1;
+	bool		retransmitting	:1;
 
 	int		sock		:FD_REF_BITS;
 
@@ -122,7 +124,8 @@ struct tcp_tap_conn {
  * struct tcp_tap_transfer - Migrated TCP data, flow table part, network order
  * @pif:		Interfaces for each side of the flow
  * @side:		Addresses and ports for each side of the flow
- * @retries:		Number of retries occurred due to timeouts
+ * @retries:		Number of retries / duplicate ACKs
+ * @retransmitting:	0 if counting duplicate ACKs, 1 if retransmitting
  * @ws_from_tap:	Window scaling factor advertised from tap/guest
  * @ws_to_tap:		Window scaling factor advertised to tap/guest
  * @events:		Connection events, implying connection states
@@ -143,6 +146,7 @@ struct tcp_tap_transfer {
 	struct flowside	side[SIDES];
 
 	uint8_t		retries;
+	uint8_t		retransmitting;
 	uint8_t		ws_from_tap;
 	uint8_t		ws_to_tap;
 	uint8_t		events;
-- 
2.55.0


             reply	other threads:[~2026-11-19 12:58 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 12:57 Anshu Kumari [this message]
2026-11-19 19:01 ` 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=20261119125752.1418394-1-anskuma@redhat.com \
    --to=anskuma@redhat.com \
    --cc=ada.urbaniec+bugzilla@gmail.com \
    --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).