From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=SkxSLnqD; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6A8A85A0274 for ; Thu, 28 May 2026 07:02:24 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779944535; bh=26x9MTtGmlkjoniTsl329Ma2W8R6cDB8WJo2LT/pOp0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SkxSLnqDIA4ez5ZfM8stENwY7c2EbNgRXRV6X/ppXDWPQlv+GEQ36vdl+6Oz7rtnt 6RQbrYbiccuIvva5dqgnp4QxJOZf35+UfIJBq3fw+IZf5CDkyyAxBz1vG0xpvcF75e XbGaI1EHlhqVjiuOlN9w/APp0se7fgP+qK3MfM67H7P96crcArMpfNyH55xsznoSvo PfEXEDlgsrubTQ+m+tOkEJQ7QkcDFKiMim0fBcRZ+ngU/WcVNLrUmEXW20r0rF2xnk NK2MUYdKJGSr2nr/rJep/Lto4JKE/oJoZyWkRUJqU/x7CpvMNIGPJxJjnVRxRyKXqF i3nydJ4PkXWuQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gQvVb0V1nz4wLt; Thu, 28 May 2026 15:02:15 +1000 (AEST) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 5/8] tcp_splice: Simplify shutdown(2) handling Date: Thu, 28 May 2026 15:02:10 +1000 Message-ID: <20260528050213.679685-6-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260528050213.679685-1-david@gibson.dropbear.id.au> References: <20260528050213.679685-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: 5S5JCEHSIFU62II5LQPOJDB2RMNXOVQC X-Message-ID-Hash: 5S5JCEHSIFU62II5LQPOJDB2RMNXOVQC X-MailFrom: dgibson@gandalf.ozlabs.org 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 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: At the end of tcp_splice_forward(), we check for half-closed connections in either direction and propagate the FIN to the other side with a shutdown(2). However, it's unnecessary to check both directions: a FIN from side X will cause an EPOLLRDUP on side X's socket, which will trigger tcp_splice_forward() from side X to side !X. Likewise for the other side. So we only need to check for "forward" FIN propagation. Signed-off-by: David Gibson --- tcp_splice.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/tcp_splice.c b/tcp_splice.c index 8c8e3bbb..42902684 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -544,22 +544,15 @@ static int tcp_splice_forward(struct ctx *c, break; } - if (!conn->pending[fromsidei] && - conn->events & FIN_RCVD(fromsidei)) { - unsigned sidei; - - flow_foreach_sidei(sidei) { - if ((conn->events & FIN_RCVD(sidei)) && - !(conn->events & FIN_SENT(!sidei))) { - if (shutdown(conn->s[!sidei], SHUT_WR) < 0) { - flow_perror_ratelimit( - conn, now, "shutdown() on %s", - pif_name(conn->f.pif[!sidei])); - return -1; - } - conn_event(conn, FIN_SENT(!sidei)); - } + if ((conn->events & FIN_RCVD(fromsidei)) && + !(conn->events & FIN_SENT(!fromsidei)) && + !conn->pending[fromsidei]) { + if (shutdown(conn->s[!fromsidei], SHUT_WR) < 0) { + flow_perror_ratelimit(conn, now, "shutdown() on %s", + pif_name(conn->f.pif[!fromsidei])); + return -1; } + conn_event(conn, FIN_SENT(!fromsidei)); } return 0; -- 2.54.0