On Tue, 6 Oct 2026 14:34:53 +0530
Anshu Kumari
Append user-specified options from --dhcpv6-opt to DHCPv6 reply messages. Options that exceed available buffer space are skipped with a warning.
Link: https://bugs.passt.top/show_bug.cgi?id=192 Signed-off-by: Anshu Kumari
--- v4: - warn() instead of debug() when options don't fit in the reply. - doc comment for dhcpv6_user_opts_fill() updated. v3: - rename dhcpv6_custom_opts_fill() to dhcpv6_user_opts_fill(). - Iterate directly over the pre-parsed binary dhcpv6_user_opts[] array instead of re-parsing string values at reply time.
v2: - Updated dhcpv6_custom_opts_fill() to parse str at reply time using dhcpv6_opt_parse() instead of copying cached val/len. --- dhcpv6.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+)
diff --git a/dhcpv6.c b/dhcpv6.c index abc45813..a0545406 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -879,6 +879,41 @@ static size_t dhcpv6_client_fqdn_fill(const struct iov_tail *data, return offset + sizeof(struct opt_hdr) + opt_len; }
+/** + * dhcpv6_user_opts_fill() - Append user-specified options to reply + * @buf: Response message buffer + * @offset: Current offset in buffer + * + * Return: offset after appended user options + */ +static size_t dhcpv6_user_opts_fill(char *buf, size_t offset) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(dhcpv6_user_opts); i++) { + int vlen = dhcpv6_user_opts[i].len; + struct opt_hdr *hdr; + + if (!vlen) + continue; + + if (offset + sizeof(struct opt_hdr) + vlen > OPT_MAX_SIZE) { + warn("DHCPv6: option %u doesn't fit, skipping", i);
I've seen Laurent's comment in: https://archives.passt.top/passt-dev/6fcca48c-a992-436f-a308-061ae0017d4f@re... but the issue with a warn() call here is that the guest could try to flood logs that way. You could rate-limit it by passing the timestamp to here via dhcpv6(), it's just one caller to modify, it doesn't look that bad.
+ continue; + } + + hdr = (struct opt_hdr *)(buf + offset); + hdr->t = htons(i); + hdr->l = htons(vlen); + offset += sizeof(struct opt_hdr); + + memcpy(buf + offset, dhcpv6_user_opts[i].val, vlen); + offset += vlen; + } + + return offset; +} + /** * dhcpv6() - Check if this is a DHCPv6 message, reply as needed * @c: Execution context @@ -1017,6 +1052,7 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, sizeof(struct opt_hdr) + ntohs(client_id->l); n = dhcpv6_dns_fill(c, (char *)&resp, n); n = dhcpv6_client_fqdn_fill(data, c, (char *)&resp, n); + n = dhcpv6_user_opts_fill((char *)&resp, n);
resp.hdr.xid = mh->xid;
-- Stefano