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=202512 header.b=T+OL2/kH; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id E3A635A0625 for ; Tue, 27 Jan 2026 09:39:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202512; t=1769503195; bh=UXgnRO2NHTKW8JyZ8eu/Rs4aA+G1Ib7DgQBdisgXubQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=T+OL2/kH5KJQbikobhEa7lJsgMrp1+Nk3DhYwO6mrfaS/GihSxwcOBDKUUP4WOBcX Wx/7yS9PqqCEctevv++snor0y+NP5IdNg+quv6azmE2nXYDvfA9bvxogwnmGqx3txd PiJnN8FqBSGwcoyfHE9oeFf/IpXuHuWg46WuLVvdvwzKnRHj/oLt0zc5Y/5acqVTcV iCGi3o3xY1BlC1DxyeQ/ZUtMBrlC0lISpPod5UM/yK1wefx6NNCP5naZFo7TzVxHZw gTjBViJaBc38truBmnLAHeM+QmwSUDSiONNSv8iOx5ws++IzSJEpNk3Ehz6Wfb3idg 3kcVSkD4XEqHw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4f0f3b1jS6z4w2D; Tue, 27 Jan 2026 19:39:55 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH 2/3] tcp: Properly propagate tap-side RST to socket side Date: Tue, 27 Jan 2026 19:39:52 +1100 Message-ID: <20260127083953.824556-3-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.52.0 In-Reply-To: <20260127083953.824556-1-david@gibson.dropbear.id.au> References: <20260127083953.824556-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: LUIKVXJQIWW2ZP4K6T3F4PLXO42SDLOC X-Message-ID-Hash: LUIKVXJQIWW2ZP4K6T3F4PLXO42SDLOC 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: When the guest sends a TCP RST, or on certain error conditions, we want to signal the abnormal termination of a TCP connection to the peer with an RST as well. We attempt to do that by close()ing the socket. That doesn't work: a close() will usually send a FIN, rather than an RST. The standard method of forcing an RST on a socket is to set the SO_LINGER socket option with a 0 timeout, then close(). Update the tcp_rst() path to do this, so it forces a socket side RST. Update the handling of a guest side RST to use the same path (minus sending a tap side RST) so that we properly propagate guest RSTs to the peer. Link: https://bugs.passt.top/show_bug.cgi?id=191 Signed-off-by: David Gibson --- tcp.c | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/tcp.c b/tcp.c index 45dde5a0..9da37c2f 100644 --- a/tcp.c +++ b/tcp.c @@ -1403,7 +1403,34 @@ static int tcp_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, } /** - * tcp_rst_do() - Reset a tap connection: send RST segment to tap, close socket + * tcp_sock_rst() - Close TCP connection forcing RST on socket side + * @c: Execution context + * @conn: Connection pointer + */ +static void tcp_sock_rst(const struct ctx *c, struct tcp_tap_conn *conn) +{ + const struct linger linger0 = { + .l_onoff = 1, + .l_linger = 0, + }; + + /* Force RST on socket to inform the peer + * + * We do this by setting SO_LINGER with 0 timeout, which means that + * close() will send an RST (unless the connection is already closed in + * both directions). + */ + if (setsockopt(conn->sock, SOL_SOCKET, + SO_LINGER, &linger0, sizeof(linger0)) < 0) { + flow_dbg_perror(conn, + "SO_LINGER failed, may not send RST to peer"); + } + + conn_event(c, conn, CLOSED); +} + +/** + * tcp_rst_do() - Reset a tap connection: send RST segment on both sides, close * @c: Execution context * @conn: Connection pointer */ @@ -1412,8 +1439,10 @@ void tcp_rst_do(const struct ctx *c, struct tcp_tap_conn *conn) if (conn->events == CLOSED) return; + /* Send RST on tap */ tcp_send_flag(c, conn, RST); - conn_event(c, conn, CLOSED); + + tcp_sock_rst(c, conn); } /** @@ -1884,7 +1913,7 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, return -1; if (th->rst) { - conn_event(c, conn, CLOSED); + tcp_sock_rst(c, conn); return 1; } @@ -2248,7 +2277,7 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af, flow_trace(conn, "packet length %zu from tap", l4len); if (th->rst) { - conn_event(c, conn, CLOSED); + tcp_sock_rst(c, conn); return 1; } -- 2.52.0