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=N9D/1UDi; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 27DB65A0272 for ; Wed, 27 May 2026 05:26:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779852384; bh=WMDM7/L8Zc2aNHRiRSMJiNVqpTpjuraRXWrspIygz40=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=N9D/1UDiVxLXI20Y1dYG/I1iAZXUME1NiKzZQU/JeI5lwgrGzXxXXeIeKmOT2B0zp Yh0FwIhELPJ02k+4Vg2oyW/F4GMHmF4DFdKzTmquROwfYrmKI55QNTHyRUEfMt7j/5 Lk4z23zwvVWTJowZrWjCaJ9f7H/8hLVTBkzOnNLOJAqcBnMplS0gRa+gkCyIclsMjO bxuYbPts5edoTKkoW+MVtNQJaiqldo0QD5fEHzAkU0lrFUHzmqYiGDHBami/LE9agC Qr9WBU1FGEWCTnMuRpnJTScHCnRhxowvp6ACG5XJDm3NFeLM8y5HAUqXaPoJnU5e0y BrreqvinzRLLg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gQFQR71wGz4w9g; Wed, 27 May 2026 13:26:23 +1000 (AEST) Date: Wed, 27 May 2026 12:51:16 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v2 1/6] conf: Add --dhcp-opt command-line option Message-ID: References: <20260526123115.1226166-1-anskuma@redhat.com> <20260526123115.1226166-2-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="1GIS8lTajZtiJcyJ" Content-Disposition: inline In-Reply-To: <20260526123115.1226166-2-anskuma@redhat.com> Message-ID-Hash: EE3XNJVGV5YALYQXWTETGI23I2TIW5UI X-Message-ID-Hash: EE3XNJVGV5YALYQXWTETGI23I2TIW5UI 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, sbrivio@redhat.com, jmaloy@redhat.com, lvivier@redhat.com 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: --1GIS8lTajZtiJcyJ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 26, 2026 at 06:01:08PM +0530, Anshu Kumari wrote: > Introduce the --dhcp-opt flag that allows setting arbitrary DHCP > options from command-line in the form of [Option CODE,VALUE]. > This patch adds the option storage in struct ctx and CLI parsing; > the type-aware value parser and DHCP reply injection follow > in subsequent patches. >=20 > Link: https://bugs.passt.top/show_bug.cgi?id=3D192 > Signed-off-by: Anshu Kumari Mostly LGTM, but one query below. > --- > v2: > - Added kerneldoc for @custom_opts, @custom_opts.code, @custom_opts.str= , and @custom_opts_count in struct ctx > - Removed len and val[255] fields from struct (moved to patch=C2=A03) > - Removed braces from case 33, moved declarations (optcode, comma, end)= to function scope > - Renamed code =E2=86=92 optcode to follow function-scope convention > --- > conf.c | 34 +++++++++++++++++++++++++++++++++- > passt.h | 12 ++++++++++++ > 2 files changed, 45 insertions(+), 1 deletion(-) >=20 > diff --git a/conf.c b/conf.c > index 029b9c7..89d2127 100644 > --- a/conf.c > +++ b/conf.c > @@ -47,6 +47,7 @@ > #include "lineread.h" > #include "isolation.h" > #include "log.h" > +#include "dhcp.h" > #include "vhost_user.h" > #include "epoll_ctl.h" > #include "conf.h" > @@ -616,7 +617,8 @@ static void usage(const char *name, FILE *f, int stat= us) > " -S, --search LIST Space-separated list, search domains\n" > " a single, empty option disables the DNS search list\n" > " -H, --hostname NAME Hostname to configure client with\n" > - " --fqdn NAME FQDN to configure client with\n"); > + " --fqdn NAME FQDN to configure client with\n" > + " --dhcp-opt CODE,VAL Set DHCP option by code\n"); > if (strstr(name, "pasta")) > FPRINTF(f, " default: don't use any search list\n"); > else > @@ -844,6 +846,10 @@ static void conf_print(const struct ctx *c) > info(" router: %s", > inet_ntop(AF_INET, &c->ip4.guest_gw, > buf, sizeof(buf))); > + for (i =3D 0; i < c->custom_opts_count; i++) > + info(" option %u: %s", > + c->custom_opts[i].code, > + c->custom_opts[i].str); > } > =20 > for (i =3D 0; i < ARRAY_SIZE(c->ip4.dns); i++) { > @@ -1233,6 +1239,7 @@ void conf(struct ctx *c, int argc, char **argv) > {"migrate-no-linger", no_argument, NULL, 30 }, > {"stats", required_argument, NULL, 31 }, > {"conf-path", required_argument, NULL, 'c' }, > + {"dhcp-opt", required_argument, NULL, 33 }, > { 0 }, > }; > const char *optstring =3D "+dqfel:hs:c:F:I:p:P:m:a:n:M:g:i:o:D:S:H:461t= :u:T:U:"; > @@ -1248,10 +1255,13 @@ void conf(struct ctx *c, int argc, char **argv) > uint8_t prefix_len_from_opt =3D 0; > unsigned int ifi4 =3D 0, ifi6 =3D 0; > const char *logfile =3D NULL; > + unsigned long optcode; > char *runas =3D NULL; > size_t logsize =3D 0; > + const char *comma; > long fd_tap_opt; > int name, ret; > + char *end; > uid_t uid; > gid_t gid; > =09 > @@ -1465,6 +1475,28 @@ void conf(struct ctx *c, int argc, char **argv) > die("Can't display statistics if not running in foreground"); > c->stats =3D strtol(optarg, NULL, 0); > break; > + case 33: > + comma =3D strchr(optarg, ','); > + if (!comma) > + die("--dhcp-opt requires Option CODE,VALUE format"); > + > + optcode =3D strtoul(optarg, &end, 0); > + if (end !=3D comma || optcode < 1 || optcode > 254) > + die("DHCP option code must be 1-254: %s", > + optarg); > + > + if (c->custom_opts_count >=3D MAX_CUSTOM_DHCP_OPTS) > + die("Too many --dhcp-opt entries (max %d)", > + MAX_CUSTOM_DHCP_OPTS); > + > + c->custom_opts[c->custom_opts_count].code =3D optcode; What happens if the user specifies the same DHCP option code multiple times? I don't know off-hand if DHCP allows the same option to be presented multiple times; I'm guessing not. In which case we probably want to check for already-specified options and overwrite them, instead of adding them to the array twice. > + if (snprintf_check(c->custom_opts[c->custom_opts_count].str, > + sizeof(c->custom_opts[0].str), > + "%s", comma + 1)) > + die("DHCP option value too long: %s", > + comma + 1); > + c->custom_opts_count++; > + break; > case 'd': > c->debug =3D 1; > c->quiet =3D 0; > diff --git a/passt.h b/passt.h > index 1726965..3a0816f 100644 > --- a/passt.h > +++ b/passt.h > @@ -182,6 +182,10 @@ struct ip6_ctx { > * @dns_search: DNS search list > * @hostname: Guest hostname > * @fqdn: Guest FQDN > + * @custom_opts: User-specified DHCP options from --dhcp-opt > + * @custom_opts.code: DHCP option code > + * @custom_opts.str: Original string value from command line > + * @custom_opts_count: Number of entries in @custom_opts > * @ifi6: Template interface for IPv6, -1: none, 0: IPv6 disabled > * @ip6: IPv6 configuration > * @pasta_ifn: Name of namespace interface for pasta > @@ -263,6 +267,14 @@ struct ctx { > char hostname[PASST_MAXDNAME]; > char fqdn[PASST_MAXDNAME]; > =20 > +#define MAX_CUSTOM_DHCP_OPTS 32 > + > + struct { > + uint8_t code; > + char str[256]; > + } custom_opts[MAX_CUSTOM_DHCP_OPTS]; > + int custom_opts_count; > + > int ifi6; > struct ip6_ctx ip6; > =20 > --=20 > 2.54.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 --1GIS8lTajZtiJcyJ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoWXCMACgkQzQJF27ox 2GeLig/8CJn4t1fMK938M20IPppRcYBNYXH00rYkO+ZVMK3mQUWbFAvevlFHgwfA OzVgJ6dPDLm65/+pZXmFyzClv23LLiWbpvbky0g9T3zTHw2C6QRfhxfpdWfnz6jW 70qIE4u59M7MjlvssRNEwGaIGKo9UkK0kbW8RpHRsWjMHdfP6GiwZ8HgLAZKUm4H +O4TrEVkZ3svTXCQAcCAS2rpha7itPK3ARI5WGlHin18xoM1kfXSTZgVlbZSihUI JOVGltVuiuw/U9+KEy1beNZB6OjEGOA9TrEzqXrvJIBMZuDahDFO6s+O2udko+Nk 88P5dcFCixBgKnnnVoYcr45n7kFa7NBM86W7GPEHsn/G5Co0qhv7jmmkc9UXOH+h fSoxxKwBCK6Am3hO2uURh3daXbV0x+FAGu3Dgw4JPHGyZHzqW/g/N3aWY3sIm+ap lyOS4Hrx/+tCzrgRqMdx/J63/O0h3oI7ha9zBEmbIEZ0lkcJeiTaJAYWbYbYk4ZC 5Y6KUkAitopVeC+dRn4y5kciqNetet0jMmqZWESSqQxi9FPkRCO3uiP+41PwFqTo Ygd84NSe9rH4FY/eZhqbt8MIUg1EiKNEMlsPkkKVp7ETx17rSS6CnsOy8WSvFCNK +xRxyeVEJzNzRE2hyK2ChWde2T53tUzRTNKhXRSTuTU2bYZFnPU= =rkI7 -----END PGP SIGNATURE----- --1GIS8lTajZtiJcyJ--