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=202508 header.b=Yd2eJp6R; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id DAC285A027C for ; Mon, 18 Aug 2025 05:04:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1755486257; bh=i0VeFI+AdlRT4SNIH45psI7OBegIbtWfpHKW3LtpBfQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Yd2eJp6R5QYR9wbuUbON5Y90SFL8lA11Qa4KVVUpAspOCih8FuJmadXcvSxX5l3/t 1tI36urJvqcThI24O04GtCytuuMRIMTbHPEsv8lfT12WhvQY4dsoKVoXEp1JUQ2qgN nZZSLigd57pbtVHzci+nSOxg0vclWeAtxXvwP2w9N1P+HIVjdOEtJx6LOtJz+KXpUd fDhvj/nbUbwTykzCsb+a6SP/8EGbB+qkGTBVRGiynSOiqKycigSKZdVJvZHZV+v13J xKgit6/z63VtSdqT8nRFQNa+t7+OntYkLPX9O2k9oeUs59SxK9KnGakw7OOy09ZWqu Jf70nvepoMt9Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4c4yH53K2Bz4x4m; Mon, 18 Aug 2025 13:04:17 +1000 (AEST) Date: Mon, 18 Aug 2025 12:52:09 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 4/6] tcp: Fix closing logic for half-closed connections Message-ID: References: <20250815161042.3606244-1-sbrivio@redhat.com> <20250815161042.3606244-5-sbrivio@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="U5VzDh+qgTSI3qtJ" Content-Disposition: inline In-Reply-To: <20250815161042.3606244-5-sbrivio@redhat.com> Message-ID-Hash: LRNBJYSXCXGB6GBSY24EXWBFFDVHL5E6 X-Message-ID-Hash: LRNBJYSXCXGB6GBSY24EXWBFFDVHL5E6 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: passt-dev@passt.top, Jon Maloy , Paul Holzinger 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: --U5VzDh+qgTSI3qtJ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 15, 2025 at 06:10:40PM +0200, Stefano Brivio wrote: > First off, don't close connections half-closed by the guest before > our own FIN is acknowledged by the guest itself. >=20 > That is, after we receive a FIN from the guest (TAP_FIN_RCVD), if we > don't have any data left to send from the socket (SOCK_FIN_RCVD, or > EPOLLHUP), we send a FIN segment to the guest (TAP_FIN_SENT), but we > need to actually have it acknowledged (and have no pending > retransmissions) before we can close the connection: check for > TAP_FIN_ACKED, first. >=20 > Then, if we set TAP_FIN_SENT, and we receive an ACK segment from the > guest, set TAP_FIN_ACKED. This was entirely missing for the > TAP_FIN_RCVD case, and as we fix the problem described above, this > becomes relevant as well. >=20 > Signed-off-by: Stefano Brivio Reviewed-by: David Gibson > --- > tcp.c | 13 +++++++++---- > 1 file changed, 9 insertions(+), 4 deletions(-) >=20 > diff --git a/tcp.c b/tcp.c > index dda0a2e..aed25a9 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -2081,9 +2081,14 @@ int tcp_tap_handler(const struct ctx *c, uint8_t p= if, sa_family_t af, > tcp_tap_window_update(c, conn, ntohs(th->window)); > tcp_data_from_sock(c, conn); > =20 > - if (conn->events & SOCK_FIN_RCVD && > - conn->seq_ack_from_tap =3D=3D conn->seq_to_tap) > - conn_event(c, conn, CLOSED); > + if (conn->seq_ack_from_tap =3D=3D conn->seq_to_tap) { > + if (th->ack && conn->events & TAP_FIN_SENT) > + conn_event(c, conn, TAP_FIN_ACKED); > + > + if (conn->events & SOCK_FIN_RCVD && > + conn->events & TAP_FIN_ACKED) > + conn_event(c, conn, CLOSED); > + } > =20 > return 1; > } > @@ -2363,7 +2368,7 @@ void tcp_sock_handler(const struct ctx *c, union ep= oll_ref ref, > return; > } > =20 > - if ((conn->events & TAP_FIN_SENT) && (events & EPOLLHUP)) { > + if ((conn->events & TAP_FIN_ACKED) && (events & EPOLLHUP)) { > conn_event(c, conn, CLOSED); > return; > } --=20 David Gibson (he or they) | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you, not the other way | around. http://www.ozlabs.org/~dgibson --U5VzDh+qgTSI3qtJ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmiilVgACgkQzQJF27ox 2Gev4w//VwVVzCH+3XVURkcuz4yjnhDySq0o3a3d/6vFvN1R9ezU6wgrHkJJQBZ4 eCwhDC2MeB6XQX7zayuWJSUHTCIrlDCEmYfQsqKz2rvGEPrR7agUxJHwQg80ljoZ uqAPJ+jdC1rzOrIuSGe8CEXMjx97bEKH0ZJuXgwR8A7TXkUJsF8VRRxNj26eoUOY YFhw+d9iyNAjCJoLr4ASlUXxk29Sg+YIb4qU4cDq2jPQ1c2+aCoNMom6hxn9mJgW OhpGhWflMnFop+Vn7yVypoZzNylH5HILKXFiohTilnyXREA/yUv84pyco6T7kWeQ HBBsCHUdq5LkHsoHJl8i3PEw0/Jyg8OaqK8cpB++HPoOw6c3X9qzzVrFvGoLyJzs QkkzVUaF5CIXJBU9vzmOtVIIVvzJf0/9dblY56P+3+mB3GBL07AcXeTKEjYXEDMJ ZHzgpq3mrvDGfI/v6aM0F3MbFHN0T1bLxadohireBSSf04C9ooCYCzNqTI7y5NGv CCsJB75o/f7lsi8B0Huiu6cGIGDv22/tgBTNIrgi/7ck/vtSXxuRBOLj6H2XgIOG kxbBUSO7q+bMZy0VieoftCOehm0kpxbzjsFhsVYVmvq3bWTfSeBefMFQsIkrgKt0 21PGkxn4N+jSwJCxDper+044McShvuznWTBGVtsMyk1tErxULxQ= =Vp14 -----END PGP SIGNATURE----- --U5VzDh+qgTSI3qtJ--