public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: Anshu Kumari <anskuma@redhat.com>,
	sbrivio@redhat.com, passt-dev@passt.top
Cc: david@gibson.dropbear.id.au, jmaloy@redhat.com
Subject: Re: [PATCH v3 2/2] dhcpv6: Inject custom options into DHCPv6 replies
Date: Tue, 25 Aug 2026 16:09:19 +0200	[thread overview]
Message-ID: <6fcca48c-a992-436f-a308-061ae0017d4f@redhat.com> (raw)
In-Reply-To: <20260824121352.244081-3-anskuma@redhat.com>

On 8/24/26 14:13, Anshu Kumari wrote:
> Append user-specified options from --dhcpv6-opt to DHCPv6 reply
> messages.  Options are read from the pre-parsed static storage
> populated by dhcpv6_set_opt() at startup, 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>
> ---
> 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 | 39 +++++++++++++++++++++++++++++++++++++++
>   1 file changed, 39 insertions(+)

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

but see below

> 
> diff --git a/dhcpv6.c b/dhcpv6.c
> index 3964dd9..041b589 100644
> --- a/dhcpv6.c
> +++ b/dhcpv6.c
> @@ -865,6 +865,43 @@ 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: updated offset after appending 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) {
> +			debug("DHCPv6: option %u doesn't fit,"
> +			      " skipping", i);

Perhaps a warn() rather than a debug(), to inform user that something bad happens?

> +			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
> @@ -1003,6 +1040,8 @@ 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;
>   
>   	tap_udp6_send(c, src, 547, saddr, 546, mh->xid, &resp, n);


      reply	other threads:[~2026-08-25 14:09 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 12:13 [PATCH v3 0/2] [PATCH 0/2] dhcpv6: Add --dhcpv6-opt for custom DHCPv6 options Anshu Kumari
2026-08-24 12:13 ` [PATCH v3 1/2] dhcpv6: Add --dhcpv6-opt with option type table and value parser Anshu Kumari
2026-08-25 13:19   ` Laurent Vivier
2026-08-24 12:13 ` [PATCH v3 2/2] dhcpv6: Inject custom options into DHCPv6 replies Anshu Kumari
2026-08-25 14:09   ` Laurent Vivier [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=6fcca48c-a992-436f-a308-061ae0017d4f@redhat.com \
    --to=lvivier@redhat.com \
    --cc=anskuma@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=jmaloy@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).