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=QfmGQ5Ob; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 1AB415A0265 for ; Sun, 22 Feb 2026 18:45:05 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1771782303; 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=B5caEyXZfXNd3Zt9L3lybTpzQQ3wGiBhRnY1RT3AMc0=; b=QfmGQ5Ob0tJfCi8OL9csz2INUtY7maaoLpX87SUaaLceqd/2fq0QONKp7gn7vjTnLU5uB2 Kjyp9GlPOt075wfRQF1fVfZgGkiNrz2rSNW8k9bO9BPBPeQj350ANKoj55vUwDCoakPYTZ i1PT+D3D8p+7eJfd8YEIxWzwu76lR38= Received: from mx-prod-mc-01.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-533-d5fc2JW4MBeJrmO4U3w8KQ-1; Sun, 22 Feb 2026 12:45:02 -0500 X-MC-Unique: d5fc2JW4MBeJrmO4U3w8KQ-1 X-Mimecast-MFC-AGG-ID: d5fc2JW4MBeJrmO4U3w8KQ_1771782301 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 8B51F1956095; Sun, 22 Feb 2026 17:45:01 +0000 (UTC) Received: from jmaloy-thinkpadp16vgen1.rmtcaqc.csb (unknown [10.22.64.49]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9680C1800669; Sun, 22 Feb 2026 17:45:00 +0000 (UTC) From: Jon Maloy To: sbrivio@redhat.com, dgibson@redhat.com, david@gibson.dropbear.id.au, jmaloy@redhat.com, passt-dev@passt.top Subject: [PATCH v5 08/13] ip: Track observed guest IPv6 addresses in unified address array Date: Sun, 22 Feb 2026 12:44:40 -0500 Message-ID: <20260222174445.743845-9-jmaloy@redhat.com> In-Reply-To: <20260222174445.743845-1-jmaloy@redhat.com> References: <20260222174445.743845-1-jmaloy@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ori0no9WviujBg3QOMsaPv5-YaOzdrx2krl1PcIGz6A_1771782301 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 3VIRXAAQKYNYAIJORXOX5WTHPFEAG3JY X-Message-ID-Hash: 3VIRXAAQKYNYAIJORXOX5WTHPFEAG3JY 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 remove the addr_seen and addr_ll_seen fields in struct ip6_ctx and replace them by setting CONF_ADDR_OBSERVED and CONF_ADDR_LINKLOCAL flags in the corresponding entry in the unified address array. The observed IPv6 address is always added/moved to position 0 in the array, improving chances for fast lookup. This completes the unification of address storage for both IPv4 and IPv6, enabling future support for multiple guest addresses per family. Signed-off-by: Jon Maloy --- v5: - Made to use same algorithm and function as IPv4 for inserting observed into the array. --- conf.c | 2 -- dhcpv6.c | 6 +----- dhcpv6.h | 2 +- migrate.c | 27 +++++++++++++++++++------- passt.h | 4 ---- pasta.c | 17 +++++++++++++---- tap.c | 57 +++++++++++++++++++++++++++++++++---------------------- 7 files changed, 69 insertions(+), 46 deletions(-) diff --git a/conf.c b/conf.c index faa60ec..f622424 100644 --- a/conf.c +++ b/conf.c @@ -816,8 +816,6 @@ static unsigned int conf_ip6(struct ctx *c, unsigned int ifi) e->flags = CONF_ADDR_HOST; } - ip6->addr_seen = e->addr.a6; - if (IN6_IS_ADDR_LINKLOCAL(&ip6->guest_gw)) ip6->our_tap_ll = ip6->guest_gw; diff --git a/dhcpv6.c b/dhcpv6.c index 55c17cf..ba200e5 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -549,7 +549,7 @@ static size_t dhcpv6_client_fqdn_fill(const struct iov_tail *data, * Return: 0 if it's not a DHCPv6 message, 1 if handled, -1 on failure */ int dhcpv6(struct ctx *c, struct iov_tail *data, - const struct in6_addr *saddr, const struct in6_addr *daddr) + const struct in6_addr *daddr) { const struct opt_server_id *server_id = NULL; struct inany_addr_entry *e = first_v6(c); @@ -591,8 +591,6 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, if (mlen + sizeof(*uh) != ntohs(uh->len) || mlen < sizeof(*mh)) return -1; - c->ip6.addr_ll_seen = *saddr; - src = &c->ip6.our_tap_ll; mh = IOV_REMOVE_HEADER(data, mh_storage); @@ -683,8 +681,6 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, tap_udp6_send(c, src, 547, tap_ip6_daddr(c, src), 546, mh->xid, &resp, n); - if (e) - c->ip6.addr_seen = e->addr.a6; return 1; } diff --git a/dhcpv6.h b/dhcpv6.h index c706dfd..8cbc769 100644 --- a/dhcpv6.h +++ b/dhcpv6.h @@ -7,7 +7,7 @@ #define DHCPV6_H int dhcpv6(struct ctx *c, struct iov_tail *data, - struct in6_addr *saddr, struct in6_addr *daddr); + struct in6_addr *daddr); void dhcpv6_init(const struct ctx *c); #endif /* DHCPV6_H */ diff --git a/migrate.c b/migrate.c index f026e95..1e2830f 100644 --- a/migrate.c +++ b/migrate.c @@ -56,10 +56,7 @@ struct migrate_seen_addrs_v1 { static int seen_addrs_source_v1(struct ctx *c, const struct migrate_stage *stage, int fd) { - struct migrate_seen_addrs_v1 addrs = { - .addr6 = c->ip6.addr_seen, - .addr6_ll = c->ip6.addr_ll_seen, - }; + struct migrate_seen_addrs_v1 addrs = { 0 }; const struct inany_addr_entry *e; (void)stage; @@ -69,6 +66,15 @@ static int seen_addrs_source_v1(struct ctx *c, if (e) addrs.addr4 = *inany_v4(&e->addr); + /* IPv6 observed address */ + e = fwd_get_addr(c, AF_INET6, CONF_ADDR_OBSERVED, 0); + if (e) { + if (e->flags & CONF_ADDR_LINKLOCAL) + addrs.addr6_ll = e->addr.a6; + else + addrs.addr6 = e->addr.a6; + } + memcpy(addrs.mac, c->guest_mac, sizeof(addrs.mac)); if (write_all_buf(fd, &addrs, sizeof(addrs))) @@ -89,6 +95,7 @@ static int seen_addrs_target_v1(struct ctx *c, const struct migrate_stage *stage, int fd) { struct migrate_seen_addrs_v1 addrs; + struct in6_addr addr6, addr6_ll; struct in_addr addr4; (void)stage; @@ -96,14 +103,20 @@ static int seen_addrs_target_v1(struct ctx *c, if (read_all_buf(fd, &addrs, sizeof(addrs))) return errno; - c->ip6.addr_seen = addrs.addr6; - c->ip6.addr_ll_seen = addrs.addr6_ll; - /* Copy from packed struct to avoid alignment issues */ addr4 = addrs.addr4; + addr6 = addrs.addr6; + addr6_ll = addrs.addr6_ll; + if (addr4.s_addr) fwd_set_addr(c, &inany_from_v4(addr4), CONF_ADDR_OBSERVED, 0); + /* Prefer global over link-local if both present */ + if (!IN6_IS_ADDR_UNSPECIFIED(&addr6)) + fwd_set_addr(c, &inany_from_v6(addr6), CONF_ADDR_OBSERVED, 0); + else if (!IN6_IS_ADDR_UNSPECIFIED(&addr6_ll)) + fwd_set_addr(c, &inany_from_v6(addr6_ll), CONF_ADDR_OBSERVED, 0); + memcpy(c->guest_mac, addrs.mac, sizeof(c->guest_mac)); return 0; diff --git a/passt.h b/passt.h index b808a19..e7489ca 100644 --- a/passt.h +++ b/passt.h @@ -112,8 +112,6 @@ struct ip4_ctx { /** * struct ip6_ctx - IPv6 execution context - * @addr_seen: Latest IPv6 global/site address seen as source from tap - * @addr_ll_seen: Latest IPv6 link-local address seen as source from tap * @guest_gw: IPv6 gateway as seen by the guest * @map_host_loopback: Outbound connections to this address are NATted to the * host's [::1] @@ -129,8 +127,6 @@ struct ip4_ctx { * @no_copy_addrs: Don't copy all addresses when configuring namespace */ struct ip6_ctx { - struct in6_addr addr_seen; - struct in6_addr addr_ll_seen; struct in6_addr guest_gw; struct in6_addr map_host_loopback; struct in6_addr map_guest_addr; diff --git a/pasta.c b/pasta.c index 7a081e7..56b2e0a 100644 --- a/pasta.c +++ b/pasta.c @@ -46,6 +46,8 @@ #include "util.h" #include "passt.h" +#include "conf.h" +#include "fwd.h" #include "isolation.h" #include "netlink.h" #include "log.h" @@ -384,12 +386,15 @@ void pasta_ns_conf(struct ctx *c) ipv4_done: if (c->ifi6) { - rc = nl_addr_get_ll(nl_sock_ns, c->pasta_ifi, - &c->ip6.addr_ll_seen); - if (rc < 0) { + struct in6_addr addr_ll; + + rc = nl_addr_get_ll(nl_sock_ns, c->pasta_ifi, &addr_ll); + if (rc < 0) warn("Can't get LL address from namespace: %s", strerror_(-rc)); - } + else + fwd_set_addr(c, &inany_from_v6(addr_ll), + CONF_ADDR_OBSERVED, 0); rc = nl_addr_set_ll_nodad(nl_sock_ns, c->pasta_ifi); if (rc < 0) { @@ -403,6 +408,10 @@ ipv4_done: if (c->ip6.no_copy_addrs) { for_each_addr(e, c, AF_INET6) { + /* Skip, kernel auto-configures */ + if (e->flags & CONF_ADDR_LINKLOCAL) + continue; + rc = nl_addr_set(nl_sock_ns, c->pasta_ifi, AF_INET6, &e->addr.a6, diff --git a/tap.c b/tap.c index 30e52f7..875c2bf 100644 --- a/tap.c +++ b/tap.c @@ -174,6 +174,17 @@ static void tap_check_src_addr4(struct ctx *c, const struct in_addr *addr) fwd_set_addr(c, &inany_from_v4(*addr), CONF_ADDR_OBSERVED, 0); } +/** + * tap_check_src_addr6() - Note an IPv6 address seen in guest traffic + * @c: Execution context + * @addr: IPv6 address seen as source from guest + */ +static void tap_check_src_addr6(struct ctx *c, const struct in6_addr *addr) +{ + if (!IN6_IS_ADDR_UNSPECIFIED(addr)) + fwd_set_addr(c, &inany_from_v6(*addr), CONF_ADDR_OBSERVED, 0); +} + /** * tap_ip6_daddr() - Normal IPv6 destination address for inbound packets * @c: Execution context @@ -184,9 +195,25 @@ static void tap_check_src_addr4(struct ctx *c, const struct in_addr *addr) const struct in6_addr *tap_ip6_daddr(const struct ctx *c, const struct in6_addr *src) { - if (IN6_IS_ADDR_LINKLOCAL(src)) - return &c->ip6.addr_ll_seen; - return &c->ip6.addr_seen; + const struct inany_addr_entry *e; + + if (IN6_IS_ADDR_LINKLOCAL(src)) { + /* Link-local: first LL address (observed is at front) */ + e = fwd_get_addr(c, AF_INET6, CONF_ADDR_LINKLOCAL, 0); + } else { + /* Global: observed non-LL first, then any non-LL */ + e = fwd_get_addr(c, AF_INET6, CONF_ADDR_OBSERVED, + CONF_ADDR_LINKLOCAL); + if (!e) + e = fwd_get_addr(c, AF_INET6, 0, CONF_ADDR_LINKLOCAL); + } + + if (e) + return &e->addr.a6; + + /* Last resort: first IPv6 address */ + e = first_v6(c); + return e ? &e->addr.a6 : &in6addr_any; } /** @@ -786,7 +813,7 @@ resume: if (iph->saddr) tap_check_src_addr4(c, - (const struct in_addr *)&iph->saddr); + (const struct in_addr *)&iph->saddr); if (!iov_drop_header(&data, hlen)) continue; @@ -958,24 +985,8 @@ resume: continue; } - if (IN6_IS_ADDR_LINKLOCAL(saddr)) { - c->ip6.addr_ll_seen = *saddr; - - if (IN6_IS_ADDR_UNSPECIFIED(&c->ip6.addr_seen)) { - c->ip6.addr_seen = *saddr; - } - - if (!first_v6(c) && c->addr_count < INANY_MAX_ADDRS) { - struct inany_addr_entry *e; - - e = &c->addrs[c->addr_count++]; - e->addr.a6 = *saddr; - e->prefix_len = 64; - e->flags = CONF_ADDR_LINKLOCAL; - } - } else if (!IN6_IS_ADDR_UNSPECIFIED(saddr)){ - c->ip6.addr_seen = *saddr; - } + if (!IN6_IS_ADDR_UNSPECIFIED(saddr)) + tap_check_src_addr6(c, saddr); if (proto == IPPROTO_ICMPV6) { struct iov_tail ndp_data; @@ -1006,7 +1017,7 @@ resume: if (proto == IPPROTO_UDP) { struct iov_tail uh_data = data; - if (dhcpv6(c, &uh_data, saddr, daddr)) + if (dhcpv6(c, &uh_data, daddr)) continue; } -- 2.52.0