From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 0C2705A0307 for ; Mon, 03 Jun 2024 05:08:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1717384095; bh=M3WkajY6cIl7h4xoAAYCE7UFOv6WbNy4F/26Q8+60zc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=H6Ot5iKaa0JKwkugrLwDspsEm/EZAlbluvep+pPsWqUDWLeUZd+qZLNVUXbOfG+xi QakzQ6r9C4U/JmcrrFPX/OcE+JREXujjAWNt0QSiywkghuFXnQKGdeQVsF0zweKKvg KBN7onGFf0KIrGDXADgwW/+yvJXEgnz1yqj6gWOgpGlJZRUuK8axS8+PHlWJ5efMQc dzKR1e8JJKm7lLF8D31pWkBoK4Y16E8c2sRGIIZNHYc0ka1Ljorsd6Ygh86rZ6sR1g bRCS4lgLQBtyLhM1ZaxGP8WEAW2b0KjX+UsTxQ5k4CeK4jYZJ1YHT+KAGFgmYArQ57 Db9/NN1E7a+xg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4VszFC6jQJz4wyw; Mon, 3 Jun 2024 13:08:15 +1000 (AEST) Date: Mon, 3 Jun 2024 12:54:12 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v4 05/10] udp: move udpX_l2_buf_t and udpX_l2_mh_sock out of udp_update_hdrX() Message-ID: References: <20240531142344.1420034-1-lvivier@redhat.com> <20240531142344.1420034-6-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="oh62st4WUvNE6sfZ" Content-Disposition: inline In-Reply-To: <20240531142344.1420034-6-lvivier@redhat.com> Message-ID-Hash: HXX74PUH3UY65UJMSYZJLDFNZ3TDU4PT X-Message-ID-Hash: HXX74PUH3UY65UJMSYZJLDFNZ3TDU4PT 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.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: --oh62st4WUvNE6sfZ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, May 31, 2024 at 04:23:39PM +0200, Laurent Vivier wrote: Needs a proper commit message. Also, I'm not sure the 1-line description is still accurate in this current rebased version. > Signed-off-by: Laurent Vivier > --- > udp.c | 60 +++++++++++++++++++++++++++++++++-------------------------- > 1 file changed, 34 insertions(+), 26 deletions(-) >=20 > diff --git a/udp.c b/udp.c > index 3abafc994537..4295d48046a6 100644 > --- a/udp.c > +++ b/udp.c > @@ -556,7 +556,8 @@ static void udp_splice_sendfrom(const struct ctx *c, = unsigned start, unsigned n, > /** > * udp_update_hdr4() - Update headers for one IPv4 datagram > * @c: Execution context > - * @bm: Pointer to udp_meta_t to update > + * @ip4h: Pre-filled IPv4 header (except for tot_len and saddr) > + * @s_in: Source socket address, filled in by recvmmsg() > * @bp: Pointer to udp_payload_t to update > * @dstport: Destination port number > * @dlen: Length of UDP payload > @@ -565,15 +566,16 @@ static void udp_splice_sendfrom(const struct ctx *c= , unsigned start, unsigned n, > * Return: size of IPv4 payload (UDP header + data) > */ > static size_t udp_update_hdr4(const struct ctx *c, > - struct udp_meta_t *bm, struct udp_payload_t *bp, > + struct iphdr *ip4h, const struct sockaddr_in *s_in, > + struct udp_payload_t *bp, > in_port_t dstport, size_t dlen, > const struct timespec *now) This change will definitely conflict with my upcoming UDP flow table stuff, but I think it's a good idea. So, I may end up cherry-picking this patch or an equivalent one for my series. > { > - in_port_t srcport =3D ntohs(bm->s_in.sa4.sin_port); > + in_port_t srcport =3D ntohs(s_in->sin_port); > const struct in_addr dst =3D c->ip4.addr_seen; > - struct in_addr src =3D bm->s_in.sa4.sin_addr; > + struct in_addr src =3D s_in->sin_addr; > size_t l4len =3D dlen + sizeof(bp->uh); > - size_t l3len =3D l4len + sizeof(bm->ip4h); > + size_t l3len =3D l4len + sizeof(*ip4h); > =20 > if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) && > IN4_ARE_ADDR_EQUAL(&src, &c->ip4.dns_host) && srcport =3D=3D 53 && > @@ -594,24 +596,24 @@ static size_t udp_update_hdr4(const struct ctx *c, > src =3D c->ip4.gw; > } > =20 > - bm->ip4h.tot_len =3D htons(l3len); > - bm->ip4h.daddr =3D dst.s_addr; > - bm->ip4h.saddr =3D src.s_addr; > - bm->ip4h.check =3D csum_ip4_header(l3len, IPPROTO_UDP, src, dst); > + ip4h->tot_len =3D htons(l3len); > + ip4h->daddr =3D dst.s_addr; > + ip4h->saddr =3D src.s_addr; > + ip4h->check =3D csum_ip4_header(l3len, IPPROTO_UDP, src, dst); > =20 > - bp->uh.source =3D bm->s_in.sa4.sin_port; > + bp->uh.source =3D s_in->sin_port; > bp->uh.dest =3D htons(dstport); > bp->uh.len =3D htons(l4len); > csum_udp4(&bp->uh, src, dst, bp->data, dlen); > =20 > - tap_hdr_update(&bm->taph, l3len + sizeof(udp4_eth_hdr)); > return l4len; > } > =20 > /** > * udp_update_hdr6() - Update headers for one IPv6 datagram > * @c: Execution context > - * @bm: Pointer to udp_meta_t to update > + * @ip6h: Pre-filled IPv6 header (except for payload_len and addresses) > + * @s_in: Source socket address, filled in by recvmmsg() > * @bp: Pointer to udp_payload_t to update > * @dstport: Destination port number > * @dlen: Length of UDP payload > @@ -620,13 +622,14 @@ static size_t udp_update_hdr4(const struct ctx *c, > * Return: size of IPv6 payload (UDP header + data) > */ > static size_t udp_update_hdr6(const struct ctx *c, > - struct udp_meta_t *bm, struct udp_payload_t *bp, > + struct ipv6hdr *ip6h, struct sockaddr_in6 *s_in6, > + struct udp_payload_t *bp, > in_port_t dstport, size_t dlen, > const struct timespec *now) > { > - const struct in6_addr *src =3D &bm->s_in.sa6.sin6_addr; > + const struct in6_addr *src =3D &s_in6->sin6_addr; > const struct in6_addr *dst =3D &c->ip6.addr_seen; > - in_port_t srcport =3D ntohs(bm->s_in.sa6.sin6_port); > + in_port_t srcport =3D ntohs(s_in6->sin6_port); > uint16_t l4len =3D dlen + sizeof(bp->uh); > =20 > if (IN6_IS_ADDR_LINKLOCAL(src)) { > @@ -663,19 +666,18 @@ static size_t udp_update_hdr6(const struct ctx *c, > =20 > } > =20 > - bm->ip6h.payload_len =3D htons(l4len); > - bm->ip6h.daddr =3D *dst; > - bm->ip6h.saddr =3D *src; > - bm->ip6h.version =3D 6; > - bm->ip6h.nexthdr =3D IPPROTO_UDP; > - bm->ip6h.hop_limit =3D 255; > + ip6h->payload_len =3D htons(l4len); > + ip6h->daddr =3D *dst; > + ip6h->saddr =3D *src; > + ip6h->version =3D 6; > + ip6h->nexthdr =3D IPPROTO_UDP; > + ip6h->hop_limit =3D 255; > =20 > - bp->uh.source =3D bm->s_in.sa6.sin6_port; > + bp->uh.source =3D s_in6->sin6_port; > bp->uh.dest =3D htons(dstport); > - bp->uh.len =3D bm->ip6h.payload_len; > + bp->uh.len =3D ip6h->payload_len; > csum_udp6(&bp->uh, src, dst, bp->data, dlen); > =20 > - tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + sizeof(udp6_eth_hd= r)); > return l4len; > } > =20 > @@ -708,11 +710,17 @@ static void udp_tap_send(const struct ctx *c, > size_t l4len; > =20 > if (v6) { > - l4len =3D udp_update_hdr6(c, bm, bp, dstport, > + l4len =3D udp_update_hdr6(c, &bm->ip6h, > + &bm->s_in.sa6, bp, dstport, > udp6_l2_mh_sock[i].msg_len, now); > + tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip6h) + > + sizeof(udp6_eth_hdr)); > } else { > - l4len =3D udp_update_hdr4(c, bm, bp, dstport, > + l4len =3D udp_update_hdr4(c, &bm->ip4h, > + &bm->s_in.sa4, bp, dstport, > udp4_l2_mh_sock[i].msg_len, now); > + tap_hdr_update(&bm->taph, l4len + sizeof(bm->ip4h) + > + sizeof(udp4_eth_hdr)); > } > tap_iov[i][UDP_IOV_PAYLOAD].iov_len =3D l4len; > } --=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 --oh62st4WUvNE6sfZ Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmZdMFMACgkQzQJF27ox 2Gc+kA/9Fdet18uJ6gK8JeQ3GTCqFQlqiLycxuA3I38DNlf8GukBfC6CKVn7uBmG NilkCkc1U1RbIqcmIIsQKecUe7OfKDi2mwDlcBLoDJ0bxWkHSkMruT7s+PRtCqta ip0dYqNU1tPknSGgPVktSr028gC6JNbRo1pBtYFOKQOw+RYpWKqy6wyKDUyaEkf2 Mr45s7ztKHP9pwSNQA4mKQ22KETDV+NYlLUoHkxocvhdwnSuz1rU167riA3wMkMh BAAWfbowc8mQABrtZlA+g/OBkDyXvJLVr6kzaKUqIpox99AYVuga6Z4ci+VVOFai 9iHBiGh3K/UL91fmh7tFFG3GBjbTqCQcxHdYEsTkUo8yl9mTBNsmsgWXvDug1dNP ipJSPr1ivN+/mdm6l0tkc+q50bL1AI83RZBgYNB0o8FXXqSCb919Ug6PSw5INVRc hJJH3meHJxG86OoNnLeID2rW8Eku70arNPFAoWMY1u1jzXAqzLmxLBK58DigyctC 8Wx3hcoeYoof4EzMU8vmBHqQchIJENHlndmH4FkG/Uo294DJhFUYbiKcIC8c6QSn T676BtdTHnELXVgINZAXW++BrHWdBPwlamkmJ3j1eyDecK1NhY5m1Sa9rWGhwXDR +N8DyU6CnVYutmiLDOsBZ3BZWV/NxxqrioYJ3tZBnJstsaglwOg= =TEFs -----END PGP SIGNATURE----- --oh62st4WUvNE6sfZ--