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=VabhIxJs; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 66C655A0262 for ; Tue, 24 Mar 2026 04:45:32 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774323930; bh=EEb0c3Z3oe0h24zxgO4hO8RYcnlqihfeWZZDbnHI4E8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=VabhIxJsEp6QH6ObSuykLo4KvVja95Kief3WewhFrze8eGlb5rQuzPc4uogkITMm1 aoAz8vGLQHq/LgRKGuX/KuiUNSd7WPCUF5NcAEozGLBID4380ITCghN40j9Ej6FmpE jv4Nqy1RaFwZfXsDGEpOvZBN4XL7wQMjBbrATEwsIZsXXw50x+ja0yAJTJfdxp20nP aIHlDzmp3Pu4yYsGdqyhRXSaM+AkaPw4AIz8jZzVuXlx484g3a6YsDHYvlV8lgFg8p SYFtNYKrgv6QBUB/59StBa/vFTIFzSoO3AX2R0Jfu2WuJQex2a5LuCUZ3EwpksN0lE Ulq3U92HU5WTQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ffwt21xr1z4wCG; Tue, 24 Mar 2026 14:45:30 +1100 (AEDT) Date: Tue, 24 Mar 2026 14:45:21 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v6 03/13] fwd: Unify guest accessibility checks with unified address array Message-ID: References: <20260322004333.365713-1-jmaloy@redhat.com> <20260322004333.365713-4-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="enHXOLFT/zXU8nmd" Content-Disposition: inline In-Reply-To: <20260322004333.365713-4-jmaloy@redhat.com> Message-ID-Hash: 46DFHZ6H7OU3BZYJA6I27UIKHVHZEN2J X-Message-ID-Hash: 46DFHZ6H7OU3BZYJA6I27UIKHVHZEN2J 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: --enHXOLFT/zXU8nmd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 21, 2026 at 08:43:23PM -0400, 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 AF_UNSPEC. >=20 > Signed-off-by: Jon Maloy Reviewed-by: David Gibson >=20 > --- > v6: -Some fixes based on feedback from David Gibson > --- > fwd.c | 69 ++++++++++++++--------------------------------------------- > 1 file changed, 16 insertions(+), 53 deletions(-) >=20 > diff --git a/fwd.c b/fwd.c > index 9101d6d..695b5a5 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -991,19 +991,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) > { > - const struct guest_addr *a =3D fwd_get_addr(c, AF_INET, 0, 0); > + const struct guest_addr *a; > =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, > @@ -1011,36 +1011,18 @@ static bool fwd_guest_accessible4(const struct ct= x *c, > * that has a different meaning for host and guest, we can't let it > * through untranslated. > */ > - if (IN4_IS_ADDR_UNSPECIFIED(addr)) > + if (inany_is_unspecified(addr)) > return false; > =20 > - /* For IPv4, addr_seen is initialised to addr, so is always a valid > - * address > - */ > - if ((a && IN4_ARE_ADDR_EQUAL(addr, inany_v4(&a->addr))) || > - IN4_ARE_ADDR_EQUAL(addr, &c->ip4.addr_seen)) > - return false; > - > - 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) > -{ > - const struct guest_addr *a =3D fwd_get_addr(c, AF_INET6, 0, 0); > - > - if (IN6_IS_ADDR_LOOPBACK(addr)) > - return false; > + /* Check against all configured guest addresses */ > + for_each_addr(a, c, AF_UNSPEC) > + if (inany_equals(addr, &a->addr)) > + return false; > =20 > - if (a && IN6_ARE_ADDR_EQUAL(addr, &a->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 > @@ -1048,31 +1030,12 @@ static bool fwd_guest_accessible6(const struct ct= x *c, > * 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)) > + 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 --enHXOLFT/zXU8nmd Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnCCNAACgkQzQJF27ox 2GcVdw//WLo7qCqZRL3zOJqXYMWqUGI9bfTCWEFphYns6Kzv2uIaGXhlU/RxpjQb zSc23smkDAFf4Hll9qO/qJeE1wtaL7b+X1g5JZlPNoWcO93RIUUpMyjxWYS+bTrl MAjyMKS7poqbm7EMPc3lA4Ujc6GyDd1xUJ5dGKQvuNc9ZV7TwK3OSKhELqyJ2L78 oRq7Sw7hUHd5YOzTYd+EBX/xNTNbQwXxgXxaJlMEuSr+lfcPzNJQnn+b5PMsbQNY DZh+1/yHwlzbRvI/8LtLAUxQs7l7dxhMwLPKWJKP40mM9iWJf285a1xydH3bmwwo W+e992EDZoa6ssKW1JZYzxbzgULl1+BAz2la6H5gZJMsfk+9WG93dRec4zothD+g AseCI4tnA9L74VcjYVYK8VDGl9TLPNMGm53Lfwk7lMvPN9f8eIf35tK/PKr946IV KMa7GR69LY0oD0Q5aZn4rcRvq5xMURZy96AStEugfx5bUTkiIYItnvpSZia+ttaG VfniggY54OScAkfVo7njK/BlpUtcNKBzFQA6awUNP3ishSkFA2DapPsQfmOFdXyU uPnkVVkNuvAtfifbQQDtEFp3doV63EBbF2k1RTJJl4TgYzKlHtv9Ixq+izyHPRqv 35UlxwivhHlIJqgwTjFb0HxGBsn4For3MkxDPsoQcOYD741yhmE= =H3UF -----END PGP SIGNATURE----- --enHXOLFT/zXU8nmd--