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=EkgungL6; 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 434D05A026E for ; Tue, 17 Sep 2024 23:54:42 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726610081; 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=fViN4yS5uEzoDhokhMEm7998nCKLmJXlZ2REm8BhUTE=; b=EkgungL6Z5LqzhuYdHjCH5amGoXZ7NTyjX6dIF1WDLqL8l69bLBZ4sOR0s14LJcjtgsh2v 42fUaC/b5T4fgRNxI2tWZPdsKnZJ17Z0AvdqziT5vwjiLki8KJ/eYntHapB3BUfkP9O/5D 0B5sCFwMnsaAlmqK+ZJp05QJtIDnwjk= Received: from mail-pl1-f198.google.com (mail-pl1-f198.google.com [209.85.214.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-668-Dt9YYFF2NiCL-p29kOepuQ-1; Tue, 17 Sep 2024 17:54:39 -0400 X-MC-Unique: Dt9YYFF2NiCL-p29kOepuQ-1 Received: by mail-pl1-f198.google.com with SMTP id d9443c01a7336-207332f7c17so56771135ad.2 for ; Tue, 17 Sep 2024 14:54:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726610079; x=1727214879; 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=fViN4yS5uEzoDhokhMEm7998nCKLmJXlZ2REm8BhUTE=; b=IExrdVYXzwoRSim2de7Ep/ntACMUIBuCWqF6Y+mAkMMKwyNTYGHRmCAyD5P8BpvMMe 0Uhxjz97YMVlmzd1L1PGDZjQsRg5YigfzECWTseJWPyQmcpYpADzf4IwSz0F0bxSbimC 7ZPnqDAiZ08a9mTZpZbVeaxP4OgdUQ9LyjC1/lwLrLBRhxHT3BkVNBLHxR4S6EEM8j39 OmF0PYmFWo2u/+6ZwmU1CX0zr45mARco0MkNzTrmxGIGt9sCiX4BtGY+mjYFKkYA5Pzy jcqmaXlOXQzFV331IS4/flFrRKcJrvebWkwnlmRw1SoQuQ5ZyA4U9+Wv4TC4Ln85Cdpe /3gw== X-Gm-Message-State: AOJu0YyAPMHF5vQYDwQvrLLq5cVEs4/f3c6QWBmwdk8iVtMzdH6oFdES muITnbxDnk1r/QzclhN83NETQh4GqxuX8zu/KVpOjNa4PmMmXVHmqaz5mChnsULel7plYdukBau CGl8ckjnph5kgRtHrkwEuZYRwIw7vZWA3Y5HdftYHemb30B3Zmg== X-Received: by 2002:a17:903:26ce:b0:206:d66d:a30d with SMTP id d9443c01a7336-2076e3155bdmr226879135ad.6.1726610078828; Tue, 17 Sep 2024 14:54:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFELNqye0AGzjRO6IaOpqAssuGboNymU+fMCm/LnxJtUOycn2ZtuMBqdhhxiWmGD8nveoirRQ== X-Received: by 2002:a17:903:26ce:b0:206:d66d:a30d with SMTP id d9443c01a7336-2076e3155bdmr226878975ad.6.1726610078359; Tue, 17 Sep 2024 14:54:38 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [176.103.220.4]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2079472cb3esm54250885ad.242.2024.09.17.14.54.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Sep 2024 14:54:37 -0700 (PDT) Date: Tue, 17 Sep 2024 23:54:34 +0200 From: Stefano Brivio To: David Gibson Subject: Re: [PATCH v2 03/10] tcp: Simplify ifdef logic in tcp_update_seqack_wnd() Message-ID: <20240917235434.22e09fef@elisabeth> In-Reply-To: <20240913043214.1753014-4-david@gibson.dropbear.id.au> References: <20240913043214.1753014-1-david@gibson.dropbear.id.au> <20240913043214.1753014-4-david@gibson.dropbear.id.au> 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-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 3RWTIHZEVG5IEK4JJ4C6OX5EBUJOL3JO X-Message-ID-Hash: 3RWTIHZEVG5IEK4JJ4C6OX5EBUJOL3JO 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 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 Fri, 13 Sep 2024 14:32:07 +1000 David Gibson wrote: > This function has a block conditional on !snd_wnd_cap shortly before an > #ifdef HAS_SND_WND. But snd_wnd_cap implies HAS_SND_WND (if !HAS_SND_WND, > snd_wnd_cap is statically false). > > Therefore, simplify this down to a single conditional with an else branch. > While we're there, fix some improperly indented closing braces. > > Signed-off-by: David Gibson > --- > tcp.c | 36 +++++++++++++++++------------------- > 1 file changed, 17 insertions(+), 19 deletions(-) > > diff --git a/tcp.c b/tcp.c > index cba3f3bd..6733e7e3 100644 > --- a/tcp.c > +++ b/tcp.c > @@ -1061,27 +1061,25 @@ int tcp_update_seqack_wnd(const struct ctx *c, struct tcp_tap_conn *conn, > conn->wnd_to_tap = MIN(new_wnd_to_tap >> conn->ws_to_tap, > USHRT_MAX); > goto out; > - } > - > - if (!tinfo) { > - if (prev_wnd_to_tap > WINDOW_DEFAULT) { > - goto out; > -} > - tinfo = &tinfo_new; > - if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) { > - goto out; > -} > - } > - > -#ifdef HAS_SND_WND > - if ((conn->flags & LOCAL) || tcp_rtt_dst_low(conn)) { > - new_wnd_to_tap = tinfo->tcpi_snd_wnd; > } else { I thought cppcheck would report else-after-goto, but it doesn't, just else-after-return. In any case, we could simplify further by avoid that else clause (and one level of indentation) in the whole block below. It would also look more natural to me: we deal with if (!snd_wnd_cap) as a special case and go to 'out' in that special case, then we resume with the regular path. I guess this is better than the original anyway and it's not a strong preference, so I can also apply this up to 4/10 as it is (or fix up on merge). The rest of the patches up to 4/10 look good to me. > - tcp_get_sndbuf(conn); > - new_wnd_to_tap = MIN((int)tinfo->tcpi_snd_wnd, > - SNDBUF_GET(conn)); > + if (!tinfo) { > + if (prev_wnd_to_tap > WINDOW_DEFAULT) { > + goto out; > + } > + tinfo = &tinfo_new; > + if (getsockopt(s, SOL_TCP, TCP_INFO, tinfo, &sl)) { > + goto out; > + } > + } > + > + if ((conn->flags & LOCAL) || tcp_rtt_dst_low(conn)) { > + new_wnd_to_tap = tinfo->tcpi_snd_wnd; > + } else { > + tcp_get_sndbuf(conn); > + new_wnd_to_tap = MIN((int)tinfo->tcpi_snd_wnd, > + SNDBUF_GET(conn)); > + } > } > -#endif > > new_wnd_to_tap = MIN(new_wnd_to_tap, MAX_WINDOW); > if (!(conn->events & ESTABLISHED)) -- Stefano