From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Rsy4ICQe; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 2BDA25A0262 for ; Mon, 13 Apr 2026 02:53:30 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1776041609; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Us3Y3rJPysUnu1ArWmM7b6vM3eFjIGiWc5SZzt9GUdA=; b=Rsy4ICQesM3Fhwyy3kwujqzSZX1NfGTiv3k8DN3sThCh2/Vq0lzfr53f49I4qshyj5e33T pPiqedh5yiBCAY1yNyp5tQn/JFCHJh72Y9q8LCuUElSNkE1F5xMN26pe1IvPFUwfNgHSgk ZBeXZHBHpNxWGbLDPM0TW7XgNhejOjw= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-84-qbXQYJDQO-KSg8D_gya5Pg-1; Sun, 12 Apr 2026 20:53:26 -0400 X-MC-Unique: qbXQYJDQO-KSg8D_gya5Pg-1 X-Mimecast-MFC-AGG-ID: qbXQYJDQO-KSg8D_gya5Pg_1776041605 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1F759195608B; Mon, 13 Apr 2026 00:53:25 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.64.70]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 606E43000C1D; Mon, 13 Apr 2026 00:53:24 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH v7 03/13] fwd: Unify guest accessibility checks with unified address array Date: Sun, 12 Apr 2026 20:53:09 -0400 Message-ID: <20260413005319.3295910-4-jmaloy@redhat.com> In-Reply-To: <20260413005319.3295910-1-jmaloy@redhat.com> References: <20260413005319.3295910-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: GWTlfryYUCwOiJTNEAo9xpst-Pe2s-yfhYZ_34k412w_1776041605 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: FNBFLTKONYMLZVHXHL7R255I4ME6UCI7 X-Message-ID-Hash: FNBFLTKONYMLZVHXHL7R255I4ME6UCI7 X-MailFrom: jmaloy@redhat.com 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 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: 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. Signed-off-by: Jon Maloy --- v6: -Some fixes based on feedback from David Gibson v7: -Added curly brackets to for_each_addr() in fwd_guest_accessible(), as suggested by Stefano Brivio. --- fwd.c | 69 +++++++++++++---------------------------------------------- 1 file changed, 15 insertions(+), 54 deletions(-) diff --git a/fwd.c b/fwd.c index 14ce0a7..e676c18 100644 --- a/fwd.c +++ b/fwd.c @@ -988,19 +988,19 @@ static bool is_dns_flow(uint8_t proto, const struct flowside *ini) } /** - * 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; - if (IN4_IS_ADDR_LOOPBACK(addr)) + if (inany_is_loopback(addr)) return false; /* In socket interfaces 0.0.0.0 generally means "any" or unspecified, @@ -1008,38 +1008,18 @@ 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)) + if (inany_is_unspecified(addr)) return false; - /* For IPv4, addr_seen is initialised to addr, so is always a valid - * address + /* Check against all configured guest addresses */ + for_each_addr(a, c->addrs, c->addr_count, AF_UNSPEC) { + if (inany_equals(addr, &a->addr)) + return false; + } + /* Also check addr_seen: it tracks the address the guest is actually + * using, which may differ from configured addresses. */ - a = fwd_get_addr(c, AF_INET, 0, 0); - 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; - - if (IN6_IS_ADDR_LOOPBACK(addr)) - return false; - - a = fwd_get_addr(c, AF_INET6, 0, 0); - if (a && IN6_ARE_ADDR_EQUAL(addr, &a->addr.a6)) + if (inany_equals4(addr, &c->ip4.addr_seen)) return false; /* For IPv6, addr_seen starts unspecified, because we don't know what LL @@ -1047,31 +1027,12 @@ static bool fwd_guest_accessible6(const struct ctx *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; return true; } -/** - * 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 = 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 -- 2.52.0