On Thu, Jun 04, 2026 at 04:21:48PM +0530, Anshu Kumari wrote: > Add a --dhcpv6-opt CODE,VALUE option for injecting custom DHCPv6 > options into server replies. This patch adds the CLI parsing in conf.c, > storage in struct ctx, and a simple dhcpv6_add_option() that stores the > option code and raw string value. > > Signed-off-by: Anshu Kumari Reviewed-by: David Gibson > --- > conf.c | 26 +++++++++++++++++++++++++- > dhcpv6.c | 37 +++++++++++++++++++++++++++++++++++++ > dhcpv6.h | 1 + > passt.1 | 6 ++++++ > passt.h | 12 ++++++++++++ > 5 files changed, 81 insertions(+), 1 deletion(-) > > diff --git a/conf.c b/conf.c > index 6f86940..ac7e6e5 100644 > --- a/conf.c > +++ b/conf.c > @@ -47,6 +47,7 @@ > #include "lineread.h" > #include "isolation.h" > #include "log.h" > +#include "dhcpv6.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" > + " --dhcpv6-opt CODE,VAL Set DHCPv6 option by code\n"); > if (strstr(name, "pasta")) > FPRINTF(f, " default: don't use any search list\n"); > else > @@ -884,6 +886,10 @@ static void conf_print(const struct ctx *c) > info(" our link-local: %s", > inet_ntop(AF_INET6, &c->ip6.our_tap_ll, > buf, sizeof(buf))); > + for (i = 0; i < c->custom_v6opts_count; i++) > + info(" v6 option %u: %s", > + c->custom_v6opts[i].code, > + c->custom_v6opts[i].str); > > dns6: > for (i = 0; i < ARRAY_SIZE(c->ip6.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' }, > + {"dhcpv6-opt", required_argument, NULL, 34 }, > { 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 v6optcode; > 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,20 @@ 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 34: > + comma = strchr(optarg, ','); > + if (!comma) > + die("--dhcpv6-opt requires CODE,VALUE format"); > + > + errno = 0; > + v6optcode = strtoul(optarg, &end, 0); > + if (end != comma || errno || > + v6optcode < 1 || v6optcode > 255) > + die("DHCPv6 option code must be 1-255: %s", > + optarg); > + > + dhcpv6_add_option(c, v6optcode, comma + 1); > + break; > case 'd': > c->debug = 1; > c->quiet = 0; > diff --git a/dhcpv6.c b/dhcpv6.c > index 97c04e2..a0fb77c 100644 > --- a/dhcpv6.c > +++ b/dhcpv6.c > @@ -32,6 +32,43 @@ > #include "tap.h" > #include "log.h" > > +/** > + * dhcpv6_add_option() - Add or update a custom DHCPv6 option > + * @c: Execution context > + * @code: DHCPv6 option code > + * @val_str: Value string from command line > + * > + * Stores the option code and raw string value. Binary encoding and > + * injection into DHCPv6 replies are handled by later patches. > + * > + * Return: 0 on success > + */ > +int dhcpv6_add_option(struct ctx *c, uint16_t code, const char *val_str) > +{ > + int idx; > + > + for (idx = 0; idx < c->custom_v6opts_count; idx++) { > + if (c->custom_v6opts[idx].code == code) > + break; > + } > + > + if (idx == c->custom_v6opts_count) { > + if (c->custom_v6opts_count >= MAX_CUSTOM_DHCPV6_OPTS) > + die("Too many --dhcpv6-opt entries (max %d)", > + MAX_CUSTOM_DHCPV6_OPTS); > + c->custom_v6opts_count++; > + } > + > + c->custom_v6opts[idx].code = code; > + > + if (snprintf_check(c->custom_v6opts[idx].str, > + sizeof(c->custom_v6opts[0].str), > + "%s", val_str)) > + die("DHCPv6 option value too long: %s", val_str); > + > + return 0; > +} > + > /** > * struct opt_hdr - DHCPv6 option header > * @t: Option type > diff --git a/dhcpv6.h b/dhcpv6.h > index c706dfd..c01bc36 100644 > --- a/dhcpv6.h > +++ b/dhcpv6.h > @@ -9,5 +9,6 @@ > int dhcpv6(struct ctx *c, struct iov_tail *data, > struct in6_addr *saddr, struct in6_addr *daddr); > void dhcpv6_init(const struct ctx *c); > +int dhcpv6_add_option(struct ctx *c, uint16_t code, const char *val_str); > > #endif /* DHCPV6_H */ > diff --git a/passt.1 b/passt.1 > index 908fd4a..9c25214 100644 > --- a/passt.1 > +++ b/passt.1 > @@ -430,6 +430,12 @@ Send \fIname\fR as DHCP option 12 (hostname). > FQDN to configure the client with. > Send \fIname\fR as Client FQDN: DHCP option 81 and DHCPv6 option 39. > > +.TP > +.BR \-\-dhcpv6-opt " " \fICODE\fR,\fIVALUE\fR > +Set a DHCPv6 option by numeric code. The value format is determined > +automatically from the option code. This option can be specified multiple > +times. If the same option code is given more than once, the last value wins. > + > .TP > .BR \-t ", " \-\-tcp-ports " " \fIspec > Configure TCP port forwarding to guest or namespace. \fIspec\fR can be one of: > diff --git a/passt.h b/passt.h > index 1726965..91509df 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_v6opts: User-specified DHCPv6 options from --dhcpv6-opt > + * @custom_v6opts.code: DHCPv6 option code > + * @custom_v6opts.str: Original string value from command line > + * @custom_v6opts_count:Number of entries in @custom_v6opts > * @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_DHCPV6_OPTS 32 > + > + struct { > + uint16_t code; > + char str[256]; > + } custom_v6opts[MAX_CUSTOM_DHCPV6_OPTS]; > + int custom_v6opts_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