From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 6E4015A0267 for ; Tue, 18 Oct 2022 14:08:11 +0200 (CEST) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4MsCLH4Ssjz4xGc; Tue, 18 Oct 2022 23:08:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1666094887; bh=ZRhSeYtvI7JRZR+umsKQ/vBo29aiTnY54d3Rvi8X53U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=k+WePrmnf63XdRcESqraUiyqYjaR9Mi6Rugrxi4eP9Hu/YCN7fk+wHlRHWSx+7+LO 0n3DAdqdk+7KmaqXjcI+wZv1QWKdD6DtoW52lK9jFZEgBWpIgN2cAU4IUt5ENlTUfU h+d1MEION7PdKojyvkf6hmbVzgay7jOpdW5dGT6U= Date: Tue, 18 Oct 2022 23:06:28 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 03/14] Add csum_udp6() helper for calculating UDP over IPv6 checksums Message-ID: References: <20221017085807.473470-1-david@gibson.dropbear.id.au> <20221017085807.473470-4-david@gibson.dropbear.id.au> <20221018050231.22a9f79d@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="r1iXPeKWf9Zrmcpn" Content-Disposition: inline In-Reply-To: <20221018050231.22a9f79d@elisabeth> Message-ID-Hash: WRFT3ZJA5D4C352ERDIWV7OVLW7HGC4E X-Message-ID-Hash: WRFT3ZJA5D4C352ERDIWV7OVLW7HGC4E X-MailFrom: dgibson@gandalf.ozlabs.org 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.3 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: --r1iXPeKWf9Zrmcpn Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Oct 18, 2022 at 05:02:31AM +0200, Stefano Brivio wrote: > On Mon, 17 Oct 2022 19:57:56 +1100 > David Gibson wrote: >=20 > > Add a helper for calculating UDP checksums when used over IPv6 > > For future flexibility, the new helper takes parameters for the fields = in > > the IPv6 pseudo-header, so an IPv6 header or pseudo-header doesn't need= to > > be explicitly constructed. It also allows the UDP header and payload to > > be in separate buffers, although we don't use this yet. > >=20 > > Signed-off-by: David Gibson > > --- > > checksum.c | 23 +++++++++++++++++++++++ > > checksum.h | 5 +++++ > > tap.c | 5 ++--- > > 3 files changed, 30 insertions(+), 3 deletions(-) > >=20 > > diff --git a/checksum.c b/checksum.c > > index c8b6b42..0849fb1 100644 > > --- a/checksum.c > > +++ b/checksum.c > > @@ -52,6 +52,7 @@ > > #include > > #include > > =20 > > +#include > > #include > > #include > > =20 > > @@ -122,6 +123,28 @@ void csum_icmp4(struct icmphdr *icmp4hr, const voi= d *payload, size_t len) > > icmp4hr->checksum =3D csum_unaligned(payload, len, hrsum); > > } > > =20 > > +/** > > + * csum_udp6() - Calculate checksum for a UDP over IPv6 packet >=20 > Calculate and set. Done. > > + * @udp6hr: UDP header, initialized apart from checksum >=20 > -ised. Done. > > + * @payload: UDP packet payload > > + * @len: Length of @payload (not including UDP header) > > + */ > > +void csum_udp6(struct udphdr *udp6hr, > > + const struct in6_addr *saddr, > > + const struct in6_addr *daddr, >=20 > You could use some horizontal space. Done. > > + const void *payload, size_t len) > > +{ > > + /* Partial checksum for the pseudo-IPv6 header */ > > + uint32_t psum =3D sum_16b(saddr, sizeof(*saddr)) + > > + sum_16b(daddr, sizeof(*daddr)) + > > + htons(len + sizeof(*udp6hr)) + htons(IPPROTO_UDP); >=20 > Alignment: >=20 > uint32_t psum =3D sum_16b(saddr, sizeof(*saddr)) + > sum_16b(daddr, sizeof(*daddr)) + > htons(len + sizeof(*udp6hr)) + htons(IPPROTO_UDP); Done. > > + udp6hr->check =3D 0; > > + /* Add in partial checksum for the UDP header alone */ > > + psum +=3D sum_16b(udp6hr, sizeof(*udp6hr)); > > + udp6hr->check =3D csum_unaligned(payload, len, psum); > > +} > > + > > /** > > * csum_icmp6() - Calculate checksum for an ICMPv6 packet > > * @icmp6hr: ICMPv6 header, initialized apart from checksum > > diff --git a/checksum.h b/checksum.h > > index ff95cf9..1b9f48e 100644 > > --- a/checksum.h > > +++ b/checksum.h > > @@ -6,6 +6,7 @@ > > #ifndef CHECKSUM_H > > #define CHECKSUM_H > > =20 > > +struct udphdr; > > struct icmphdr; > > struct icmp6hdr; > > =20 > > @@ -13,6 +14,10 @@ uint32_t sum_16b(const void *buf, size_t len); > > uint16_t csum_fold(uint32_t sum); > > uint16_t csum_unaligned(const void *buf, size_t len, uint32_t init); > > void csum_icmp4(struct icmphdr *ih, const void *payload, size_t len); > > +void csum_udp6(struct udphdr *udp6hr, > > + const struct in6_addr *saddr, > > + const struct in6_addr *daddr, > > + const void *payload, size_t len); >=20 > Use some horizontal space. Done. > > void csum_icmp6(struct icmp6hdr *ih, > > const struct in6_addr *saddr, > > const struct in6_addr *daddr, > > diff --git a/tap.c b/tap.c > > index f082901..9c197cb 100644 > > --- a/tap.c > > +++ b/tap.c > > @@ -183,9 +183,8 @@ void tap_ip_send(const struct ctx *c, const struct = in6_addr *src, uint8_t proto, > > } else if (proto =3D=3D IPPROTO_UDP) { > > struct udphdr *uh =3D (struct udphdr *)(ip6h + 1); > > =20 > > - uh->check =3D 0; > > - uh->check =3D csum_unaligned(ip6h, len + sizeof(*ip6h), > > - 0); > > + csum_udp6(uh, &ip6h->saddr, &ip6h->daddr, > > + uh + 1, len - sizeof(*uh)); > > } else if (proto =3D=3D IPPROTO_ICMPV6) { > > struct icmp6hdr *ih =3D (struct icmp6hdr *)(ip6h + 1); > > =20 >=20 --=20 David Gibson | I'll have my music baroque, and my code david AT gibson.dropbear.id.au | minimalist, thank you. NOT _the_ _other_ | _way_ _around_! http://www.ozlabs.org/~dgibson --r1iXPeKWf9Zrmcpn Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEoULxWu4/Ws0dB+XtgypY4gEwYSIFAmNOlr4ACgkQgypY4gEw YSIOUxAApGjTxamBY+9m+6tNGc3ZI5XgJbS0cHPEZpGjMrCi6L+EfswOnjWte4CB uTd8KpAY0UYW5xD6tqdmEnZAr8PgC9fv678dXEkSDbXO04QlZiN2rcJRE4pgScqg zuFWoiHDkiPdju8LlmlfX4V4hu/hMehoCW4gU+n7XwQ89IDZu0GTkPdTHLH1cpsq pmI4DxanjUUuPg38FyejpNS7sdqQXSLzxbJF7YSsCipXzC+TDRqPtH07nXJTI0je aopnoOhwnyGI8cT+zdbIB4XyqyWpl7hCaUNr06gw2Pt+/v4a8QBAQlEceo5+pUsM z64wJ+og5UUurBVIJAiuKtfmKbIHc7rcTWRDuEcsd39vjc9/jtdj3cH1r5vykxs1 zLaMCybPpgweaBCexrtWgi0OWNc5/epCeIOBkykl/4HW3V4xir+B/eRSlDCqXFSf q7n0+l1NJGn6WxYa2mOYFoLh7zhj6hFX5wVL390prgqOfFMpZj99ne4prfODJstC SWHOyzf4qLcoMrcVLSzgpCGAiMv1qsNCFt/0Ys4wyrv4lbAe2/uApItQlvOYbSQs RQ6Oeju2EWZ+zTCgcTw/dJEXrpQaCy4Bb/JTBIXaOBClg+DaQ0v5ZgkEOHaNL4fK lX3auP285wrtZg+XKDj+kyjEGjrBSVG0QGLC9TUcej8txogav8E= =mawe -----END PGP SIGNATURE----- --r1iXPeKWf9Zrmcpn--