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=f/GpfMj3; 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 7BC515A061C for ; Thu, 21 Nov 2024 05:30:53 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732163452; 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=yvNCxkk4epShv1UJiAFo5EEz8gzUV3XPsmyXYSefchk=; b=f/GpfMj3fwftLI+s7fH3GGc82kbV6K+PgQ3VVPxeLKMHkLM2QF+/tUtAizWh4qWAlaTxG0 rLu05/HhpeSZ8vUSTjkXFU56H9BtHN34h+6uk6/DEIsPutDPJsROw2GxwGJM0ZUzQxJ0R6 uegNJgZETlc3AZuicIiCA/vuUWkrZ8Y= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-554-2oN0gOu3O-yz8E2R6ehB-w-1; Wed, 20 Nov 2024 23:30:51 -0500 X-MC-Unique: 2oN0gOu3O-yz8E2R6ehB-w-1 X-Mimecast-MFC-AGG-ID: 2oN0gOu3O-yz8E2R6ehB-w Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-431604a3b47so2945105e9.3 for ; Wed, 20 Nov 2024 20:30:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1732163449; x=1732768249; 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=yvNCxkk4epShv1UJiAFo5EEz8gzUV3XPsmyXYSefchk=; b=nZBcGrXhlRnlXOh+dzrFVdVFvA2bDiO41w3Ca+oTR6B9zgffE61d9HyE+V2DWwqDL7 1iwwEOTiK96QedFngJp6PRbshHjGuSjJHhe2KXbxcV4goSqLFyzP1eOzTEKLWZamiPtX 3n6gz83ph6faI15qtdXItK0/XErseGWL7fa0yag6NzZ202IJLMWI6zDzIlMwYBEfsjM9 iavtpdciSab1d1//eSvmV1ig8WaMkabJteM+RH2iO03dnHwfjDhiK8tj0BWtd76fpRwP Nk+jVCsFszo7hEQOZ8AB3HrVFoYqlEEhQ5yfKnjJWJ/7ylDyVNLG+83nf187Fdd241je ekQg== X-Gm-Message-State: AOJu0YznJB+8hrpUYLXggNDDDQ2sADJt4O6WGiBP4dD3f2eP52pyq2ct HHiJCqv2yYg/CJd/MM5Ea1paG+/vVc7UgXhZ67958dPsgk3DDLjH3XDZs2lFtuyXDfrwcvKsEsQ oV/t1XH4quITTeyooKbv7M4ln+IHb2scMI037rtcbL2qEQTbVMlU2b7ZjtQ== X-Gm-Gg: ASbGncuvONM5YjwGvnsaXqitQyO4QMEon1cusYId4syDLsmFDvQeGWMmZte6q0ecCVK 4zQmyUbNnJwHC61P8tK22ZcmqnXoXIOFMQmpCWWNuzjrY3+AsSWH7MwJw0hA2qGUK93TkcEd1VU FFIV++UGnD+6HGkEFxB6UJTZfd4LSzEqclpWQrBbLp12vB41J/TlesXhD1AJbcjEUenkFgDVEqa Fk8Bc1AgIb63p4Q7RKsEeG17vFkXGIsmq7gJR+IxPFfKw/XSa4roOgNc3lw/A== X-Received: by 2002:a5d:47af:0:b0:382:424b:d0a6 with SMTP id ffacd0b85a97d-38254b291e2mr3737604f8f.55.1732163448633; Wed, 20 Nov 2024 20:30:48 -0800 (PST) X-Google-Smtp-Source: AGHT+IFrbGuqby3hWRED6olkHHKH7GoXcKjzHNGPfEo4M5LghJC1MOzjZrtfuQsKIRtFEo3DuS92Qg== X-Received: by 2002:a5d:47af:0:b0:382:424b:d0a6 with SMTP id ffacd0b85a97d-38254b291e2mr3737588f8f.55.1732163448263; Wed, 20 Nov 2024 20:30:48 -0800 (PST) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-433b463ab44sm41077115e9.30.2024.11.20.20.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Nov 2024 20:30:47 -0800 (PST) Date: Thu, 21 Nov 2024 05:30: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: <20241121053044.1e817b53@elisabeth> In-Reply-To: <20241121052617.50cf96ef@elisabeth> 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: h143FHOoHtbC1QS3d3xVMbaPK9kaMXyYCfdWHfjLtOs_1732163450 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: VYI4AN65MTDDG35FHLMCG7XGU45CD2NS X-Message-ID-Hash: VYI4AN65MTDDG35FHLMCG7XGU45CD2NS 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 05:26:17 +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 ^ lonely, I should say > than the alternative, though. > > > Reviewed-by: David Gibson -- Stefano