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=202602 header.b=DK9yMwWW; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 839655A004E for ; Mon, 02 Mar 2026 11:33:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1772447605; bh=dPljWEjrh4Brr4j1s/3SDFVl3syhsfrlSyxJLoTZH5U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DK9yMwWWlE6TWCZ7TwQYwb52lHGTZ39geDrPh4fYMixHPRjkbpoc9U6dzOs5PlmXL G4Qlj0qRr4afNs03AONZu7R+xjP8Q5EuYyas/Bgbr8XeuICXXh7xNk6nJi/+OLs2X8 YBIYWHxh0Rxb+6F38QRE8gvfz5zn4zoElUgRO5ule1/yWX1s/uFclqib0CT32ZgoMV Jo42tacN8OjMLl1LNF+qSFn38aKHxOlqwhHk+Gv/bTepFcRVlo0T+uqtAEyGZmSJxj KWrcx99a8KWukAjZ8GlphbM+PD6if9TYCBgWu1f4boQACXqB6fH7yUn9P/pyIboDGc Dd4sOv1KJHuiA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4fPZys1GP8z4w9Q; Mon, 02 Mar 2026 21:33:25 +1100 (AEDT) Date: Mon, 2 Mar 2026 21:33:16 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v5 03/13] fwd: Unify guest accessibility checks with unified address array Message-ID: References: <20260222174445.743845-1-jmaloy@redhat.com> <20260222174445.743845-4-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="kU4e+/cJ9P1KWciQ" Content-Disposition: inline In-Reply-To: <20260222174445.743845-4-jmaloy@redhat.com> Message-ID-Hash: B6KDV4QMUQA2OWHSUUXISWKK2YVNBFUL X-Message-ID-Hash: B6KDV4QMUQA2OWHSUUXISWKK2YVNBFUL 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: sbrivio@redhat.com, dgibson@redhat.com, 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: --kU4e+/cJ9P1KWciQ Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Feb 22, 2026 at 12:44:35PM -0500, Jon Maloy wrote: > We replace the fwd_guest_accessible4() and fwd_guest_accessible6() > functions with a unified fwd_guest_accessible() function that handles > both address families. With the unified address array, we can check > all configured addresses in a single pass using for_each_addr() with > family filter INADDR_UNSPEC (=3D=3D 0). >=20 > Signed-off-by: Jon Maloy > --- > fwd.c | 70 +++++++++++++++-------------------------------------------- > 1 file changed, 18 insertions(+), 52 deletions(-) >=20 > diff --git a/fwd.c b/fwd.c > index cf13ddd..edf6a6b 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -880,19 +880,19 @@ static bool is_dns_flow(uint8_t proto, const struct= flowside *ini) > } > =20 > /** > - * fwd_guest_accessible4() - Is IPv4 address guest-accessible > + * fwd_guest_accessible() - Is address guest-accessible > * @c: Execution context > - * @addr: Host visible IPv4 address > + * @addr: Host visible address (IPv4 or IPv6) > * > * Return: true if @addr on the host is accessible to the guest without > * translation, false otherwise > */ > -static bool fwd_guest_accessible4(const struct ctx *c, > - const struct in_addr *addr) > +static bool fwd_guest_accessible(const struct ctx *c, > + const union inany_addr *addr) > { > - struct inany_addr_entry *e =3D first_v4(c); > + const struct inany_addr_entry *e; > =20 > - if (IN4_IS_ADDR_LOOPBACK(addr)) > + if (inany_is_loopback(addr)) > return false; > =20 > /* In socket interfaces 0.0.0.0 generally means "any" or unspecified, > @@ -900,66 +900,32 @@ static bool fwd_guest_accessible4(const struct ctx = *c, > * that has a different meaning for host and guest, we can't let it > * through untranslated. > */ > - if (IN4_IS_ADDR_UNSPECIFIED(addr)) > - return false; > - > - /* For IPv4, addr_seen is initialised to addr, so is always a valid > - * address > - */ > - if ((e && IN4_ARE_ADDR_EQUAL(addr, inany_v4(&e->addr))) || > - IN4_ARE_ADDR_EQUAL(addr, &c->ip4.addr_seen)) > + if (inany_is_unspecified4(addr)) You want inany_is_unspecified(), not inany_is_unspecified4(). > return false; > =20 > - return true; > -} > - > -/** > - * fwd_guest_accessible6() - Is IPv6 address guest-accessible > - * @c: Execution context > - * @addr: Host visible IPv6 address > - * > - * Return: true if @addr on the host is accessible to the guest without > - * translation, false otherwise > - */ > -static bool fwd_guest_accessible6(const struct ctx *c, > - const struct in6_addr *addr) > -{ > - if (IN6_IS_ADDR_LOOPBACK(addr)) > - return false; > + /* Check against all configured guest addresses */ > + for_each_addr(e, c, 0) > + if (inany_equals(addr, &e->addr)) > + return false; > =20 > - if (first_v6(c) && IN6_ARE_ADDR_EQUAL(addr, &first_v6(c)->addr.a6)) > + /* Also check addr_seen: it tracks the address the guest is actually > + * using, which may differ from configured addresses. > + */ > + if (inany_equals4(addr, &c->ip4.addr_seen)) > return false; > =20 > /* For IPv6, addr_seen starts unspecified, because we don't know what LL > * address the guest will take until we see it. Only check against it > * if it has been set to a real address. > */ > - if (!IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr_seen) && > - IN6_ARE_ADDR_EQUAL(addr, &c->ip6.addr_seen)) > + if (!inany_v4(addr) && You don't need this test. If addr is IPv4, it necessarily won't equal ip6.addr_seen which is IPv6. > + !IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr_seen) && > + inany_equals6(addr, &c->ip6.addr_seen)) > return false; > =20 > return true; > } > =20 > -/** > - * fwd_guest_accessible() - Is IPv[46] address guest-accessible > - * @c: Execution context > - * @addr: Host visible IPv[46] address > - * > - * Return: true if @addr on the host is accessible to the guest without > - * translation, false otherwise > - */ > -static bool fwd_guest_accessible(const struct ctx *c, > - const union inany_addr *addr) > -{ > - const struct in_addr *a4 =3D inany_v4(addr); > - > - if (a4) > - return fwd_guest_accessible4(c, a4); > - > - return fwd_guest_accessible6(c, &addr->a6); > -} > - > /** > * nat_outbound() - Apply address translation for outbound (TAP to HOST) > * @c: Execution context > --=20 > 2.52.0 >=20 --=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 --kU4e+/cJ9P1KWciQ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmmlZ2wACgkQzQJF27ox 2GedVw/9FlyRKpBtzeB9ezmc1KqCDTTDrqJtWs3Xe5bAJmDiR/sHy+W1sB2e9Ozs XmqIoT44ng0NCSVgX6KgkgElZsoy1ColNKo/G5c9MdHRoNp1Dho/EMOF/IzuaoRa Kic6j8F6bP7uSuWm4QyvAqbf/YDzS21sZ502F17CAXUvy1fJ8A0g6vTxgJOtBIDS 3rpEGaeyhsCpSe3paBxJwe8ZYIzECbggz5k4DCT5l3OB7oFpPs5YliVIGcFFtSu6 v+qLLYfoplOORZSZa0p4+TL+7YqtQqYcQSdrUXMwMNfBx1rJfMcI06rFxTn3SDB7 hbWaY5rO6u/LEqb+yZOIZyuTW5X/wJhdUlONdMt/wR9/IzrOuEybKIQt8sNJa/qY G/BSzuIpGEfMImyA/lQnEZq96luD1f1oEaLH+TAaovIa4ck+g4DpGrHRvImCH2Uz ugKKyVdcfJS8GYfH1H7/KbipYvg52zphzhGNZxfzLo5ERcGvVPQjZtRopYDtALwv wr4q6RcLswInt0cO39kDBB1i6QKR7kyWo9SxYtIyp7R6ZZbQmV/Pw3fUL1P43kW6 4X04xa2I7K700I2UAaUfw+enJd7ua/Rj77OV7ZyRsQuhTA5zjuW/6UCUpzPbqXjP YmR6Qd7rReW+rYT0Er6gg+jxQO106R+F9XTvAwM48AkBU+NRbZk= =Zdgq -----END PGP SIGNATURE----- --kU4e+/cJ9P1KWciQ--