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=202606 header.b=jgO/fXqn; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 92DEC5A0624 for ; Wed, 01 Jul 2026 05:04:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1782875034; bh=TZwk8wLdMv9ojFbYYcA1y6KUGbuUFgkg3HBTGXxxY64=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=jgO/fXqnBcK/f0QbXP1CGno8VrrG8Ybriqv3PjmbOONYId1/N8I9S6fEKmRkyvsEY 9QM4OETh7oEX1agV2HsgyJs8RrcsFfkS0k4njyZjdjwC0T08MHjCj7HRNG++997jco YItaT+JEC8bIKiABA5R477yub11aaxpm2yNZPUixYOD+kubGKCvUdturnuFdOyiZis zvtu3iUETfN1zjWdYuoag5oMfOrFfgoXu6RVVho6CWAs2hKTSzHEWMVWbFr09ghMJ8 7NwGCsh+LtOzPIc8tkAC07PbjevTWUECn+8eAvpQ43vF9DAEKzhqq1ekfQi/ccpi3A iTX2wLiSHqEQg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gqlGL3sspz4wZk; Wed, 01 Jul 2026 13:03:54 +1000 (AEST) Date: Wed, 1 Jul 2026 11:44:56 +1000 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 09/12] conf: Move address configuration into helper function Message-ID: References: <20260626071003.3472194-1-david@gibson.dropbear.id.au> <20260626071003.3472194-10-david@gibson.dropbear.id.au> <20260701020735.73596cda@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="nUqARGCEuNKuEihT" Content-Disposition: inline In-Reply-To: <20260701020735.73596cda@elisabeth> Message-ID-Hash: JMAMQ2SJZHNK2XNQYG4JW2GD3FGDO2W4 X-Message-ID-Hash: JMAMQ2SJZHNK2XNQYG4JW2GD3FGDO2W4 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: passt-dev@passt.top, Jon Maloy 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: --nUqARGCEuNKuEihT Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jul 01, 2026 at 02:07:38AM +0200, Stefano Brivio wrote: > On Fri, 26 Jun 2026 17:10:00 +1000 > David Gibson wrote: >=20 > > The handling of the -a option is getting complex enough that it's pretty > > bulky inside it's switch label. Move it into a new conf_addr() functio= n. >=20 > Nit if you respin: 'its'. Done. >=20 > > We also rename the bulky addr_has_prefix_len and prefix_len_from_opt > > variables to the terser 'opt_a_is_prefix' and 'opt_n', since they are > > specifically about those command line options. > >=20 > > Cc: Jon Maloy > >=20 > > Signed-off-by: David Gibson > > --- > > conf.c | 96 ++++++++++++++++++++++++++++++++-------------------------- > > 1 file changed, 53 insertions(+), 43 deletions(-) > >=20 > > diff --git a/conf.c b/conf.c > > index 2d1895d4..3614776c 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -1168,6 +1168,53 @@ int conf_tap_fd(const char *arg) > > return val; > > } > > =20 > > +/** > > + * conf_addr() - Configure guest address with -a option > > + * @c: Execution context > > + * @arg: -a command line argument > > + * @opt_n: Value from -n option, if any > > + */ > > +static bool conf_addr(struct ctx *c, char *arg, uint8_t opt_n) > > +{ > > + union inany_addr addr; > > + const char *p =3D arg; > > + uint8_t prefix_len; > > + bool is_prefix; > > + > > + is_prefix =3D inany_prefix_pton(arg, &addr, &prefix_len); > > + > > + if (is_prefix && opt_n) > > + die("Redundant prefix length specification"); > > + > > + if (!is_prefix && > > + !(parse_inany(&p, &addr) && parse_eoi(p))) > > + die("Invalid address: %s", arg); > > + > > + if (opt_n && inany_v4(&addr)) > > + prefix_len =3D opt_n; > > + else if (!is_prefix) > > + prefix_len =3D inany_default_prefix_len(&addr); > > + > > + if (inany_is_unspecified(&addr) || inany_is_multicast(&addr) || > > + inany_is_loopback(&addr) || IN6_IS_ADDR_V4COMPAT(&addr.a6)) > > + die("Invalid address: %s", arg); > > + > > + if (inany_v4(&addr)) { > > + c->ip4.addr =3D *inany_v4(&addr); > > + c->ip4.prefix_len =3D prefix_len - 96; > > + c->ip4.addr_fixed =3D true; > > + if (c->mode =3D=3D MODE_PASTA) > > + c->ip4.no_copy_addrs =3D true; > > + } else { > > + c->ip6.addr =3D addr.a6; > > + c->ip6.addr_fixed =3D true; > > + if (c->mode =3D=3D MODE_PASTA) > > + c->ip6.no_copy_addrs =3D true; > > + } > > + > > + return is_prefix; > > +} > > + > > /** > > * conf() - Process command-line arguments and set configuration > > * @c: Execution context > > @@ -1262,12 +1309,12 @@ void conf(struct ctx *c, int argc, char **argv) > > unsigned dns4_idx =3D 0, dns6_idx =3D 0; > > unsigned long max_mtu =3D IP_MAX_MTU; > > struct fqdn *dnss =3D c->dns_search; > > - bool addr_has_prefix_len =3D false; > > - uint8_t prefix_len_from_opt =3D 0; > > unsigned int ifi4 =3D 0, ifi6 =3D 0; > > + bool opt_a_is_prefix =3D false; > > const char *logfile =3D NULL; > > char *runas =3D NULL; > > size_t logsize =3D 0; > > + uint8_t opt_n =3D 0; > > int name, ret; > > uid_t uid; > > gid_t gid; > > @@ -1567,52 +1614,15 @@ void conf(struct ctx *c, int argc, char **argv) > > c->mtu =3D mtu; > > break; > > } > > - case 'a': { > > - union inany_addr addr; > > - uint8_t prefix_len; > > - > > - addr_has_prefix_len =3D inany_prefix_pton(optarg, &addr, > > - &prefix_len); > > - > > - if (addr_has_prefix_len && prefix_len_from_opt) > > - die("Redundant prefix length specification"); > > - > > - p =3D optarg; > > - if (!addr_has_prefix_len && > > - !(parse_inany(&p, &addr) && parse_eoi(p))) > > - die("Invalid address: %s", optarg); > > - > > - if (prefix_len_from_opt && inany_v4(&addr)) > > - prefix_len =3D prefix_len_from_opt; > > - else if (!addr_has_prefix_len) > > - prefix_len =3D inany_default_prefix_len(&addr); > > - > > - if (inany_is_unspecified(&addr) || > > - inany_is_multicast(&addr) || > > - inany_is_loopback(&addr) || > > - IN6_IS_ADDR_V4COMPAT(&addr.a6)) > > - die("Invalid address: %s", optarg); > > - > > - if (inany_v4(&addr)) { > > - c->ip4.addr =3D *inany_v4(&addr); > > - c->ip4.prefix_len =3D prefix_len - 96; > > - c->ip4.addr_fixed =3D true; > > - if (c->mode =3D=3D MODE_PASTA) > > - c->ip4.no_copy_addrs =3D true; > > - } else { > > - c->ip6.addr =3D addr.a6; > > - c->ip6.addr_fixed =3D true; > > - if (c->mode =3D=3D MODE_PASTA) > > - c->ip6.no_copy_addrs =3D true; > > - } > > + case 'a': > > + opt_a_is_prefix =3D conf_addr(c, optarg, opt_n); > > break; > > - } > > case 'n': > > - if (addr_has_prefix_len) > > + if (opt_a_is_prefix) > > die("Redundant prefix length specification"); > > =20 > > c->ip4.prefix_len =3D conf_ip4_prefix(optarg); > > - prefix_len_from_opt =3D c->ip4.prefix_len + 96; > > + opt_n =3D c->ip4.prefix_len + 96; > > break; > > case 'M': > > parse_mac(c->our_tap_mac, optarg); >=20 > --=20 > Stefano >=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 --nUqARGCEuNKuEihT Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpEcRIACgkQzQJF27ox 2Gd4MhAAlevDu6NueVo4OjJMOROwdEP9VPcbriTYCOuebRsRKBgtGrZ4A3WePp/0 2oZhLzhs++CQBIPyHZodUiK3TTKWpznlEfECXwbOPYK4+rLunyWit9Nu9H4oNGKr 76f3HSOmNhs5Ifi0i+HpmxhxCQjHC7WpdaH1iZhaOJr/RVGDgU8+XUfFpK9Iuo63 hsZQmWgv008iPan85avH0rDcS/pMTFhIVZz07hd8avKSRKRDU6uXmWHrctIIpTkG bXtLJ2WyMaiZ+7V2tJ/gy+1+5eKyS6cLOUxqYNnkulIWd5buMp+4F1a6rJ4UUb1w VP89gjDs7t+DepXB6D2udOdNmPpb1IbP1J60YRANR+FFoxxWcsiT2Z2Ah5jgdJr6 P/qdJIRzzEUR+Rh0iV8GnI6rms8CadtF6kE/xYX9H5wL0JAFXN3evBOVx7a0ENCC 7AqAMSs6gPUSoGZz49ZRFflaVptzCwYp96EU3IOjrT/u+ArPN1AesMoKkVGWfJtF L364B7il90kcTB3WGN5R1RE/n6/6vtNUlJ47vmhpbqj0qA7QwPB3V1H1hHf9fW7n hnEgkcIQORMtfHENFgrmYAdkLhqUNnEHRwmwfA0gP4RZRAAUZKfjFgCCuD76TC7H 1soqyl0AM0cl40ux11pvAlNcOXjUkVLwrdMAzM0mUd2zqOq9ljo= =fEWw -----END PGP SIGNATURE----- --nUqARGCEuNKuEihT--