From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=aWpU1H7G; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTP id 536A25A061C for ; Thu, 21 Nov 2024 05:26:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732163191; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IKYoCJBcDfy8VleDABgwISPIWIsWjbciK8uZUnguOK0=; b=aWpU1H7GYPBPoJNbeIFemfn+8TGFdWR6ECaVabfC9v1fpaZjGBhDOKlhOVuZ/5qnBiCgob tdwMAtlt0A+bY2A83pt+K8g2ypgzAQtYOGM3AdYDLLt2p1/H12i/bRS8QhNdGGyRQYYuC7 LtveqPzxmnCS5/mrC6Kv5oDnooOy9ks= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-300-jksTTDPxOwSBxuTlyXhUjA-1; Wed, 20 Nov 2024 23:26:27 -0500 X-MC-Unique: jksTTDPxOwSBxuTlyXhUjA-1 X-Mimecast-MFC-AGG-ID: jksTTDPxOwSBxuTlyXhUjA Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3822ebe9321so250721f8f.2 for ; Wed, 20 Nov 2024 20:26:26 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732163184; x=1732767984; h=content-transfer-encoding:mime-version:organization:references :in-reply-to:message-id:subject:cc:to:from:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=IKYoCJBcDfy8VleDABgwISPIWIsWjbciK8uZUnguOK0=; b=cr5kLoEPXMa4UsYSrOO3qvgJfbDoX2M7c1LVZu8bHIssLCapkjKRpHUZwDZ2A10vLT Cg2WL9CQ7uQAeOY7IAvPt884bEJULHpessbl8Vvuvr5/Poubw/ZuKSzkB31sOepv6dEm LOLzfduxa2eeWrlG+g5Y7qjnJM9vpOndBL1hypawBRs2a0YRy+757dByCD+Nrkugfc0L jKh02lc4PcXJiflAtl+birTaKGy6ceMZNJbU/DERtmbMJWvM9lj0k+ufQOZPQKSVopQ4 udvZ5eQNqUzFyezv5j7UFEKQzRJxuAmIxzNT1UTNWb5Fmki2k6RtyoqpVlg53aBsQqr5 1VBQ== X-Gm-Message-State: AOJu0Yzi9nEF1pTwG+zNkNyxgLOBSS8Tfcrtu7VaYCm7/rFUrkxku7LM hDeNA7Xz6OLrASJoOENRurmBt7ZxL/kpuV/08MRq9EcDNZ6j44efqHYg8L3l9Nm/mfvr7WliNWf i8D8Bgw6WS6nyURPgFjBHeba1bNM50C3FMnF9opUp1JV3lISs6A== X-Received: by 2002:a05:6000:2ae:b0:382:49f9:74bc with SMTP id ffacd0b85a97d-38254b153f0mr3758145f8f.41.1732163183916; Wed, 20 Nov 2024 20:26:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IGaltEx3NPmsiFn63ZOrEC+stH71eIPbnsJZexMjy8zQ5NXGd5PXmtsUIqlLDzLXYC8iydJhA== X-Received: by 2002:a05:6000:2ae:b0:382:49f9:74bc with SMTP id ffacd0b85a97d-38254b153f0mr3758132f8f.41.1732163183587; Wed, 20 Nov 2024 20:26:23 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-38254933c85sm3715564f8f.65.2024.11.20.20.26.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 20:26:21 -0800 (PST) Date: Thu, 21 Nov 2024 05:26:17 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/2] tcp: Acknowledge keep-alive segments, ignore them for the rest Message-ID: <20241121052617.50cf96ef@elisabeth> In-Reply-To: References: <20241119195344.3056010-1-sbrivio@redhat.com> <20241119195344.3056010-3-sbrivio@redhat.com> <20241120074344.705523be@elisabeth> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.41; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: gYr3lALLQoUv9RUgteYKu32FIj03f-NKRV2O55SNwIs_1732163184 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: YP5FZ7OEPRMREFKJ3YH4JRV3AB4ASE2P X-Message-ID-Hash: YP5FZ7OEPRMREFKJ3YH4JRV3AB4ASE2P X-MailFrom: sbrivio@redhat.com 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, Tim Besard 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: On Thu, 21 Nov 2024 13:38:09 +1100 David Gibson wrote: > On Wed, Nov 20, 2024 at 07:43:44AM +0100, Stefano Brivio wrote: > > On Wed, 20 Nov 2024 12:02:00 +1100 > > David Gibson wrote: > > > > > On Tue, Nov 19, 2024 at 08:53:44PM +0100, Stefano Brivio wrote: > > > > RFC 9293, 3.8.4 says: > > > > > > > > Implementers MAY include "keep-alives" in their TCP implementations > > > > (MAY-5), although this practice is not universally accepted. Some > > > > TCP implementations, however, have included a keep-alive mechanism. > > > > To confirm that an idle connection is still active, these > > > > implementations send a probe segment designed to elicit a response > > > > from the TCP peer. Such a segment generally contains SEG.SEQ = > > > > SND.NXT-1 and may or may not contain one garbage octet of data. If > > > > keep-alives are included, the application MUST be able to turn them > > > > on or off for each TCP connection (MUST-24), and they MUST default to > > > > off (MUST-25). > > > > > > > > but currently, tcp_data_from_tap() is not aware of this and will > > > > schedule a fast re-transmit on the second keep-alive (because it's > > > > also a duplicate ACK), ignoring the fact that the sequence number was > > > > rewinded to SND.NXT-1. > > > > > > > > ACK these keep-alive segments, reset the activity timeout, and ignore > > > > them for the rest. > > > > > > > > At some point, we could think of implementing an approximation of > > > > keep-alive segments on outbound sockets, for example by setting > > > > TCP_KEEPIDLE to 1, and a large TCP_KEEPINTVL, so that we send a single > > > > keep-alive segment at approximately the same time, and never reset the > > > > connection. That's beyond the scope of this fix, though. > > > > > > > > Reported-by: Tim Besard > > > > Link: https://github.com/containers/podman/discussions/24572 > > > > Signed-off-by: Stefano Brivio > > > > --- > > > > tcp.c | 14 ++++++++++++++ > > > > 1 file changed, 14 insertions(+) > > > > > > > > diff --git a/tcp.c b/tcp.c > > > > index f357920..1eb85bb 100644 > > > > --- a/tcp.c > > > > +++ b/tcp.c > > > > @@ -1763,6 +1763,20 @@ static int tcp_data_from_tap(const struct ctx *c, struct tcp_tap_conn *conn, > > > > continue; > > > > > > > > seq = ntohl(th->seq); > > > > + if (SEQ_LT(seq, conn->seq_from_tap) && len <= 1) { > > > > + flow_trace(conn, > > > > + "keep-alive sequence: %u, previous: %u", > > > > + seq, conn->seq_from_tap); > > > > + > > > > + tcp_send_flag(c, conn, ACK); > > > > + tcp_timer_ctl(c, conn); > > > > + > > > > + if (p->count == 1) > > > > + return 1; > > > > > > I'm not sure what this test is for. Shouldn't the continue be sufficient? > > > > I don't think we want to go through tcp_update_seqack_from_tap(), > > tcp_tap_window_update() and the like on a keep-alive segment. > > Ah, I see. But that is an optimisation, right? It shouldn't be > necessary for correctness. *Shouldn't*. > > But if we receive something else in this batch, that's going to be a > > data segment that happened to arrive just after the keep-alive, so, in > > that case, we have to do the normal processing, by ignoring just this > > segment and hitting 'continue'. > > > > Strictly speaking, the 'continue' is enough and correct, but I think > > that returning early in the obviously common case is simpler and more > > robust. > > Hrm. Doesn't seem simpler to me, but I can see the point of the > change so, The code itself is two lines longer, of course, with an additional early return. Considering all the possible side effects of looking at window values from a keep-alive segment looks to me more complicated than the alternative, though. > Reviewed-by: David Gibson -- Stefano