public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
* [PATCH] tcp: Don't reset outbound connection on SYN retries
@ 2025-02-03  7:25 Stefano Brivio
  2025-02-03  9:08 ` David Gibson
  0 siblings, 1 reply; 2+ messages in thread
From: Stefano Brivio @ 2025-02-03  7:25 UTC (permalink / raw)
  To: passt-dev

Reported by somebody on IRC: if the server has considerable latency,
it might happen that the client retries sending SYN segments for the
same flow while we're still in a TAP_SYN_RCVD, non-ESTABLISHED state.

In that case, we should go with the blanket assumption that we need
to reset the connection on any unexpected segment: RFC 9293 explicitly
mentions this case in Figure 8: Recovery from Old Duplicate SYN,
section 3.5. It doesn't make sense for us to set a specific sequence
number, socket-side, but we should definitely wait and see.

Ignoring the duplicate SYN segment should also be compatible with
section 3.10.7.3. SYN-SENT STATE, which mentions updating sequences
socket-side (which we can't do anyway), but certainly not reset the
connection.

Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
 tcp.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/tcp.c b/tcp.c
index 7787381..51ad692 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1920,6 +1920,9 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
 
 	/* Establishing connection from tap */
 	if (conn->events & TAP_SYN_RCVD) {
+		if (th->syn && !th->ack && !th->fin)
+			return 1;	/* SYN retry: ignore and keep waiting */
+
 		if (!(conn->events & TAP_SYN_ACK_SENT))
 			goto reset;
 
-- 
@@ -1920,6 +1920,9 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
 
 	/* Establishing connection from tap */
 	if (conn->events & TAP_SYN_RCVD) {
+		if (th->syn && !th->ack && !th->fin)
+			return 1;	/* SYN retry: ignore and keep waiting */
+
 		if (!(conn->events & TAP_SYN_ACK_SENT))
 			goto reset;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] tcp: Don't reset outbound connection on SYN retries
  2025-02-03  7:25 [PATCH] tcp: Don't reset outbound connection on SYN retries Stefano Brivio
@ 2025-02-03  9:08 ` David Gibson
  0 siblings, 0 replies; 2+ messages in thread
From: David Gibson @ 2025-02-03  9:08 UTC (permalink / raw)
  To: Stefano Brivio; +Cc: passt-dev

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

On Mon, Feb 03, 2025 at 08:25:58AM +0100, Stefano Brivio wrote:
> Reported by somebody on IRC: if the server has considerable latency,
> it might happen that the client retries sending SYN segments for the
> same flow while we're still in a TAP_SYN_RCVD, non-ESTABLISHED state.
> 
> In that case, we should go with the blanket assumption that we need
> to reset the connection on any unexpected segment: RFC 9293 explicitly
> mentions this case in Figure 8: Recovery from Old Duplicate SYN,
> section 3.5. It doesn't make sense for us to set a specific sequence
> number, socket-side, but we should definitely wait and see.
> 
> Ignoring the duplicate SYN segment should also be compatible with
> section 3.10.7.3. SYN-SENT STATE, which mentions updating sequences
> socket-side (which we can't do anyway), but certainly not reset the
> connection.
> 
> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>

I haven't dug into the RFC to check this thoroughly, but it makes
intuitive sense to me.

Reviewed-by: David Gibson <david@gibson.dropbear.id.au>

> ---
>  tcp.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/tcp.c b/tcp.c
> index 7787381..51ad692 100644
> --- a/tcp.c
> +++ b/tcp.c
> @@ -1920,6 +1920,9 @@ int tcp_tap_handler(const struct ctx *c, uint8_t pif, sa_family_t af,
>  
>  	/* Establishing connection from tap */
>  	if (conn->events & TAP_SYN_RCVD) {
> +		if (th->syn && !th->ack && !th->fin)
> +			return 1;	/* SYN retry: ignore and keep waiting */
> +
>  		if (!(conn->events & TAP_SYN_ACK_SENT))
>  			goto reset;
>  

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2025-02-03  9:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-02-03  7:25 [PATCH] tcp: Don't reset outbound connection on SYN retries Stefano Brivio
2025-02-03  9:08 ` David Gibson

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