On Fri, Jun 19, 2026 at 12:59:10PM +0530, Anshu Kumari wrote:
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.
Right, I understand that. What I'm suggesting is that you keep the binary value from the initial parse (that also error checks) - like you did in the earlier versions - but that it be kept in the opts[] array instead of in a new data structure. -- 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