From: David Gibson <david@gibson.dropbear.id.au>
To: Anshu Kumari <anskuma@redhat.com>
Cc: passt-dev@passt.top, sbrivio@redhat.com, jmaloy@redhat.com,
lvivier@redhat.com
Subject: Re: [PATCH v2 1/6] conf: Add --dhcp-opt command-line option
Date: Thu, 28 May 2026 15:22:14 +1000 [thread overview]
Message-ID: <ahfRBq69n78a17iM@zatzit> (raw)
In-Reply-To: <CADJNnVKKnO1YGrU+m7n4SZGvSk6+szZkHD196wUQLBC-kiAFmg@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 8364 bytes --]
On Thu, May 28, 2026 at 10:32:54AM +0530, Anshu Kumari wrote:
> On Wed, May 27, 2026 at 8:56 AM David Gibson <david@gibson.dropbear.id.au>
> wrote:
>
> > 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.
> > >
> > > Link: https://bugs.passt.top/show_bug.cgi?id=192
> > > Signed-off-by: Anshu Kumari <anskuma@redhat.com>
> >
> > 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 3)
> > > - Removed braces from case 33, moved declarations (optcode, comma,
> > end) to function scope
> > > - Renamed code → optcode to follow function-scope convention
> > > ---
> > > conf.c | 34 +++++++++++++++++++++++++++++++++-
> > > passt.h | 12 ++++++++++++
> > > 2 files changed, 45 insertions(+), 1 deletion(-)
> > >
> > > 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
> > status)
> > > " -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 = 0; i < c->custom_opts_count; i++)
> > > + info(" option %u: %s",
> > > + c->custom_opts[i].code,
> > > + c->custom_opts[i].str);
> > > }
> > >
> > > for (i = 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 =
> > "+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 = 0;
> > > unsigned int ifi4 = 0, ifi6 = 0;
> > > const char *logfile = NULL;
> > > + unsigned long optcode;
> > > char *runas = NULL;
> > > size_t logsize = 0;
> > > + const char *comma;
> > > long fd_tap_opt;
> > > int name, ret;
> > > + char *end;
> > > uid_t uid;
> > > gid_t gid;
> > >
> > > @@ -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 = strtol(optarg, NULL, 0);
> > > break;
> > > + case 33:
> > > + comma = strchr(optarg, ',');
> > > + if (!comma)
> > > + die("--dhcp-opt requires Option CODE,VALUE
> > format");
> > > +
> > > + optcode = strtoul(optarg, &end, 0);
> > > + if (end != comma || optcode < 1 || optcode > 254)
> > > + die("DHCP option code must be 1-254: %s",
> > > + optarg);
> > > +
> > > + if (c->custom_opts_count >= MAX_CUSTOM_DHCP_OPTS)
> > > + die("Too many --dhcp-opt entries (max %d)",
> > > + MAX_CUSTOM_DHCP_OPTS);
> > > +
> > > + c->custom_opts[c->custom_opts_count].code =
> > 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 a user specifies the same DHCP option code multiple times, the option
> value is overwritten.
> The last specified value is considered, like if we run below command
>
> ./passt -f --dhcp-opt 6,8.8.8.8,8.8.4.4 --dhcp-opt 6,1.1.1.1,9.9.9.9
>
> then passt DHCP option stores the last value
> DHCP:
> assign: 192.168.1.9
> mask: 255.255.255.0
> router: 192.168.1.1
> option 6: 1.1.1.1,9.9.9.9
Ok, that's good. It's not clear to me where that behaviour is
implemented: the option parsing logic here seems to just add things to
the list, even if they're the same option.
> >
> > > + 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 = 1;
> > > c->quiet = 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];
> > >
> > > +#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;
> > >
> > > --
> > > 2.54.0
> > >
> >
> > --
> > 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
> >
--
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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2026-05-28 5:22 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-26 12:31 [PATCH v2 0/6] Add --dhcp-boot and --dhcp-opt options Anshu Kumari
2026-05-26 12:31 ` [PATCH v2 1/6] conf: Add --dhcp-opt command-line option Anshu Kumari
2026-05-26 13:19 ` Laurent Vivier
2026-05-27 2:51 ` David Gibson
2026-05-28 5:02 ` Anshu Kumari
2026-05-28 5:22 ` David Gibson [this message]
2026-05-27 7:23 ` Laurent Vivier
2026-05-26 12:31 ` [PATCH v2 2/6] conf: Add --dhcp-boot " Anshu Kumari
2026-05-26 13:25 ` Laurent Vivier
2026-05-27 2:52 ` David Gibson
2026-05-28 5:14 ` Anshu Kumari
2026-05-27 6:59 ` Laurent Vivier
2026-05-26 12:31 ` [PATCH v2 3/6] dhcp: Add option type table and value parser Anshu Kumari
2026-05-26 16:05 ` Laurent Vivier
2026-05-27 3:00 ` David Gibson
2026-05-28 5:39 ` Anshu Kumari
2026-05-28 5:45 ` David Gibson
2026-05-27 3:26 ` David Gibson
2026-05-26 12:31 ` [PATCH v2 4/6] dhcp: Refactor fill_one() to operate on a generic buffer Anshu Kumari
2026-05-26 16:13 ` Laurent Vivier
2026-05-27 3:46 ` David Gibson
2026-05-26 12:31 ` [PATCH v2 5/6] dhcp: Add option overload Anshu Kumari
2026-05-26 17:42 ` Laurent Vivier
2026-05-27 4:03 ` David Gibson
2026-05-28 7:18 ` Anshu Kumari
2026-05-26 12:31 ` [PATCH v2 6/6] doc: Add --dhcp-boot and --dhcp-opt to man page Anshu Kumari
2026-05-27 4:16 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ahfRBq69n78a17iM@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=anskuma@redhat.com \
--cc=jmaloy@redhat.com \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).