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=dyW7uDTN; dkim-atps=neutral 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 BAAAE5A004C for ; Wed, 25 Sep 2024 19:39:55 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1727285994; 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=OImxV8LmjerJrkAbDQoVeZcyoZl9zbS6dCxW1tsJX0Y=; b=dyW7uDTN6eHItWsR2QJA/neTd0NMPBP6WFICpW+MOPa79p5g4+bxG+jGyHnp/eMvrD8wGS o/OzvYWGL4H1uY6WgO4gzVSuV5wUcKISuciBPVWIftqCUP1w/vSJmvBIo9JqcyjwKnG8p+ H8R7g9u0FS+qZevkhbYLdr5B8a0zcRY= Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-661-sgDaV7E1MO238sAcAN6zQQ-1; Wed, 25 Sep 2024 13:39:52 -0400 X-MC-Unique: sgDaV7E1MO238sAcAN6zQQ-1 Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-205529c3402so702715ad.0 for ; Wed, 25 Sep 2024 10:39:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727285991; x=1727890791; 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=OImxV8LmjerJrkAbDQoVeZcyoZl9zbS6dCxW1tsJX0Y=; b=R+0XrfFxrCiSi6sjqU08QwaA1SjadyQXoHjUXpH+Z0JdazddLUKkvFLsOBMd3Jblox R9fOfHA50JtxNJrACLzomukpzAvROvMBBGW44CXGwUBxeNVDN6uj3GUA7nOA3Ypldrcq Few7whMnPu4T93Ta2PdUIBxDr0qofX6DWCLHjRBs+i1xRV16y89THKdCMT2Lv/yftKMU 56xdFPDgdGStihaDM8hJdlWqJ/hOW9nZGnTr+jn9zDgWZNtzucUR5BRCFU/EzafpBw+B 43sTXfo5Ge8PIqTWJau2OMLqa8ZA12A8EOZFetvsE1s+nTTrOcAl5T084RrfnWYtKdhy bN0A== X-Gm-Message-State: AOJu0YxI7/GjFCxY3Gq96jSmXEO8/XlpIzDmYCJDvkHWWeaXHLgTl7T1 J8Y6/T3V5eO4RtL+RIpJxtFPWB9THALTND3tNcRLUwOghpxLtFS/q+aMRf72zH93RYhP5ITHACG pFTvQYBka+qQfdL2YnfNkGVmLYTtHPf6qANRSZM03LnEAGYmN8YYvqKwdYZArAoVFZ2f/g9DyX2 hQQaNSSUoIGy6uEJEryPouBzcd2PlMJAGI X-Received: by 2002:a17:903:40cc:b0:205:701b:22be with SMTP id d9443c01a7336-20afc662bdamr34898845ad.56.1727285990700; Wed, 25 Sep 2024 10:39:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGoOsk/bp07D1TwZMpIUzthejKaTwk81v93ckmbsmHNcn5y1Zdg2GjD45KGaNZ9ns3Zn8EkNQ== X-Received: by 2002:a17:903:40cc:b0:205:701b:22be with SMTP id d9443c01a7336-20afc662bdamr34898575ad.56.1727285990124; Wed, 25 Sep 2024 10:39:50 -0700 (PDT) Received: from maya.myfinge.rs (ifcgrfdd.trafficplex.cloud. [2a10:fc81:a806:d6a9::1]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e6b7c7d05dsm2949720a12.91.2024.09.25.10.39.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Sep 2024 10:39:49 -0700 (PDT) Date: Wed, 25 Sep 2024 19:39:46 +0200 From: Stefano Brivio To: Laurent Vivier Subject: Re: [PATCH v2 3/4] checksum: Add an offset argument in csum_iov() Message-ID: <20240925193946.5e598a9b@elisabeth> In-Reply-To: <20240925081125.205974-4-lvivier@redhat.com> References: <20240925081125.205974-1-lvivier@redhat.com> <20240925081125.205974-4-lvivier@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-Originator: redhat.com Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Message-ID-Hash: 6Z4VHKBEJRAVIMKE2FJSUZ2X3LDVQDRJ X-Message-ID-Hash: 6Z4VHKBEJRAVIMKE2FJSUZ2X3LDVQDRJ 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 Wed, 25 Sep 2024 10:11:24 +0200 Laurent Vivier wrote: > The offset allows any headers are that are not part > of the data to checksum to be skipped. > > Signed-off-by: Laurent Vivier > --- > > Notes: > v2: > - check iov_skip_bytes() return value > > checksum.c | 16 ++++++++++++++-- > checksum.h | 3 ++- > 2 files changed, 16 insertions(+), 3 deletions(-) > > diff --git a/checksum.c b/checksum.c > index 006614fcbb28..68ffaddb5bb0 100644 > --- a/checksum.c > +++ b/checksum.c > @@ -59,6 +59,7 @@ > #include "util.h" > #include "ip.h" > #include "checksum.h" > +#include "iov.h" > > /* Checksums are optional for UDP over IPv4, so we usually just set > * them to 0. Change this to 1 to calculate real UDP over IPv4 > @@ -498,15 +499,26 @@ uint16_t csum(const void *buf, size_t len, uint32_t init) > * @iov Pointer to the array of IO vectors > * @n Length of the array > * @init Initial 32-bit checksum, 0 for no pre-computed checksum > + * @offset: Offset of the data to checksum within the full data length Nit, which I can fix up on merge: @init and @offset are swapped here. > * > * Return: 16-bit folded, complemented checksum > */ > /* cppcheck-suppress unusedFunction */ > -uint16_t csum_iov(const struct iovec *iov, size_t n, uint32_t init) > +uint16_t csum_iov(const struct iovec *iov, size_t n, size_t offset, > + uint32_t init) > { > unsigned int i; > + size_t first; > > - for (i = 0; i < n; i++) > + i = iov_skip_bytes(iov, n, offset, &first); > + if (i >= n) > + return (uint16_t)~csum_fold(init); > + > + init = csum_unfolded((char *)iov[i].iov_base + first, > + iov[i].iov_len, init); > + i++; > + > + for (; i < n; i++) > init = csum_unfolded(iov[i].iov_base, iov[i].iov_len, init); I wonder if this could become: for (i = iov_skip_bytes(iov, n, offset, &start); i < n; i++) { init = csum_unfolded((char *)iov[i].iov_base + start, iov[i].iov_len, init); start = 0; } return (uint16_t)~csum_fold(init); ...but I haven't tested it and didn't really think it through. I'm fine with the original version too. -- Stefano