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=A319TTNz; 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 A24CB5A061B for ; Thu, 21 Nov 2024 10:23:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732180999; 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=vCQS/MoHl9RWsMZzmqpgcMi1zykiln74dim5+Jl+Tl0=; b=A319TTNzls0T7SeVctSxxJfMj2+7fbbFZW2pIeJj4PM7N/DBou0gPX0Y0OLxi3hYsAQQAN gdaN12h8tD268bg9fi4KFQY0iPfau1BgAAh2TFsMUWEaR0xY+MOS5n7wAyZWci+DEAsZgk Pkx5n/zRKjbnV6SiaU6TVuk9vwmFP9U= Received: from mail-lf1-f69.google.com (mail-lf1-f69.google.com [209.85.167.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-468-yQFKU_xJOXqaHNhjEJWsXA-1; Thu, 21 Nov 2024 04:23:18 -0500 X-MC-Unique: yQFKU_xJOXqaHNhjEJWsXA-1 X-Mimecast-MFC-AGG-ID: yQFKU_xJOXqaHNhjEJWsXA Received: by mail-lf1-f69.google.com with SMTP id 2adb3069b0e04-53da09b1ca1so395130e87.3 for ; Thu, 21 Nov 2024 01:23:17 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732180996; x=1732785796; 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=vCQS/MoHl9RWsMZzmqpgcMi1zykiln74dim5+Jl+Tl0=; b=Jtm93BN7/UJUCh3W+GOsnz4jgrKmmEq370Ju1cVb3KF3ClNZu2xwPz0oxhXrn2Kwyn ijii8aVWJEWxuD2HWEwFmDv9fW3UshjTez2Evlz4Jk0gfZhFlYQjVD7iIDAapk5A9Lh+ 2DaJ2Bo3XhhLADGKYgRSDPpsWGh+WmfCUsY7zwSexcjkaBpPVQNL39Ik5pgl7piR0v8e cIS+uYHV5YUy1z2t9vYf1DdD9XCiPzOvDzv9YNf4kdvSiDphHFTii/7cMkY4sdwEv4ov ojdMCdcRAAdSaMUu6oj4nhTNB+4h0ZUhAZwY7n1iy6PXPqa+3QOg4kVWrK6zwwrHisCq DA5Q== X-Gm-Message-State: AOJu0YzXWK6fS32o35KU+/oS22r9XdYMZMkabwcNj0HbWfWIT3zL0+SJ x68IWR+4/Gb8F6gHytAOZ8Dsu39fzBUd0JvbHbxoxT9dN5bL9Lr1zDMzBkNqSPgPKfDY/bgEN+O M2rmHfFeESSbbYvTOidimD/2DzJmJSYjAxKq/A0wmsXdvr+KGDg== X-Gm-Gg: ASbGnctFYKb/QQkhF1B+sj46NuUKW6zAnWyxG5y0pYAv6n6ge6Daco2nMMZRV5EW5Lc 2mEck9N/xCeThJD+O0E/cWqN6kpZZTqB0bTCrPKHFOEKNM6IQmTFJF+xpNkwo+wntDb66VtmoXF DY5xcmGQnDYrTwkiQSGsm+r3oEtn50ld1TWWFOicNXuq4fKT4vOlqH9+MIuLMtLN69VJ/cHLQsJ buFVhJKfjjwJfnag2dLIxrJ0DpwYFUn4RLZNSiCiSvePBc/dLhPfG6bEvSCIjenM2ZY/yjNC+V/ daM= X-Received: by 2002:a05:6512:baa:b0:53d:a8cd:4285 with SMTP id 2adb3069b0e04-53dc136cf1amr2385791e87.39.1732180996341; Thu, 21 Nov 2024 01:23:16 -0800 (PST) X-Google-Smtp-Source: AGHT+IEh/xfmwoK5R672NAIzdGYUnxsJZCCKjft49hN7lNLZSdy4aCvd0/tMA0SXyKptV3UFhZnBdQ== X-Received: by 2002:a05:6512:baa:b0:53d:a8cd:4285 with SMTP id 2adb3069b0e04-53dc136cf1amr2385778e87.39.1732180995882; Thu, 21 Nov 2024 01:23:15 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b45fa728sm47394595e9.14.2024.11.21.01.23.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Nov 2024 01:23:15 -0800 (PST) Date: Thu, 21 Nov 2024 10:23:12 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/2] tcp: Acknowledge keep-alive segments, ignore them for the rest Message-ID: <20241121102312.156af880@elisabeth> In-Reply-To: References: <20241119195344.3056010-1-sbrivio@redhat.com> <20241119195344.3056010-3-sbrivio@redhat.com> <20241120074344.705523be@elisabeth> <20241121052617.50cf96ef@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: fdcwSCCZD3aekdchepj-PFvRDpvUvvLtbwNzEoQqeoo_1732180997 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: EKUEXEKERBDUQ4OBUX2E3SE7ZORZP6YZ X-Message-ID-Hash: EKUEXEKERBDUQ4OBUX2E3SE7ZORZP6YZ 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 17:21:12 +1100 David Gibson wrote: > On Thu, Nov 21, 2024 at 05:26:17AM +0100, Stefano Brivio wrote: > > 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. > > Except that we *will* consider them if there happen to be other data > packets in the batch. Eh, yes, we have to: > > > > 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'. but we'll use _those_ window values (because we 'continue' here). > That seems like it will just make any problems > from processing the keepalive sequence values harder to track down, > not make them go away. We tested the common case (perhaps we'll never get anything else) and my priority would be to make _that_ robust, because it's what matters to users. If we find the time to write a small keep-alive sending program, then I would feel more confident to drop that additional condition. -- Stefano