From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=dAJzZLeX; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 969AA5A0619 for ; Fri, 10 Oct 2025 09:47:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1760082449; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MAZtABkoyiE6hGposeE2OhowX3MJ2Q1MLC2OPOb+AV8=; b=dAJzZLeXmg/Wb3tGS5QwCUD8E3FbEClIOUrAEB6M/8bUTOMNl3BqdpgsNIaU0AZUNA4Grv XgxNE5Uk6a+hfqQHL3ZEV39VVCviI5aL/kkI0iVQL535gqBI955M+r3Rk9J3TYxxwmW7ob j+EvXabqI30WqpgGOj72vyv4cXN0ANk= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-373-r_jDjgsEM0igPEvBHsK_DQ-1; Fri, 10 Oct 2025 03:47:26 -0400 X-MC-Unique: r_jDjgsEM0igPEvBHsK_DQ-1 X-Mimecast-MFC-AGG-ID: r_jDjgsEM0igPEvBHsK_DQ_1760082445 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DFFBD180057D; Fri, 10 Oct 2025 07:47:24 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.72.112.91]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 5A80B30001B7; Fri, 10 Oct 2025 07:47:21 +0000 (UTC) From: Yumei Huang To: passt-dev@passt.top, sbrivio@redhat.com Subject: [PATCH v2 3/3] tcp: Update data retransmission timeout Date: Fri, 10 Oct 2025 15:47:00 +0800 Message-ID: <20251010074700.22177-4-yuhuang@redhat.com> In-Reply-To: <20251010074700.22177-1-yuhuang@redhat.com> References: <20251010074700.22177-1-yuhuang@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: 0AEgVDbmAMtoe2dFeRE0a09iEDI0FrNhNHy4fV-lNuw_1760082445 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: UKFMJGWLPVQJB4T3JIBEMO5NKDPFZCSB X-Message-ID-Hash: UKFMJGWLPVQJB4T3JIBEMO5NKDPFZCSB X-MailFrom: yuhuang@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: david@gibson.dropbear.id.au, yuhuang@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Use an exponential backoff timeout with the initial timeout 1s and total timeout 60s. Signed-off-by: Yumei Huang --- tcp.c | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/tcp.c b/tcp.c index 85bbdac..0db7f30 100644 --- a/tcp.c +++ b/tcp.c @@ -185,10 +185,15 @@ * for more than TCP_MAX_RETRIES or (tcp_syn_retries + * tcp_syn_linear_timeouts) times in a row, reset the connection * - * - ACK_TIMEOUT: if no ACK segment was received from tap/guest, after sending - * data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), re-send data from the - * socket and reset sequence to what was acknowledged. If this persists for - * more than TCP_MAX_RETRIES times in a row, reset the connection + * - ACK_TIMEOUT_INIT: if no ACK segment was received from tap/guest, after + * sending data (flag ACK_FROM_TAP_DUE with ESTABLISHED event), re-send data + * from the socket and reset sequence to what was acknowledged. It's the + * starting timeout for the first retransmission. If this persists for more + * than TCP_MAX_RETRIES times in a row, reset the connection + * + * - ACK_TIMEOUT_TOTAL: if no ACK segment was received from tap/guest after + * retransmitting data repeatedly from the socket within this time, reset + * the connection * * - FIN_TIMEOUT: if a FIN segment was sent to tap/guest (flag ACK_FROM_TAP_DUE * with TAP_FIN_SENT event), and no ACK is received within this time, reset @@ -344,7 +349,8 @@ enum { #define ACK_INTERVAL 10 /* ms */ #define SYN_TIMEOUT_INIT 1 /* s */ -#define ACK_TIMEOUT 2 +#define ACK_TIMEOUT_INIT 1 +#define ACK_TIMEOUT_TOTAL 60 #define FIN_TIMEOUT 60 #define ACT_TIMEOUT 7200 @@ -358,6 +364,9 @@ enum { ((conn)->events & (SOCK_FIN_RCVD | TAP_FIN_RCVD))) #define CONN_HAS(conn, set) (((conn)->events & (set)) == (set)) +#define RETRY_ELAPSED(timeout_init, retries) \ + ((timeout_init) * ((1 << ((retries) + 1)) - 2)) + /* Buffers to migrate pending data from send and receive queues. No, they don't * use memory if we don't use them. And we're going away after this, so splurge. */ @@ -596,7 +605,7 @@ static void tcp_timer_ctl(const struct ctx *c, struct tcp_tap_conn *conn) (conn->retries - c->tcp.syn_linear_timeouts); } else - it.it_value.tv_sec = ACK_TIMEOUT; + it.it_value.tv_sec = ACK_TIMEOUT_INIT << conn->retries; } else if (CONN_HAS(conn, SOCK_FIN_SENT | TAP_FIN_ACKED)) { it.it_value.tv_sec = FIN_TIMEOUT; } else { @@ -2438,6 +2447,10 @@ void tcp_timer_handler(const struct ctx *c, union epoll_ref ref) } else if (conn->retries == TCP_MAX_RETRIES) { flow_dbg(conn, "retransmissions count exceeded"); tcp_rst(c, conn); + } else if(RETRY_ELAPSED(ACK_TIMEOUT_INIT, conn->retries) >= + ACK_TIMEOUT_TOTAL) { + flow_dbg(conn, "retransmissions timeout exceeded"); + tcp_rst(c, conn); } else { flow_dbg(conn, "ACK timeout, retry"); -- 2.47.0