From: David Gibson <david@gibson.dropbear.id.au>
To: Anshu Kumari <anskuma@redhat.com>
Cc: sbrivio@redhat.com, passt-dev@passt.top, lvivier@redhat.com,
jmaloy@redhat.com
Subject: Re: [PATCH v2 2/2] dhcpv6: Inject custom options into DHCPv6 replies
Date: Fri, 19 Jun 2026 14:03:10 +1000 [thread overview]
Message-ID: <ajS_fiydRpXWZWnI@zatzit> (raw)
In-Reply-To: <20260618120529.1768765-3-anskuma@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 3094 bytes --]
On Thu, Jun 18, 2026 at 05:35:29PM +0530, Anshu Kumari wrote:
> Append user-specified options from --dhcpv6-opt to DHCPv6 reply
> messages. Options are parsed from the stored string value at reply
> time using dhcpv6_opt_parse(), and skipped with a debug message if
> they exceed the available space.
>
> Link: https://bugs.passt.top/show_bug.cgi?id=192
> Signed-off-by: Anshu Kumari <anskuma@redhat.com>
> ---
> v2:
> - Updated dhcpv6_custom_opts_fill() to parse str at reply time
> using dhcpv6_opt_parse() instead of copying cached val/len.
As with DHCPv4, it's not that I'm against storing the parsed values
persistently, just that I'm against storing them twice. The existing
data structures for DHCPv6 are different, so maybe there's not an
obvious place to store pre-parsed options.
> ---
> dhcpv6.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 44 insertions(+)
>
> diff --git a/dhcpv6.c b/dhcpv6.c
> index 1e1dd0d..6b1e90b 100644
> --- a/dhcpv6.c
> +++ b/dhcpv6.c
> @@ -748,6 +748,49 @@ static size_t dhcpv6_client_fqdn_fill(const struct iov_tail *data,
> return offset + sizeof(struct opt_hdr) + opt_len;
> }
>
> +/**
> + * dhcpv6_custom_opts_fill() - Append user-specified custom options to reply
As discussed elsewhere "custom" isn't a great name. "user" might be
better, or just drop it.
> + * @c: Execution context
> + * @buf: Response message buffer
> + * @offset: Current offset in buffer
> + *
> + * Return: updated offset after appending custom options
> + */
> +static size_t dhcpv6_custom_opts_fill(const struct ctx *c,
> + char *buf, int offset)
> +{
> + int i;
> +
> + for (i = 0; i < c->dhcpv6_opts_count; i++) {
> + uint16_t code = c->dhcpv6_opts[i].code;
> + struct opt_hdr *hdr;
> + uint8_t val[255];
> + int vlen;
> +
> + vlen = dhcpv6_opt_parse(code, c->dhcpv6_opts[i].str,
> + val, sizeof(val));
> + if (vlen < 0)
> + continue;
> +
> + if ((size_t)offset + sizeof(struct opt_hdr) + vlen >
> + OPT_MAX_SIZE) {
> + debug("DHCPv6: custom option %u doesn't fit,"
> + " skipping", code);
> + continue;
> + }
> +
> + hdr = (struct opt_hdr *)(buf + offset);
> + hdr->t = htons(code);
> + hdr->l = htons(vlen);
> + offset += sizeof(struct opt_hdr);
> +
> + memcpy(buf + offset, val, vlen);
> + offset += vlen;
> + }
> +
> + return offset;
> +}
> +
> /**
> * dhcpv6() - Check if this is a DHCPv6 message, reply as needed
> * @c: Execution context
> @@ -886,6 +929,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_custom_opts_fill(c, (char *)&resp, n);
>
> resp.hdr.xid = mh->xid;
>
> --
> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2026-06-19 4:03 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-18 12:05 [PATCH v2 0/2] dhcpv6: Add --dhcpv6-opt for custom DHCPv6 options Anshu Kumari
2026-06-18 12:05 ` [PATCH v2 1/2] dhcpv6: Add --dhcpv6-opt with option type table and value parser Anshu Kumari
2026-06-19 4:00 ` David Gibson
2026-06-18 12:05 ` [PATCH v2 2/2] dhcpv6: Inject custom options into DHCPv6 replies Anshu Kumari
2026-06-19 4:03 ` David Gibson [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ajS_fiydRpXWZWnI@zatzit \
--to=david@gibson.dropbear.id.au \
--cc=anskuma@redhat.com \
--cc=jmaloy@redhat.com \
--cc=lvivier@redhat.com \
--cc=passt-dev@passt.top \
--cc=sbrivio@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).