On Fri, 19 Jun 2026 12:59:10 +0530
Anshu Kumari
On Fri, Jun 19, 2026 at 9:24 AM David Gibson
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
--- 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