From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTP id F105B5A0274 for ; Thu, 29 Feb 2024 17:24:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709223889; 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=IUxgzb8DAnLO744pBQCtgcH7xespb4zx+erEKKj8KL4=; b=TCPrR8J4zUuVVKsFPbpt5UfWHIvjPJGLeOhcJmOZN0s98XjaRWxmTqdkPuq4prii20A+e9 PZCWy1wUNt61hHEAtMzdoVtxG/d5jubJZUdbHIBviqFuysw057+M+rpF0gWXOORlJ6b1zc zIqMAmUKemqncIK44BF4/vH9Dqn6Dwk= Received: from mail-ej1-f72.google.com (mail-ej1-f72.google.com [209.85.218.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-459-2cU2FGOnOP60TjlXIReWsg-1; Thu, 29 Feb 2024 11:24:47 -0500 X-MC-Unique: 2cU2FGOnOP60TjlXIReWsg-1 Received: by mail-ej1-f72.google.com with SMTP id a640c23a62f3a-a431a294ebeso88277566b.0 for ; Thu, 29 Feb 2024 08:24:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709223886; x=1709828686; 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=IUxgzb8DAnLO744pBQCtgcH7xespb4zx+erEKKj8KL4=; b=R4PPx7l0Gz2RIRF7PywTwmP8UGOqaYiBqb8s19T6+99jwCV2fwSBfsifXJKsnE6pbs r8I2+LZE2bHjphgOU7inw2NsISBv0r8HR7Z2TiQl5P4nzADo8UXtB3YEWCz8GaC9irSX owoN4uYck7Q1yO8oC1xEoQQm6ivsvq3IQVfuhq/nopkMq5llTJ5dn2ByE1bT807JGzND XgAwh21XSwsZ106adoArPyzbg/AeiKeiTkXNohB7Q3hghzItLhn+VLLuVW2C6cb7kKws yN5zk/G/rsu/Jmx4CKAqc0dnEekfivnywxIngE2opU7Y1dQ1v+gLO/YbE7opWhEpfeQc tgMA== X-Gm-Message-State: AOJu0YxNR8AmSZkJgAakg0sXcKVPX/1koYffXVe6tBrX7B3sGURiMyJw yYw2IrasEx4KasJ0kLGiIcUYgFZWZMsuzMZ2sGuw7QWj57Weime79L7CFanrI98v/wkHXi14ZMT +h+aYothVQuuUniw9xqsIZQT/9X934xs0F47nJa/YG2W6GVDZ4g== X-Received: by 2002:a17:906:454d:b0:a3e:9def:5ed5 with SMTP id s13-20020a170906454d00b00a3e9def5ed5mr1804255ejq.33.1709223886091; Thu, 29 Feb 2024 08:24:46 -0800 (PST) X-Google-Smtp-Source: AGHT+IEc0kkbU5JzjDrTmpEui/G9S8giDed48oLohCAUuxh+CG9vjfihCthArIliftCz6UtzlbKEhg== X-Received: by 2002:a17:906:454d:b0:a3e:9def:5ed5 with SMTP id s13-20020a170906454d00b00a3e9def5ed5mr1804237ejq.33.1709223885747; Thu, 29 Feb 2024 08:24:45 -0800 (PST) Received: from maya.cloud.tilaa.com (maya.cloud.tilaa.com. [164.138.29.33]) by smtp.gmail.com with ESMTPSA id lb24-20020a170906add800b00a4131367204sm827084ejb.80.2024.02.29.08.24.44 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Feb 2024 08:24:45 -0800 (PST) Date: Thu, 29 Feb 2024 17:24:06 +0100 From: Stefano Brivio To: Laurent Vivier , David Gibson Subject: Re: [PATCH v3 6/9] checksum: use csum_ip4_header() in udp.c and tcp.c Message-ID: <20240229172406.6a8331f1@elisabeth> In-Reply-To: <20240217150725.661467-7-lvivier@redhat.com> References: <20240217150725.661467-1-lvivier@redhat.com> <20240217150725.661467-7-lvivier@redhat.com> Organization: Red Hat X-Mailer: Claws Mail 4.2.0 (GTK 3.24.36; 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: 6WYDZBNZISIUEJKMDVILJWM64STY77F3 X-Message-ID-Hash: 6WYDZBNZISIUEJKMDVILJWM64STY77F3 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 Sat, 17 Feb 2024 16:07:22 +0100 Laurent Vivier wrote: > We can find the same function to compute the IPv4 header > checksum in tcp.c, udp.c and tap.c > > Use the function defined for tap.c, csum_ip4_header(), but > with the code used in tcp.c and udp.c as it doesn't need a fully > initialiazed IPv4 header, only protocol, tot_len, saddr and daddr. > > Signed-off-by: Laurent Vivier > --- > > Notes: > v3: > - function parameters provide tot_len, saddr, daddr and protocol > rather than an iphdr > > v2: > - use csum_ip4_header() from checksum.c > - use code from tcp.c and udp.c in csum_ip4_header() > - use "const struct iphfr *", check is not updated by the > function but by the caller. > > checksum.c | 17 +++++++++++++---- > checksum.h | 3 ++- > tap.c | 3 ++- > tcp.c | 24 +++--------------------- > udp.c | 20 ++------------------ > 5 files changed, 22 insertions(+), 45 deletions(-) > > diff --git a/checksum.c b/checksum.c > index 74e3742bc6f6..511b296a9a80 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -57,6 +57,7 @@ > #include > > #include "util.h" > +#include "ip.h" > #include "checksum.h" > > /* Checksums are optional for UDP over IPv4, so we usually just set > @@ -116,13 +117,21 @@ uint16_t csum_fold(uint32_t sum) > uint16_t csum(const void *buf, size_t len, uint32_t init); > > /** > - * csum_ip4_header() - Calculate and set IPv4 header checksum > + * csum_ip4_header() - Calculate IPv4 header checksum > * @ip4h: IPv4 header > */ > -void csum_ip4_header(struct iphdr *ip4h) > +uint16_t csum_ip4_header(uint16_t tot_len, uint8_t protocol, > + uint32_t saddr, uint32_t daddr) > { > - ip4h->check = 0; > - ip4h->check = csum(ip4h, (size_t)ip4h->ihl * 4, 0); > + uint32_t sum = L2_BUF_IP4_PSUM(protocol); Now that we use this macro, Coverity Scan realises that it's broken: #define L2_BUF_IP4_PSUM(proto) ((uint32_t)htons_constant(0x4500) + \ (uint32_t)htons_constant(0xff00 | (proto))) ...but proto is eight (lower) bits, so this actually ignores 'proto'. -- Stefano