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=LDXkD7OZ; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 5A8625A0269 for ; Tue, 19 May 2026 08:12:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779171122; bh=L095Ve14YSIro65aNzcEdwwkzIvbt7mA4JGs2sGB6Zg=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=LDXkD7OZVqHg9aS/aUjKAUF8Bw2DdLDz+gMqIx6eJUP+WN1ik+2BMGuMe7ebKC/xW 171/hiPAVsRD0FvjyVPJ7EIeaSCBTMcZZwDpev/WwNKguMhRoxi4pBn9IGZC+AGA4+ r7+eiGJzUYdu8QEicrGkd1rA9Zje9013AHTbzZ0SFJgRL4XPrlTZup/YJOEbKZNzPy WXGIxp0/y+onAT6xmwUHReoW6bFGVCDJvAka+0gDjYBsXgDfFgcxhDDVkdvdrwG8MN u6S1IbYHa1YBfp7CHwacmvTy0jwNu92os0GIakIWUudS0DgM0CHxJNsgvX43ruglhC DKOAJ5iPLBXjQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gKPTG0lzSz4wLn; Tue, 19 May 2026 16:12:02 +1000 (AEST) Date: Tue, 19 May 2026 15:33:10 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH 1/6] conf: Add --dhcp-opt command-line option Message-ID: References: <20260518132002.418296-1-anskuma@redhat.com> <20260518132002.418296-2-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="RS5ySsz5DLXvwcL5" Content-Disposition: inline In-Reply-To: <20260518132002.418296-2-anskuma@redhat.com> Message-ID-Hash: U6L3CZFW7LUZ2KD2WIEGU5IEXVVA5KM4 X-Message-ID-Hash: U6L3CZFW7LUZ2KD2WIEGU5IEXVVA5KM4 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, passt-dev@passt.top, lvivier@redhat.com, jmaloy@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: --RS5ySsz5DLXvwcL5 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 18, 2026 at 06:49:57PM +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 > --- > conf.c | 36 +++++++++++++++++++++++++++++++++++- > passt.h | 10 ++++++++++ > 2 files changed, 45 insertions(+), 1 deletion(-) >=20 > diff --git a/conf.c b/conf.c > index 029b9c7..2624e58 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:"; > @@ -1465,6 +1472,33 @@ 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: { > + unsigned long code; > + const char *comma; > + char *end; > + > + comma =3D strchr(optarg, ','); > + if (!comma) > + die("--dhcp-opt requires Option CODE,VALUE format"); > + > + code =3D strtoul(optarg, &end, 0); > + if (end !=3D comma || code < 1 || code > 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 code; > + 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..acb57dd 100644 > --- a/passt.h > +++ b/passt.h > @@ -263,6 +263,16 @@ struct ctx { > char hostname[PASST_MAXDNAME]; > char fqdn[PASST_MAXDNAME]; > =20 > +#define MAX_CUSTOM_DHCP_OPTS 32 > + > + struct { > + uint8_t code; > + uint8_t len; > + uint8_t val[255]; The @len and @val fields are not used so far. I'm assuming they are later in the series, but in that case it's generally preferable to add those fields in the patches that use them. Possible more comments there. > + 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 --RS5ySsz5DLXvwcL5 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoL9hUACgkQzQJF27ox 2Gdv5Q/7BeGACiW6fy1g1Tk+tctWTRARpxPJYGiG3dZiHZgmGRS55H1jMFUY3IIE Y4nPr9lKDNQYDqSlRynIG6cTCTJpyzcI5H+elI/CFHTgTg8lJGiXD/LGDjMW8txF Z3JjOxE6f2G23ktbLbrKuQYKxxeMMees9NIzC7kK5Fg53EdEfDZvdryqDi0iqzWy uEIX5Zrx2WmluKoabd+/xiQbmK81StaTrNVdI0Li7jTbh2myYHJu5R5aNK85DR2d dhid1IXVWsD4IT/fkmiWEmHxFjBlqB0GyCY7YAT7ZbO6ckr1v9l51ZTk/bEFeohN jCNP2j5X5qceAUJTzIWH4FUZyT3Qgl2YrXWb5CZCGoPDjOWjp3FC7cLwnE9AvVZk Crw6ci7lqsHf+y6JNIHgtMwxdVz1z4ULjOLqDBD71iRIyWmQFhe/Ibr9hju1+T/y f3mzBGYOeO4Dp+GQwIJvbrr08iBnojKLY5y/PlYh839D0XXWVN23IcBD6Nl9Yq2n gINVvhr4wsC53efy3kv4Gg8VzdmLuJQ7xmHIznUES2jSbIlCePTfai4L3XMKbATO Qr1Q2IsVttH0PjjNLgOtCF4PG7f9UkeF+eK7QgDyZ1vASkbJBpb7M3fJXCsUfhRF o4qj22js1PV4O0sWt7dvwjSQypWCaHL1ty+4NU1m1s0UHDBZKUU= =apH/ -----END PGP SIGNATURE----- --RS5ySsz5DLXvwcL5--