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=SbODeXlm; 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 BB1C85A004E for ; Wed, 20 Nov 2024 07:43:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732085030; 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=33QeWeGbOenPHQwmFKTkiFN4wjRmDlps7ExcqL4QuyM=; b=SbODeXlmHDLPZPJt9PH55rRF+Vr8lVBMecxx2EcQc27glEl34YRD078TbmSBHI+RcnXKZc vfY9AA+PFMIpxNDaRsswS4CPQfuT3ohnSVnqE+f79dEdDuKjDe47JCvaZIWD/Iem5XC65f ks711k5VThBZRhnH0c97iHzNCM4nnjI= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-172-dV3Q83wAOyCMKidw__XA6Q-1; Wed, 20 Nov 2024 01:43:48 -0500 X-MC-Unique: dV3Q83wAOyCMKidw__XA6Q-1 X-Mimecast-MFC-AGG-ID: dV3Q83wAOyCMKidw__XA6Q Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38233ea8c1bso235605f8f.0 for ; Tue, 19 Nov 2024 22:43:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732085027; x=1732689827; 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=33QeWeGbOenPHQwmFKTkiFN4wjRmDlps7ExcqL4QuyM=; b=Jc7wGsqxkbIXm2dsaqOt8VIwdHgYwO0mQUHlU1s6apqVSMMpCNuk7OEEVVBY2wXE2T /ugm2AuLEgi8ul6X+ht2CFkqCnl3+bzAXN29bYwGI5FaEU4ji69O1PTIcv/2SIUtCRIE f6aVEX1uAfbLV++amJ/1fmVBVQF61trLcwqD3PZKdlaRmXx4c29MQbP8r/C7XatDBGga iQ1eo4mYBWCNgOUKHWEOWHtrlE6AVQSQV7TDNysdyZYBlvdEf3H6gkvHIJlMJ5KALGTL oQoaJk6V4fHJN0IYiDv+nwFvG/129GnWbMgiihWRo8kgM4WZtxLxdKMshq49JVPyKovv /StA== X-Gm-Message-State: AOJu0Yx+eLTNmrifBC7RGcy5RFF54NB9d3FeY1Whz2gTTwLAl3G62DSN 7csmrxKHPD6dp9I/a1xy6nImmwL+pO0WzpHgqdZzDx2I0BH4VcbfSDZBgjF/ZrKZlUQ4bktTkLp iY/ZNhTgQedij5uIgfAJD5aPMZrlPE+hGlXK6mQRiwYvQ5w0jmg== X-Received: by 2002:a5d:598f:0:b0:382:48ba:631 with SMTP id ffacd0b85a97d-3824cd4fc93mr4595886f8f.22.1732085027658; Tue, 19 Nov 2024 22:43:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfChHygoQq/lTaNZ3quxAQ4ufF/j5il02L1VtcwfBrYYrkHqy3Dun98zU3AHX/BlWMb3zP1w== X-Received: by 2002:a5d:598f:0:b0:382:48ba:631 with SMTP id ffacd0b85a97d-3824cd4fc93mr4595872f8f.22.1732085027270; Tue, 19 Nov 2024 22:43:47 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b463ab2bsm7962615e9.33.2024.11.19.22.43.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Nov 2024 22:43:46 -0800 (PST) Date: Wed, 20 Nov 2024 07:43:44 +0100 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH 2/2] tcp: Acknowledge keep-alive segments, ignore them for the rest Message-ID: <20241120074344.705523be@elisabeth> In-Reply-To: References: <20241119195344.3056010-1-sbrivio@redhat.com> <20241119195344.3056010-3-sbrivio@redhat.com> 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: N_f-QQtka1PVs8JnJkvATtAIYpc38nxNAGR_Ag-hARE_1732085028 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: CP3MQXRIXW6JQKXEBPVVIOJGQQ75FDV6 X-Message-ID-Hash: CP3MQXRIXW6JQKXEBPVVIOJGQQ75FDV6 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 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. 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. -- Stefano