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=htZGrvyY; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 5A3305A0265 for ; Tue, 02 Jun 2026 04:25:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780367126; bh=vtCKL0YAe/MT7btG/K+gJLAKhOJ9dTYT8AurFFd06EA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=htZGrvyY4FlycR6qYndNM++UVJvsOVOK89ZgQ9zG7h9MJISTuJk6VQOGv/7xbAHBs 8zHr5Lta5CMQfVcj8mI7Ym0BIEiji6jyy3ovcd2AMxpb3kq/5azWhSod1HzCmQCidk VV//DckX0tPpelSS9iaHEZ0Jz6cguLgB8e/EeGHHHbSAPKFBNHdLu2crvczzoqSdLO sbEAsXnCvY7xPGi8bAAFilGy9s+InWBLZHeYNY65S7QsLMnqZC7OcBUkKGqhk/eYpJ hoOZwWWjr2vrjK0iEuOxK3nTjCTlnRFgJ7pOZLXlM3O11BLI+KL6g7KHwcv52wZS6u xWo7Qd/SvqkOg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gTvnL0Pb2z4wJk; Tue, 02 Jun 2026 12:25:26 +1000 (AEST) Date: Tue, 2 Jun 2026 12:00:29 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v3 1/6] conf: Add --dhcp-opt command-line option Message-ID: References: <20260601073758.1571317-1-anskuma@redhat.com> <20260601073758.1571317-2-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="deVZt8P6C4tR2VVp" Content-Disposition: inline In-Reply-To: <20260601073758.1571317-2-anskuma@redhat.com> Message-ID-Hash: J4AY53JQCAFE7ANNIPQSDFR5BTVE5R5L X-Message-ID-Hash: J4AY53JQCAFE7ANNIPQSDFR5BTVE5R5L 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: --deVZt8P6C4tR2VVp Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 01, 2026 at 01:07:51PM +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 LGTM except for one remaining detail [snip] > @@ -1465,6 +1475,18 @@ 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 CODE,VALUE format"); > + > + optcode =3D strtoul(optarg, &end, 0); Sorry, missed it on the previous round of review. This strtoul() also needs the errno =3D 0 / check errno trick to catch the handful of error cases that end !=3D comma won't. > + if (end !=3D comma || optcode < 1 || optcode > 254) > + die("DHCP option code must be 1-254: %s", > + optarg); > + > + dhcp_add_option(c, optcode, comma + 1); > + break; > case 'd': > c->debug =3D 1; > c->quiet =3D 0; > diff --git a/dhcp.c b/dhcp.c > index 1ff8cba..c5fbf37 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -33,6 +33,44 @@ > #include "log.h" > #include "dhcp.h" > =20 > + > +/** > + * dhcp_add_option() - Add or update a custom DHCP option > + * @c: Execution context > + * @code: DHCP option code > + * @val_str: Value string from command line > + * > + * If @code was already added, the previous value is overwritten. > + * Calls die() on any error. > + * > + * Return: 0 on success > + */ > +int dhcp_add_option(struct ctx *c, uint8_t code, const char *val_str) > +{ > + int idx; > + > + for (idx =3D 0; idx < c->custom_opts_count; idx++) { > + if (c->custom_opts[idx].code =3D=3D code) > + break; > + } > + > + if (idx =3D=3D c->custom_opts_count) { > + 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_count++; > + } > + > + c->custom_opts[idx].code =3D code; > + > + if (snprintf_check(c->custom_opts[idx].str, > + sizeof(c->custom_opts[0].str), > + "%s", val_str)) > + die("DHCP option value too long: %s", val_str); > + > + return 0; > +} > + > /** > * struct opt - DHCP option > * @sent: Convenience flag, set while filling replies > diff --git a/dhcp.h b/dhcp.h > index cd50c99..9c8f1e3 100644 > --- a/dhcp.h > +++ b/dhcp.h > @@ -8,5 +8,6 @@ > =20 > int dhcp(const struct ctx *c, struct iov_tail *data); > void dhcp_init(void); > +int dhcp_add_option(struct ctx *c, uint8_t code, const char *val_str); > =20 > #endif /* DHCP_H */ > 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 --deVZt8P6C4tR2VVp Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoeOTwACgkQzQJF27ox 2GcCNA//dpov9PNV5tLV4XwNdnEruLoProJSG2keHqhNRlJ7ffVYyex1n9pl3Of8 rEq/5a+wc0t6YLyqreim+azxKISx6GmXc1VuENvcEavAOx1VXKJQeCl3L8r0omms 2fwsrju7+CqirzYWKL9HsEPL1SL5k33JNR9VnqtT8vB0ojzOKiWuE2IGXKn77o2U 6Fp3G0fzRB9thBBwKEgmjO5LWi/m04enfktcSCx+NsIpSUAJ1RG8GzONR9NDITb3 1iC7LZcBNtrrxgrUMkUaLXK0jqbJnLjReLUlG/YPq3yz8TTfVqf4g6gDV69uUyeD M0c+X9BBSK1zvBxwP7MEVQVR7OMOtC+n9jeWurzAyv+/4m1IB+0I3jcPsyrCnq4z UrcgkyYFPZE/MAMdja2BEnGr8HoGQRpa9b4f19nCZyKtCgWJzvOrX1GaU6pmbySc 9Rrg7yFB126bLw5ZmrpBAGANputDmm4mzdiJxhoYsUPOsDwgH+IXR21yKbBZzN5A PL4UPlhuKhy+O3BJj/z8bJupTp+RHlVtqriTe0dObRW07pkn4UqcdbvuiAsV5EnU qEnUc7TCDc8ZyM8gcor0WQKafGTuzsqt4Tj8m4/czyglP9jsHsuQs9bsNemKJ5Cn YQDRbPwOxp+zmrCUJfwy6vjMl3A87VbGuIcX4risNU/TH/aMimA= =4Lq/ -----END PGP SIGNATURE----- --deVZt8P6C4tR2VVp--