public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Anshu Kumari <anskuma@redhat.com>
Cc: passt-dev@passt.top, lvivier@redhat.com
Subject: Re: [PATCH v4 2/2] dhcpv6: Inject custom options into DHCPv6 replies
Date: Sun, 25 Oct 2026 13:01:37 +0100 (CET)	[thread overview]
Message-ID: <20261025130136.6085c3e0@elisabeth> (raw)
In-Reply-To: <20261006090454.1474409-3-anskuma@redhat.com>

On Tue,  6 Oct 2026 14:34:53 +0530
Anshu Kumari <anskuma@redhat.com> wrote:

> 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 <anskuma@redhat.com>
> ---
> 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@redhat.com/

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


      reply	other threads:[~2026-10-25 12:01 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-06  9:04 [PATCH v4 0/2] [PATCH 0/2] dhcpv6: Add --dhcpv6-opt for custom DHCPv6 options Anshu Kumari
2026-10-06  9:04 ` [PATCH v4 1/2] dhcpv6: Add --dhcpv6-opt with option type table and value parser Anshu Kumari
2026-10-25 12:01   ` Stefano Brivio
2026-10-06  9:04 ` [PATCH v4 2/2] dhcpv6: Inject custom options into DHCPv6 replies Anshu Kumari
2026-10-25 12:01   ` Stefano Brivio [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=20261025130136.6085c3e0@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=anskuma@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /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).