From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202502 header.b=dELjiY5C; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id D89F35A0777 for ; Mon, 24 Feb 2025 03:21:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1740363705; bh=Sbrjr9RtGYVjW0cdR1NxyE2KNnwnC7kqk8wwLLezvqk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=dELjiY5CRhgGMI599LJ6xem2ak0KDVijL//hvE7bgFRBKXnskm/olhM9Bpbh09NBA q42IqdRSw05hHmJyrePVf7ZuVjZSR5wBvdAg/jVpP4j7qlMUcxHIWacTp49RiVjYzi ysO7M2d3kRb591GtENORIY1pPFHfErbXvQ+S4Ig3V7hI++EdivHA21qS0biF8ZSBMI gntNoa6RVayJGMdHftGvCrAg0qObPf3ALwRfIV12LwDeTgVxdLeQcoxBxy6juolc/x sCGPKOpbqMZyXesfZTvRe0FDiuI8ohM+789DmxiJnnumD9ltyrMqH4l7A8vIXf3WHc oeSgGn6de0h1Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Z1Pcn3MQmz4wb0; Mon, 24 Feb 2025 13:21:45 +1100 (AEDT) Date: Mon, 24 Feb 2025 13:16:23 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v5 3/4] tap: break out building of udp header from tap_udp6_send function Message-ID: References: <20250223225951.3534010-1-jmaloy@redhat.com> <20250223225951.3534010-4-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="kul0kq8xG5uVP9pa" Content-Disposition: inline In-Reply-To: <20250223225951.3534010-4-jmaloy@redhat.com> Message-ID-Hash: SP33E2XPMYSQUSOMOKBS765GPNLPISHV X-Message-ID-Hash: SP33E2XPMYSQUSOMOKBS765GPNLPISHV 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, sbrivio@redhat.com, lvivier@redhat.com, dgibson@redhat.com 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: --kul0kq8xG5uVP9pa Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 23, 2025 at 05:59:50PM -0500, Jon Maloy wrote: > We will need to build the UDP header at other locations than in function > tap_udp6_send(), so we break that part out to a separate function. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson =2E..minus one nit. > --- > tap.c | 40 ++++++++++++++++++++++++++++++---------- > tap.h | 4 ++++ > 2 files changed, 34 insertions(+), 10 deletions(-) >=20 > diff --git a/tap.c b/tap.c > index 3daba28..380a7b9 100644 > --- a/tap.c > +++ b/tap.c > @@ -266,7 +266,7 @@ static void *tap_push_ip6h(struct ipv6hdr *ip6h, > } > =20 > /** > - * tap_udp6_send() - Send UDP over IPv6 packet > + * tap_push_uh6() - Build UDPv6 header with checksum > * @c: Execution context > * @src: IPv6 source address > * @sport: UDP source port > @@ -276,19 +276,14 @@ static void *tap_push_ip6h(struct ipv6hdr *ip6h, > * @in: UDP payload contents (not including UDP header) > * @dlen: UDP payload length (not including UDP header) > */ > -void tap_udp6_send(const struct ctx *c, > +void *tap_push_uh6(struct udphdr *uh, > const struct in6_addr *src, in_port_t sport, > const struct in6_addr *dst, in_port_t dport, > - uint32_t flow, void *in, size_t dlen) > + void *in, size_t dlen) > { > size_t l4len =3D dlen + sizeof(struct udphdr); > - char buf[USHRT_MAX]; > - struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, ETH_P_IPV6); > - struct udphdr *uh =3D tap_push_ip6h(ip6h, src, dst, > - l4len, IPPROTO_UDP, flow); > - char *data =3D (char *)(uh + 1); > const struct iovec iov =3D { > - .iov_base =3D in, > + .iov_base =3D (void *)in, 'in' is already a void * so the cast is not necessary (even ignoring the fact that you can generall coerce to and from void * without a cast). > .iov_len =3D dlen > }; > struct iov_tail payload =3D IOV_TAIL(&iov, 1, 0); > @@ -297,8 +292,33 @@ void tap_udp6_send(const struct ctx *c, > uh->dest =3D htons(dport); > uh->len =3D htons(l4len); > csum_udp6(uh, src, dst, &payload); > - memcpy(data, in, dlen); > + return uh + 1; > +} > + > +/** > + * tap_udp6_send() - Send UDP over IPv6 packet > + * @c: Execution context > + * @src: IPv6 source address > + * @sport: UDP source port > + * @dst: IPv6 destination address > + * @dport: UDP destination port > + * @flow: Flow label > + * @in: UDP payload contents (not including UDP header) > + * @dlen: UDP payload length (not including UDP header) > + */ > +void tap_udp6_send(const struct ctx *c, > + const struct in6_addr *src, in_port_t sport, > + const struct in6_addr *dst, in_port_t dport, > + uint32_t flow, void *in, size_t dlen) > +{ > + size_t l4len =3D dlen + sizeof(struct udphdr); > + char buf[USHRT_MAX]; > + struct ipv6hdr *ip6h =3D tap_push_l2h(c, buf, ETH_P_IPV6); > + struct udphdr *uh =3D tap_push_ip6h(ip6h, src, dst, > + l4len, IPPROTO_UDP, flow); > + char *data =3D tap_push_uh6(uh, src, sport, dst, dport, in, dlen); > =20 > + memcpy(data, in, dlen); > tap_send_single(c, buf, dlen + (data - buf)); > } > =20 > diff --git a/tap.h b/tap.h > index 37da21d..b7b8cef 100644 > --- a/tap.h > +++ b/tap.h > @@ -47,6 +47,10 @@ static inline void tap_hdr_update(struct tap_hdr *thdr= , size_t l2len) > void *tap_push_uh4(struct udphdr *uh, struct in_addr src, in_port_t spor= t, > struct in_addr dst, in_port_t dport, > const void *in, size_t dlen); > +void *tap_push_uh6(struct udphdr *uh, > + const struct in6_addr *src, in_port_t sport, > + const struct in6_addr *dst, in_port_t dport, > + void *in, size_t dlen); > void *tap_push_ip4h(struct iphdr *ip4h, struct in_addr src, > struct in_addr dst, size_t l4len, uint8_t proto); > void tap_udp4_send(const struct ctx *c, struct in_addr src, in_port_t sp= ort, --=20 David Gibson (he or they) | 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 --kul0kq8xG5uVP9pa Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAme71nYACgkQzQJF27ox 2Gda2xAAmBDiiG9AKh7E/3kABrUlKtqpmx6o7aUnbETg7d0VQBoEgIg3BaNXIZiu kLG7epSO9MU3AMJI4pdA1oEwCIwluDzPN5ga7Xn77m3BWNOKx7MgQcYgTDZ3ChCj QMUgrSbAVw1IcnX971MC+JwHx8lxdIyyTmbY99JR8fyNaanqz+tXk7OZgFCOAWW/ vFFLQ/7rHjqxmB9fcrY01TAHghcqT73HwyWKtsGD0nmCpkomciyLmEHpB07+yxJ8 auVMY4P5GrmIkyujjj4e83ePYXAIxwdkaeLIpYRmSaEy8xqhaAkAwaDaH1o8sHL9 1/L5Nqt4VNl+303eBlc1vcFv8+Duq7ruosFM+UF3GV5MhaQ42WqfOUeNoEZ7Mj5O +FIFd6ZFhL2UKYFb2+WgC39gRcdcedBl5fMyTGpy8c3cmTZdbgtdqLVmf1dK/1xo v0xQCS0ymQOx6XXsNK5LyArvyhyaWfYmFEN3JG3KXMyWKvYR7fhuJo/3XbBmkBCJ Ax458NwxnbXeUAqc+rxeyObpaCut+c05rAZtVjeyZLbvYw69hU3BOaXNyjcdVHXl Lh0ns1jvUQLOrYtnJs9hXxB1n5xuvJrpcDVh9ocksnFidWKV07/a2sv/GyC6oDFC htOekL59dpDCIIrgQMLbZujhG2vd6gHqJAmU2+bLT0odL/G15mM= =h0Zp -----END PGP SIGNATURE----- --kul0kq8xG5uVP9pa--