From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202602 header.b=S6RtYkFu; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id A38D15A0262 for ; Fri, 05 Jun 2026 03:08:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780621736; bh=+7vsp6NgVYuPp9JnrgDAR3iJuZuIUmsFMFE/aEarZ10=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=S6RtYkFuoqb2cV3aP9+Q0OAAb5SC77u2EzgbZCMQeXVZsXSMXg5iUM6AoNynJB00t 6dqjUmpjfxTgcuauvLw77iSeJoi4IzLfZ12QrCeB6lJgHp5LorTKVCBQPeVKpC9FZ1 LLER1D7XBoE8ZQrOFGraEaBj/oZcji5RodIqazyYtQ59tDcQd3WP3wsAMEDy7/PJPR lTb+ucKzyBZ+Qkay80j/nYamiNyH5jnU5XaCAzTA/lwMoQhOuiCj/0aSccWVgo2PJX BnddnxwbBrd98vPeF0GC2uMWn6ldGPGPA+H/6M4aEX8hmg1bH8GB5/ELzMJasup5ZO e+Cz7wTp+5edg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gWjxh4pdqz58lg; Fri, 05 Jun 2026 11:08:56 +1000 (AEST) Date: Fri, 5 Jun 2026 10:50:30 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH 1/3] conf: Add --dhcpv6-opt command-line option Message-ID: References: <20260604105150.1977905-1-anskuma@redhat.com> <20260604105150.1977905-2-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="H8qRP7eh20+DO51O" Content-Disposition: inline In-Reply-To: <20260604105150.1977905-2-anskuma@redhat.com> Message-ID-Hash: PU2BRANFJ7CJPM3LJZG4AJPYZT2JGP4Q X-Message-ID-Hash: PU2BRANFJ7CJPM3LJZG4AJPYZT2JGP4Q X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: passt-dev@passt.top, sbrivio@redhat.com, jmaloy@redhat.com, lvivier@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: --H8qRP7eh20+DO51O Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable 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. >=20 > 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(-) >=20 > 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 stat= us) > " -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 =3D 0; i < c->custom_v6opts_count; i++) > + info(" v6 option %u: %s", > + c->custom_v6opts[i].code, > + c->custom_v6opts[i].str); > =20 > dns6: > for (i =3D 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 =3D "+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 =3D 0; > unsigned int ifi4 =3D 0, ifi6 =3D 0; > const char *logfile =3D NULL; > + unsigned long v6optcode; > char *runas =3D NULL; > size_t logsize =3D 0; > + const char *comma; > long fd_tap_opt; > int name, ret; > + char *end; > uid_t uid; > gid_t gid; > =09 > @@ -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 =3D strtol(optarg, NULL, 0); > break; > + case 34: > + comma =3D strchr(optarg, ','); > + if (!comma) > + die("--dhcpv6-opt requires CODE,VALUE format"); > + > + errno =3D 0; > + v6optcode =3D strtoul(optarg, &end, 0); > + if (end !=3D 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 =3D 1; > c->quiet =3D 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" > =20 > +/** > + * 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 =3D 0; idx < c->custom_v6opts_count; idx++) { > + if (c->custom_v6opts[idx].code =3D=3D code) > + break; > + } > + > + if (idx =3D=3D c->custom_v6opts_count) { > + if (c->custom_v6opts_count >=3D 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 =3D 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); > =20 > #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. > =20 > +.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 w= ins. > + > .TP > .BR \-t ", " \-\-tcp-ports " " \fIspec > Configure TCP port forwarding to guest or namespace. \fIspec\fR can be o= ne 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]; > =20 > +#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; > =20 > --=20 > 2.54.0 >=20 --=20 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 --H8qRP7eh20+DO51O Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoiHVEACgkQzQJF27ox 2GcSpA//af2M2eXcHVg8R/y5SX5kVwo/01sisOZY/uuW/emSG6XBT1gJ20Nfe18o HvXi84H478cT75YHuqN2MjTTsMsDvyGKJC6mhVKHFExKMqalFUNXrFPrBbREy/az ily+Oe/dX9Rnam56VDTxK1QNHduOsvCUyRshZjB9RBRbb7jYkbXExMXpT9/gasIo 0pjzPdBccOVQUSRh58+BtwSyFRlzoqf2dQ3KSb251J8JE4VcfP4s6u8yGJFosqE7 AH9QXNYOs36Y9jJqOpo30MUTUQneSdGvAyijSTQSj8SxBmyAOXRa/4lh5/mvtxwi Quanyz0bLtK94DQFnQ+Uvkxz22Ug622XKpj/FBDQoT3bqG5ioGQhO7nxVggQ/yZx qjEVkVLgmlojULXqT4PxXXjf1NkRhrKAUp61cxU94nVqyZx799i8GAxyMY++ylmA AfPEB3sqBTCjFK+DsD1PBQFSIvVBhuawUv34LuFCUjPw/8hxhP2h71JpH0Ocj1ZA s05AL5pJ/xOnZQLAryc1UXcJTxUDzwa35osmegl67hF2HaN/QVIDZInIJ+wL6ZH/ v4/O3vQpvyVLO5VKT0Wouq5gnfOwyhcD9ySUU+eJ2yPYOECzocCWl9FBWhSaPrzl WdNyrx5yuPMN8o080U7mkfRVXbXAG5OuTLdZUnfkwf1igvzBTsw= =zgCh -----END PGP SIGNATURE----- --H8qRP7eh20+DO51O--