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=TkTBTq2G; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 813425A0265 for ; Tue, 24 Mar 2026 06:49:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1774331387; bh=OQ1vx3vbB4eAJSGI8jGZE9nMq5jQyPMeqnEm3io8RI8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=TkTBTq2GOecgSXDNRH0jxZsFuh2JaIIPcoNZh9QEfLcV7pzPsFOyzZ4I0BjmcDzv+ hWiPtJhlRK80JxRcWD3bIfu+T0Yvgxeyw2zuX2CU2aQ4LoREfmTp9wdOi/DYuaT7QP 2yusxzYrMdXIlduh9xMFNBtV+clJNdj8XQBgEnirfV+ZodAUZtR+KrmSz7UkJ2enE7 tX1N8YLwiocw5zd9wxLWGMMwN431s7UU3FqJjFp9I1pGzHD19xI0dLqdyWhKy2pl2m NnoB04N6DQOrCDSWNOFRognZwHJWcWR8pyCYAX3jNnZoeB1VT1cRjFdlzmX26IwpDA VgXri8kWsXaIA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ffzdR2jVqz4wF0; Tue, 24 Mar 2026 16:49:47 +1100 (AEDT) Date: Tue, 24 Mar 2026 16:29:25 +1100 From: David Gibson To: Jon Maloy Subject: Re: [PATCH v6 05/13] conf: Allow multiple -a/--address options per address family Message-ID: References: <20260322004333.365713-1-jmaloy@redhat.com> <20260322004333.365713-6-jmaloy@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="JS1ad62fZI2q7fMF" Content-Disposition: inline In-Reply-To: <20260322004333.365713-6-jmaloy@redhat.com> Message-ID-Hash: KJKVHC3FR6WHKDIZQ2KFIOWSIOPD2S6G X-Message-ID-Hash: KJKVHC3FR6WHKDIZQ2KFIOWSIOPD2S6G 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: --JS1ad62fZI2q7fMF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sat, Mar 21, 2026 at 08:43:25PM -0400, Jon Maloy wrote: > Allow specifying multiple addresses per family with -a/--address. > The first address of each family is used for DHCP/DHCPv6 assignment. >=20 > Signed-off-by: Jon Maloy >=20 > --- > v2: - Adapted to previous code changes > v3: - Adapted to single-array strategy > - Changes according to feedback from S. Brivio and G Gibson. > v4: - Stripped down and adapted after feedback from David G. > v6: - Adapted to previous changes in series > - Removed the "one address" limitation for -n option > --- > conf.c | 7 ++++--- > fwd.c | 7 ++----- > pasta.c | 17 ++++++++++------- > 3 files changed, 16 insertions(+), 15 deletions(-) >=20 > diff --git a/conf.c b/conf.c > index 8f02494..95f09cb 100644 > --- a/conf.c > +++ b/conf.c > @@ -935,9 +935,11 @@ static void usage(const char *name, FILE *f, int sta= tus) > " default: 65520: maximum 802.3 MTU minus 802.3 header\n" > " length, rounded to 32 bits (IPv4 words)\n" > " -a, --address ADDR Assign IPv4 or IPv6 address ADDR[/PREFIXLEN]\n" > - " can be specified zero to two times (for IPv4 and IPv6)\n" > + " can be specified up to a maximum of %d times\n" > " default: use addresses from interface with default route\n" > - " -n, --netmask MASK Assign IPv4 MASK, dot-decimal or bits\n" > + " -n, --netmask MASK Assign IPv4 MASK, dot-decimal or bits\n", > + MAX_GUEST_ADDRS); > + FPRINTF(f, > " default: netmask from matching address on the host\n" > " -M, --mac-addr ADDR Use source MAC address ADDR\n" > " default: 9a:55:9a:55:9a:55 (locally administered)\n" > @@ -1891,7 +1893,6 @@ void conf(struct ctx *c, int argc, char **argv) > IN6_IS_ADDR_V4COMPAT(&addr.a6)) > die("Invalid address: %s", optarg); > =20 > - /* Legacy behaviour: replace existing address if any */ > fwd_set_addr(c, &addr, CONF_ADDR_USER, prefix_len); > if (inany_v4(&addr)) > c->ip4.no_copy_addrs =3D true; > diff --git a/fwd.c b/fwd.c > index 695b5a5..2853c0e 100644 > --- a/fwd.c > +++ b/fwd.c > @@ -250,14 +250,12 @@ void fwd_neigh_table_init(const struct ctx *c) > } > =20 > /** > - * fwd_set_addr() - Add or update an address in the unified address array > + * fwd_set_addr() - Update address entry, adding one if needed > * @c: Execution context > * @addr: Address to add (IPv4-mapped or IPv6) > * @flags: CONF_ADDR_* flags for this address > * @prefix_len: Prefix length in IPv6/mapped format, 0-128 > * > - * Find the first existing entry of the same address family and > - * overwrite it, or create a new one if none exists > */ > void fwd_set_addr(struct ctx *c, const union inany_addr *addr, > uint8_t flags, int prefix_len) > @@ -266,8 +264,7 @@ void fwd_set_addr(struct ctx *c, const union inany_ad= dr *addr, > =20 > for (int i =3D 0; i < c->addr_count; i++) { > a =3D &c->addrs[i]; > - if ((inany_v4(addr) && inany_v4(&a->addr)) || > - (!inany_v4(addr) && !inany_v4(&a->addr))) > + if (inany_equals(addr, &a->addr)) > goto found; > } > =20 > diff --git a/pasta.c b/pasta.c > index e88a893..6307c65 100644 > --- a/pasta.c > +++ b/pasta.c > @@ -342,12 +342,14 @@ void pasta_ns_conf(struct ctx *c) > =20 > if (c->ifi4) { > if (c->ip4.no_copy_addrs) { > - a =3D fwd_get_addr(c, AF_INET, 0, 0); > - if (a) > + for_each_addr(a, c, AF_INET) { I think this will work out cleaner if you have a single loop for all addresses, then do the v4 vs. v6 conditionals in the body. > rc =3D nl_addr_set(nl_sock_ns, > c->pasta_ifi, AF_INET, > inany_v4(&a->addr), > - a->prefix_len - 96); > + inany_prefix_len(a)); > + if (rc < 0) > + break; > + } > } else { > rc =3D nl_addr_dup(nl_sock, c->ifi4, > nl_sock_ns, c->pasta_ifi, > @@ -400,13 +402,14 @@ ipv4_done: > 0, IFF_NOARP); > =20 > if (c->ip6.no_copy_addrs) { > - a =3D fwd_get_addr(c, AF_INET6, 0, 0); > - if (a) > + for_each_addr(a, c, AF_INET6) { > rc =3D nl_addr_set(nl_sock_ns, > c->pasta_ifi, > - AF_INET6, > - &a->addr.a6, > + AF_INET6, &a->addr.a6, > a->prefix_len); > + if (rc < 0) > + break; > + } > } else { > rc =3D nl_addr_dup(nl_sock, c->ifi6, > nl_sock_ns, c->pasta_ifi, > --=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 --JS1ad62fZI2q7fMF Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmnCITQACgkQzQJF27ox 2Ge2tw/7BezqWXHDgNPMGi//jfsDijPcKH4gCCcPpJ3AUuwCQRcdeykSFwOfVf/2 6f907WOT2oxahSkxkVoXWb+S6EjC7W6RhtpoS4/dn1U1106bkPEDIfz6O9wSA44g 4kaB2aHWnFsgzwmaqHMqpikPnd8/5k/D2ffT/3phbf2XppQfa2MZwRnyj5l+Rw0D 0G0IDeIIbbiGkzwHa+6XuUSwcLTeRC81LZJaBrU9Coc6iyChMaw6FGTEYtz9EH7W uNkzXpK46Lu3aZiuDGP/iYanXZDCHKF17o9eiX1jkKvnr7bOK42ZgVag1+o1skSu sGggK2+rmJTB0/f8b1QKcYrojjSkdCPK3CXitV7SGHbSg4xG+KOhOCqF97IoDY0B pGznYHUG7l6tKRP9rzp6qrxNJfMdsCzu0cG8IOvgnvORT7Tp46sS0uj3SAgwOPIP gp5Ib3ZvWiSJodB6Apm3xDDSwmgflnx86hyrOTVd2CQbjmZNdRduoy0YrRRTz3Zi 9IcqlzwbQxowESGSFhjpZPBTiIDROnZIDHM5MzD+bThmr/VSh8Xt4WLHpDah7DJ4 U5SGkTIo7Q5oYyi60gMhXMxHZp0QlC1XH3rNCz7e1SuqhgCK68tmvHplJP6+6IiZ y472Q2+2pdlIr7hB3EZkDeYZl6OGXu5vG7YJvpbnQpJ+DVlAr4k= =kwNh -----END PGP SIGNATURE----- --JS1ad62fZI2q7fMF--