From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 706DB5A026F for ; Mon, 4 Mar 2024 01:55:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709513695; bh=xMsigrU/gIiQ3Y1BBmssVTv8IXY2zxZkxn+O8O/5DvI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X6fJ/WQq7ZcL5Ln8V7KSyhp7J14gARapF0I/ZSE4ven5JuKqC//2cFsCv9yhtrU9+ WKyAl8cF9DuleU2Mg5zuoMekyj6CPsaS3cHg0108OPe+lWurPpPQj0tPpSG00+PBwa vTiQ1/HDbEmjI0kD0Fr6JyR+SO4Exu5zGWiEWm7mkf2J6k5lGDBME+gSCjjYZ5A9Z1 a53kPD/b1xIufUV1epge7nOyoGO+LFEfwzJawLzB9ipTqKsMUBuOuHIP0gr+2lcK/r KTFtiijPXPIfYbOjMYQqpeTsiHdL41MW/XNQ6BR6sicpMLJIRX7kvzJ7C5guoG+OUM WdTIIpjvl/9Nw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Tp0bM6lyMz4wp0; Mon, 4 Mar 2024 11:54:55 +1100 (AEDT) Date: Mon, 4 Mar 2024 11:46:25 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v5 5/9] udp: little cleanup in udp_update_hdrX() to prepare future changes Message-ID: References: <20240303135114.1023026-1-lvivier@redhat.com> <20240303135114.1023026-6-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="cIHVS0AWeSXrYSCp" Content-Disposition: inline In-Reply-To: <20240303135114.1023026-6-lvivier@redhat.com> Message-ID-Hash: JID236OLPPHWZOJURZNY7VNDRC7FPHB2 X-Message-ID-Hash: JID236OLPPHWZOJURZNY7VNDRC7FPHB2 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: --cIHVS0AWeSXrYSCp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Mar 03, 2024 at 02:51:10PM +0100, Laurent Vivier wrote: > in udp_update_hdr4(): >=20 > Assign the source address to src, either b->s_in.sin_addr, > c->ip4.dns_match or c->ip4.gw and then set b->iph.saddr to src->s_add= r. >=20 > in udp_update_hdr6(): >=20 > Assign the source address to src, either b->s_in6.sin6_addr, > c->ip6.dns_match, c->ip6.gw or c->ip6.addr_ll. > Assign the destination to dst, either c->ip6.addr_seen or > &c->ip6.addr_ll_seen. > Then set dst to b->ip6h.daddr and src to b->ip6h.saddr. >=20 > Signed-off-by: Laurent Vivier Heh, this does something quite similar to one of the patches in my small udp cleanups series. Reviewed-by: David Gibson I don't want to delay this further, so I'll rebase my other UDP work on top of this. > --- >=20 > Notes: > v5: > - new patch to introduce the use of struct in_addr with > csum_ip4_header() >=20 > udp.c | 39 +++++++++++++++++++-------------------- > 1 file changed, 19 insertions(+), 20 deletions(-) >=20 > diff --git a/udp.c b/udp.c > index 26774df7018c..2b41a1bdff61 100644 > --- a/udp.c > +++ b/udp.c > @@ -588,7 +588,7 @@ static size_t udp_update_hdr4(const struct ctx *c, in= t n, in_port_t dstport, > const struct timespec *now) > { > struct udp4_l2_buf_t *b =3D &udp4_l2_buf[n]; > - struct in_addr *src; > + const struct in_addr *src; > in_port_t src_port; > size_t ip_len; > =20 > @@ -602,10 +602,9 @@ static size_t udp_update_hdr4(const struct ctx *c, i= nt n, in_port_t dstport, > =20 > if (!IN4_IS_ADDR_UNSPECIFIED(&c->ip4.dns_match) && > IN4_ARE_ADDR_EQUAL(src, &c->ip4.dns_host) && src_port =3D=3D 53) { > - b->iph.saddr =3D c->ip4.dns_match.s_addr; > + src =3D &c->ip4.dns_match; > } else if (IN4_IS_ADDR_LOOPBACK(src) || > IN4_ARE_ADDR_EQUAL(src, &c->ip4.addr_seen)) { > - b->iph.saddr =3D c->ip4.gw.s_addr; > udp_tap_map[V4][src_port].ts =3D now->tv_sec; > udp_tap_map[V4][src_port].flags |=3D PORT_LOCAL; > =20 > @@ -615,9 +614,10 @@ static size_t udp_update_hdr4(const struct ctx *c, i= nt n, in_port_t dstport, > udp_tap_map[V4][src_port].flags &=3D ~PORT_LOOPBACK; > =20 > bitmap_set(udp_act[V4][UDP_ACT_TAP], src_port); > - } else { > - b->iph.saddr =3D src->s_addr; > + > + src =3D &c->ip4.gw; > } > + b->iph.saddr =3D src->s_addr; > =20 > udp_update_check4(b); > b->uh.source =3D b->s_in.sin_port; > @@ -640,10 +640,11 @@ static size_t udp_update_hdr6(const struct ctx *c, = int n, in_port_t dstport, > const struct timespec *now) > { > struct udp6_l2_buf_t *b =3D &udp6_l2_buf[n]; > - struct in6_addr *src; > + const struct in6_addr *src, *dst; > in_port_t src_port; > size_t ip_len; > =20 > + dst =3D &c->ip6.addr_seen; > src =3D &b->s_in6.sin6_addr; > src_port =3D ntohs(b->s_in6.sin6_port); > =20 > @@ -652,23 +653,14 @@ static size_t udp_update_hdr6(const struct ctx *c, = int n, in_port_t dstport, > b->ip6h.payload_len =3D htons(udp6_l2_mh_sock[n].msg_len + sizeof(b->uh= )); > =20 > if (IN6_IS_ADDR_LINKLOCAL(src)) { > - b->ip6h.daddr =3D c->ip6.addr_ll_seen; > - b->ip6h.saddr =3D b->s_in6.sin6_addr; > + dst =3D &c->ip6.addr_ll_seen; > } else if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.dns_match) && > IN6_ARE_ADDR_EQUAL(src, &c->ip6.dns_host) && > src_port =3D=3D 53) { > - b->ip6h.daddr =3D c->ip6.addr_seen; > - b->ip6h.saddr =3D c->ip6.dns_match; > + src =3D &c->ip6.dns_match; > } else if (IN6_IS_ADDR_LOOPBACK(src) || > IN6_ARE_ADDR_EQUAL(src, &c->ip6.addr_seen) || > IN6_ARE_ADDR_EQUAL(src, &c->ip6.addr)) { > - b->ip6h.daddr =3D c->ip6.addr_ll_seen; > - > - if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw)) > - b->ip6h.saddr =3D c->ip6.gw; > - else > - b->ip6h.saddr =3D c->ip6.addr_ll; > - > udp_tap_map[V6][src_port].ts =3D now->tv_sec; > udp_tap_map[V6][src_port].flags |=3D PORT_LOCAL; > =20 > @@ -683,10 +675,17 @@ static size_t udp_update_hdr6(const struct ctx *c, = int n, in_port_t dstport, > udp_tap_map[V6][src_port].flags &=3D ~PORT_GUA; > =20 > bitmap_set(udp_act[V6][UDP_ACT_TAP], src_port); > - } else { > - b->ip6h.daddr =3D c->ip6.addr_seen; > - b->ip6h.saddr =3D b->s_in6.sin6_addr; > + > + dst =3D &c->ip6.addr_ll_seen; > + > + if (IN6_IS_ADDR_LINKLOCAL(&c->ip6.gw)) > + src =3D &c->ip6.gw; > + else > + src =3D &c->ip6.addr_ll; > + > } > + b->ip6h.daddr =3D *dst; > + b->ip6h.saddr =3D *src; > =20 > b->uh.source =3D b->s_in6.sin6_port; > b->uh.dest =3D htons(dstport); --=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 --cIHVS0AWeSXrYSCp Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXlGdwACgkQzQJF27ox 2GcmrA/5AdaLtZFXsmbi3sf4VzdEtQ72BHrk60DqrK0HJIRg6cd0v3LZI4gyH5V7 /o/xD8TmrEjH8nH3BMcqkIm7nGmlMnskv8Ed2M6RhuiVkQ1kmZ7ZKViHHDbhUegF JWDXOYTHcdQp6Q3jA6jX11eLlbhmBjrmICh7D26qYtVgr2yJc9jmkzlQuBexhdmK vhtdRR36HtJTGfxLMsZCQRa9FQG/F8hqemQdLmomTgW93ZXr1XDy5oSOs/qyWmZ+ 5M4lgL5v69eMmMX9JvcxoCoSyPEAeqIQOhA0vnvnhVE1I0wpotvEgY8AECV8ZXa1 HDh+oYjeFEGcp5l9ATLeK34W/nF4b6FYZgTihJA/77ELVgnlE+d2zDvGqLIKyNzh qMwDQPw1hiRnzSejVm783uIGSc+qVZ1EEDgEP0AdVT9cIqspfz84ivGR7pFeuQCr Wxes4+Pv8nUXrQ/BRkzGJkPVMLkW/VyoWhyLMuoVHBBixG5PbBbhUrDMmqTlaloe /nsd0egoQ8uwx6hfdrJhBO6Wdf81T/pJCyflTtjZgD4su6MolIsrZvLKgP3s88Su QlPMmqrLKPCDVQ3YxqPevnr2E11fLVXt+ZmxmkppBJOgwFsWS1e4FEPEpVTpu58m RB+OqEvjGwCo57Udb5sZURh8eS2v0cc6atx02nhRDqu7SerFQKU= =kqgd -----END PGP SIGNATURE----- --cIHVS0AWeSXrYSCp--