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=202502 header.b=hxow9Ebr; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id A31775A0008 for ; Wed, 12 Mar 2025 01:57:23 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202502; t=1741741022; bh=tSAUFIu9Brc1hgolTh4BAJZV1W/jXP4MFF91d22dXkc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hxow9EbrjpcbZ+LjQwNxnk0XyrezvliRJV49rCB1vkY8Zl+yRboaCZQIKDYmCnAZn hmqxLjr6mqLq24Z5bJtft1fL0W1bN6tB9oVYfCFe4pxQmmhTuyXWi5nZF1ofKtoV+/ B5t9mFozT540Gvi8yjkvgxysD/XKtIFg8JIyWtcgIQHYuv6cXW7ZxgdL+vnU/v37ba OKXB0ML6RtU/xYw21Ec98Uemk0kh7HUHKI75URCCqFfN8DzEK7bBtjceOMDGLYCZqc KeKm5CQ2XF45SX6UFC3CxGgL1glyY+yXGCbnK54p1l0IdXDZCBzAaxxwiboXoQUCaQ hHOC0ZtxBdcEQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZCBzf0vVhz4x04; Wed, 12 Mar 2025 11:57:02 +1100 (AEDT) Date: Wed, 12 Mar 2025 11:48:56 +1100 From: David Gibson To: Stefano Brivio Subject: Re: [PATCH 3/9] conf: Detect vhost-user mode earlier Message-ID: References: <20250311060318.1502861-1-david@gibson.dropbear.id.au> <20250311060318.1502861-4-david@gibson.dropbear.id.au> <20250311234503.5bb0d132@elisabeth> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="8DF12FIeqi89Sq/D" Content-Disposition: inline In-Reply-To: <20250311234503.5bb0d132@elisabeth> Message-ID-Hash: DE5GDGTH6QTB6GDYDDSZY25DHYCZKNFH X-Message-ID-Hash: DE5GDGTH6QTB6GDYDDSZY25DHYCZKNFH 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 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: --8DF12FIeqi89Sq/D Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Mar 11, 2025 at 11:45:03PM +0100, Stefano Brivio wrote: > On Tue, 11 Mar 2025 17:03:12 +1100 > David Gibson wrote: >=20 > > We detect our operating mode in conf_mode(), unless we're using vhost-u= ser > > mode, in which case we change it later when we parse the --vhost-user > > option. That means we need to delay parsing the --repair-path option (= for > > vhost-user only) until still later. > >=20 > > However, there are many other places in the main option parsing loop wh= ich > > also rely on mode. We get away with those, because they happen to be a= ble > > to treat passt and vhost-user modes identically. This is potentially > > confusing, though. So, move setting of MODE_VU into conf_mode() so > > c->mode always has its final value from that point onwards. > >=20 > > To match, we move the parsing of --repair-path back into the main option > > parsing loop. > >=20 > > Signed-off-by: David Gibson > > --- > > conf.c | 43 ++++++++++++++++++++++++++----------------- > > 1 file changed, 26 insertions(+), 17 deletions(-) > >=20 > > diff --git a/conf.c b/conf.c > > index 2022ea1d..b58e2a6e 100644 > > --- a/conf.c > > +++ b/conf.c > > @@ -998,10 +998,23 @@ pasta_opts: > > * > > * Return: mode to operate in, PASTA or PASST > > */ > > -/* cppcheck-suppress constParameter */ > > enum passt_modes conf_mode(int argc, char *argv[]) > > { > > + int vhost_user =3D 0; > > + const struct option optvu[] =3D { > > + {"vhost-user", no_argument, &vhost_user, 1 }, > > + { 0 }, > > + }; > > char argv0[PATH_MAX], *basearg0; > > + int name; > > + > > + optind =3D 0; > > + do { > > + name =3D getopt_long(argc, argv, "-:", optvu, NULL); > > + } while (name !=3D -1); > > + > > + if (vhost_user) > > + return MODE_VU; > > =20 > > if (argc < 1) > > die("Cannot determine argv[0]"); > > @@ -1604,9 +1617,8 @@ void conf(struct ctx *c, int argc, char **argv) > > =20 > > die("Invalid host nameserver address: %s", optarg); > > case 25: > > - if (c->mode =3D=3D MODE_PASTA) > > - die("--vhost-user is for passt mode only"); >=20 > This check should now be moved to conf_mode() instead of being dropped, > otherwise you can do: >=20 > $ ./pasta -f --vhost-user >=20 > and at this point, the mode is MODE_VU, so it's all fine, but I don't > think it's intended (...or is it?). It's more or less intended. To me it seemed simpler to treat "vhost-user mode" as co-equal with "/dev/net/tun mode" (pasta) or "qemu -net stream mode" (passt), rather than having vu be sort of a sub-mode of passt. It's true that vu mode has slightly more in common with passt mode than pasta at the moment, but I don't see that as really inherent. I also saw this as a precursor to a "--mode whatever" option which would override the mode regardless of argv[0], in case there are circumstances where manipulating argv[0] is inconvenient. But if you'd really prefer I can reinstate the check. > > - c->mode =3D MODE_VU; > > + /* Already handled in conf_mode() */ > > + ASSERT(c->mode =3D=3D MODE_VU); > > break; > > case 26: > > vu_print_capabilities(); >=20 > Pre-existing, but now we can fix this: case 26 (--print-capabilities) > should only be accepted if (c->mode =3D=3D MODE_VU). I was unsure about this, because I wasn't certain if --vhost-user was passed when we were invoked just to probe capabilities. > It can also be done in another patch I would say, if you don't want to > re-spin this. >=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 --8DF12FIeqi89Sq/D Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmfQ2fcACgkQzQJF27ox 2Ge+2g//dYaBPRy/wesO+PnTAR3zbQ3s06B+/WinrwOFcSZ5o2p9edCsTZbW1v8v HrtkPdvyAOGBV2fGz+qr5fPfY/O90g0TVerosnEvZnQHmedABOR0XFrssJpA4+qA gmO/gR4E5naark6/iaxxOxn6tLMhsYgc1Dch35c5VX/IdqoxkePWY8mH9633/Aks dEkeJxGuvyjfSFXFmxjx6meeBDpkZh9Dij9xe1X7J/6vvMb5V/UcCT/2C1rjNFJB Cba7vLb1Qz6Hj3lun5uFKVDDHMW8Yn6WRaSbU3a/Iwgll6yQ5FP7hDX2OmRzwup+ s5kLzGFYlykuvS5a2vxPeyVs+PgXW4k5gwNwuGqlD7VQbrJieG1b8D8zysPKX9eX DSu005lcCOPNi3IaIQ4T1HW+YQi1FKavo78lfxkSKzQQ+YJ9/8ENtuaAkpjDY2fp QdJ2cDwrhGMzrgHLIsFAoZw8Po4ahK6/eW9zf98HDbSPYXlDkNhUh59p0TPW4Y3Z lb+XGj7LCeG5s+cThyvI5joABqK3YUDGntNt5Lctyu9885VZuDEeIR2wPf/eZZDj D+tVIDuo029hY8KEWSwkkmNS5nEWfwHXRGBr6PeHmd1k0BGQkPzxsit6huKPMcZX NS6n0u738GF4hnoK97lwO3cHM3n4RX5tbCB74jv8/m+46XtZlyM= =Z++x -----END PGP SIGNATURE----- --8DF12FIeqi89Sq/D--