From: Stefano Brivio <sbrivio@redhat.com>
To: Anshu Kumari <anskuma@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>,
passt-dev@passt.top, jmaloy@redhat.com, lvivier@redhat.com
Subject: Re: [PATCH v4 3/4] dhcp: Add --dhcp-opt with option table and value parser
Date: Wed, 01 Jul 2026 09:51:16 +0200 (CEST) [thread overview]
Message-ID: <20260701095115.4834f6fa@elisabeth> (raw)
In-Reply-To: <CADJNnV+bXYBarBDuGLLdXzHaz3e-5ggE9MgNtYEHB6Er+TqrKA@mail.gmail.com>
On Fri, 19 Jun 2026 12:59:10 +0530
Anshu Kumari <anskuma@redhat.com> wrote:
> On Fri, Jun 19, 2026 at 9:24 AM David Gibson <david@gibson.dropbear.id.au>
> wrote:
>
> > On Wed, Jun 17, 2026 at 06:52:37PM +0530, Anshu Kumari wrote:
> > > Introduce the --dhcp-opt flag that allows setting arbitrary DHCP
> > > options from command-line in the form [--dhcp-opt CODE,VALUE].
> > >
> > > Add a type lookup table mapping option codes to RFC 2132 value types
> > > (IPv4, IPv4 list, integer, string) and dhcp_opt_parse() to convert
> > > CLI strings to binary wire format. Parsed options are stored in
> > > struct ctx and injected into DHCP replies. If the same option code
> > > is given more than once, the last value wins.
> > >
> > > Link: https://bugs.passt.top/show_bug.cgi?id=192
> > > Signed-off-by: Anshu Kumari <anskuma@redhat.com>
> > > ---
> > > v4:
> > > - Renamed custom_opts to dhcp_opts, 256 entries indexed by option
> > > code, removed MAX_CUSTOM_DHCP_OPTS and count field.
> > > - Changed str buffer from 256 to 255 bytes.
> > > - Moved function to conf.c as static conf_dhcp_option(), renamed
> > > from dhcp_add_option().
> > > - Made dhcp_opt_parse() non-static, declared in dhcp.h
> > > - Dropped val/len from ctx struct; conf_dhcp_option() validates
> > > with temp buffer, dhcp() parses str directly into opts[] at
> > > reply time.
> >
> > Hmm. So each option is parsed twice. What prevents you from parsing
> > directly into the opts[] array at conf() time?
>
> The first parse acts as a validation step to check that the user has
> entered the
> correct value format for the option. Without it, if the user passes
> something
> like *--dhcp-opt 3,notanip*, the error would surface only when the first
> DHCP client connects, not at startup.
>
> I think it's better to fail during startup if correct value format is not
> entered in command-line rather than failing at later
> stage during reply time.
Sure, I would say we have to.
But I think David was suggesting (that would be my suggestion as well)
that you actually validate values right away, and store them directly
into opts[], instead of having two steps and keeping a c->dhcp_opts[]
array in parallel.
The downside of a single parsing step, without duplicating values, is
that you would need to render values back from opts[] to print them in
conf_print(). But it should be relatively trivial. It might actually be
less code than it is now.
--
Stefan
next prev parent reply other threads:[~2026-07-01 7:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 13:22 [PATCH v4 0/4] Add --dhcp-boot and --dhcp-opt options Anshu Kumari
2026-06-17 13:22 ` [PATCH v4 1/4] dhcp: Refactor fill_one() to operate on a generic buffer Anshu Kumari
2026-06-19 3:26 ` David Gibson
2026-07-01 7:51 ` Stefano Brivio
2026-06-17 13:22 ` [PATCH v4 2/4] dhcp: Add option overload Anshu Kumari
2026-06-19 3:39 ` David Gibson
2026-06-19 7:55 ` Anshu Kumari
2026-06-22 2:43 ` David Gibson
2026-07-01 7:51 ` Stefano Brivio
2026-07-01 17:00 ` Stefano Brivio
2026-06-17 13:22 ` [PATCH v4 3/4] dhcp: Add --dhcp-opt with option table and value parser Anshu Kumari
2026-06-19 3:52 ` David Gibson
2026-06-19 7:29 ` Anshu Kumari
2026-06-22 2:42 ` David Gibson
2026-07-01 7:51 ` Stefano Brivio [this message]
2026-07-01 17:00 ` Stefano Brivio
2026-06-17 13:22 ` [PATCH v4 4/4] conf: Add --dhcp-boot command-line option Anshu Kumari
2026-06-19 3:53 ` 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=20260701095115.4834f6fa@elisabeth \
--to=sbrivio@redhat.com \
--cc=anskuma@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=jmaloy@redhat.com \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
/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).