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.133.124]) by passt.top (Postfix) with ESMTP id 5F6785A0271 for ; Fri, 1 Mar 2024 13:31:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709296276; 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=Dv0jUKXZvIzQ3kvlE9CxFgbG0aCFSrln19CPsc4k/Pg=; b=f5RBlGA0uJnYC/ZtQFhe0IKMN/sJl+4i99VhjdbhCElqqmhtYg+ABeK/WPjTX5rRn9X5jS bxEsA5BJDPClHp8GptgzBfSUyOWf8teknmuDnyx59GoeL8+bjcCXGVxOgnG3BHG3TwBIRZ Sx3yx+0uRyNoiIYHhv6OHDGCYhdu92o= Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-382-QAA449ACMHGCBJBBMlrtbg-1; Fri, 01 Mar 2024 07:31:15 -0500 X-MC-Unique: QAA449ACMHGCBJBBMlrtbg-1 Received: by mail-qt1-f199.google.com with SMTP id d75a77b69052e-42ecb410a6bso5328331cf.1 for ; Fri, 01 Mar 2024 04:31:15 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709296274; x=1709901074; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dv0jUKXZvIzQ3kvlE9CxFgbG0aCFSrln19CPsc4k/Pg=; b=FEiearLRyynkQRN1BYvjdKhYo4BDIbVrQYe+qNI2yEYTpgdCFAS5fMpzVctZObjpEs uqUPNmcSbesQXJu7+bdSk/Wh2jdJC1ofSE8TSVJPA8ldv/hjFZt5CWeNWmqFUyDu5aVF B+L6cUqQB++acOAhZcZ/tE5qeLR2FKc3Mcz96bwbql57K5pEBFtyd+ajpWlk7OPWl9BP 0MMGlN1Yc+YD+LeVnoDhfEidr80OoCQqkzpT7sG5tloVWPrckG+/zPW4Kp1kGHPdJD9k hxvqVdN6zp99E8kKvjvUc0/IzvWPArR7QV1+nh2tSOzPoUhQ9LAk67pE/zf/odIROniz SciQ== X-Gm-Message-State: AOJu0YwaOJgZTDQL0qIURBrTlKNCFUBA7KGDt+fVdwRwZ3H7n6v6JveG OgYtzfTfffXDEJfakC5Pz8A1qG6mYktJ9SC3W6JGRKL98/R+KEYZT4D6fk1LaggJ1IuRTZxGdxQ 0hP5o1UiL4KP2Ly/133HquRDbIScR8awHsGl7VkUeBuB0mlmKlZPhGla9Gw== X-Received: by 2002:ac8:5e4c:0:b0:42e:c583:b9f1 with SMTP id i12-20020ac85e4c000000b0042ec583b9f1mr1440508qtx.39.1709296274463; Fri, 01 Mar 2024 04:31:14 -0800 (PST) X-Google-Smtp-Source: AGHT+IGuKaaK9GJXwHe6mtRBFiOl3khiBDnnx0HzQE03y+AHL7zfSZGU01E2GNgmczViB/BIicxT3g== X-Received: by 2002:ac8:5e4c:0:b0:42e:c583:b9f1 with SMTP id i12-20020ac85e4c000000b0042ec583b9f1mr1440490qtx.39.1709296274043; Fri, 01 Mar 2024 04:31:14 -0800 (PST) Received: from [192.168.100.30] ([82.142.8.70]) by smtp.gmail.com with ESMTPSA id lb27-20020a056214319b00b00690456832c8sm1810513qvb.29.2024.03.01.04.31.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 01 Mar 2024 04:31:13 -0800 (PST) Message-ID: Date: Fri, 1 Mar 2024 13:31:11 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v4 5/8] checksum: use csum_ip4_header() in udp.c and tcp.c To: David Gibson References: <20240229165955.829476-1-lvivier@redhat.com> <20240229165955.829476-6-lvivier@redhat.com> From: Laurent Vivier In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Message-ID-Hash: JQP6UUOGBQ4SWZXHR6FDXPYTULJREK5O X-Message-ID-Hash: JQP6UUOGBQ4SWZXHR6FDXPYTULJREK5O X-MailFrom: lvivier@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 3/1/24 00:25, David Gibson wrote: > On Thu, Feb 29, 2024 at 05:59:52PM +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 >> Reviewed-by: David Gibson >> --- >> >> Notes: >> v4: >> - rebase >> >> 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 > > Function comment needs to be updated for the new parameters. In > particular it needs to note that tot_len, saddr and daddr are all > passed in network order. > > As noted elsewhere, I kind of hate passing non-host-endian values in > plain integer types, but I can see why doing otherwise here would be > very awkward. Perhaps we can use __be16 and __be32 types to really show the endianness in the code? Thanks, Laurent