public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: Stefano Brivio <sbrivio@redhat.com>
Cc: passt-dev@passt.top
Subject: Re: [PATCH 2/3] tcp: Properly propagate tap-side RST to socket side
Date: Wed, 28 Jan 2026 11:12:24 +1100	[thread overview]
Message-ID: <aXlUaKjjo0dmgvJi@zatzit> (raw)
In-Reply-To: <20260127123232.4877d5e3@elisabeth>

[-- Attachment #1: Type: text/plain, Size: 3701 bytes --]

On Tue, Jan 27, 2026 at 12:32:32PM +0100, Stefano Brivio wrote:
> On Tue, 27 Jan 2026 19:39:52 +1100
> David Gibson <david@gibson.dropbear.id.au> wrote:
> 
> > 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 <david@gibson.dropbear.id.au>
> > ---
> >  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);
> 
> The whole series looks good to me, except for one exceedingly minor
> aspect: should we do this also in the getsockopt() error handling path
> of tcp_prepare_flags()?

Yes, I think we should.  Or, perhaps more to the point, we should
actually handle the error code that tcp_prepare_flags() returns via
tcp_send_flag(), and we currently ignore in all callers.

> I would be inclined to apply it regardless of that, the fix is critical
> enough. I'll start the usual test run in a few hours.
> 
> -- 
> Stefano
> 

-- 
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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

  reply	other threads:[~2026-01-28  0:37 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-01-27  8:39 [PATCH 0/3] Fix bugs with RST propagation David Gibson
2026-01-27  8:39 ` [PATCH 1/3] doc: Add test program verifying socket RST behaviour David Gibson
2026-01-27  8:39 ` [PATCH 2/3] tcp: Properly propagate tap-side RST to socket side David Gibson
2026-01-27 11:32   ` Stefano Brivio
2026-01-28  0:12     ` David Gibson [this message]
2026-01-27  8:39 ` [PATCH 3/3] tcp_splice: Force TCP RST on abnormal close conditions David Gibson

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=aXlUaKjjo0dmgvJi@zatzit \
    --to=david@gibson.dropbear.id.au \
    --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).