public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Anshu Kumari <anskuma@redhat.com>
To: passt-dev@passt.top, sbrivio@redhat.com, anskuma@redhat.com
Cc: david@gibson.dropbear.id.au, jmaloy@redhat.com, lvivier@redhat.com
Subject: [PATCH 3/3] dhcpv6: Inject custom options into DHCPv6 replies
Date: Thu,  4 Jun 2026 16:21:50 +0530	[thread overview]
Message-ID: <20260604105150.1977905-4-anskuma@redhat.com> (raw)
In-Reply-To: <20260604105150.1977905-1-anskuma@redhat.com>

Add dhcpv6_custom_opts_fill() which appends user-specified custom
options to DHCPv6 response packets, and call it from the main dhcpv6()
handler after the built-in DNS and FQDN options.

Each custom option is written with its DHCPv6 option header (code +
length) followed by the binary-encoded value from dhcpv6_opt_parse().
Options that would exceed the IPv6 minimum MTU are skipped with a
debug message.

Signed-off-by: Anshu Kumari <anskuma@redhat.com>
---
 dhcpv6.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/dhcpv6.c b/dhcpv6.c
index 85e2926..590c40d 100644
--- a/dhcpv6.c
+++ b/dhcpv6.c
@@ -798,6 +798,41 @@ 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
+ * @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->custom_v6opts_count; i++) {
+		struct opt_hdr *hdr;
+		uint16_t len = c->custom_v6opts[i].len;
+
+		if ((size_t)offset + sizeof(struct opt_hdr) + len > OPT_MAX_SIZE) {
+			debug("DHCPv6: custom option %u doesn't fit, skipping",
+			      c->custom_v6opts[i].code);
+			continue;
+		}
+
+		hdr = (struct opt_hdr *)(buf + offset);
+		hdr->t = htons(c->custom_v6opts[i].code);
+		hdr->l = htons(len);
+		offset += sizeof(struct opt_hdr);
+
+		memcpy(buf + offset, c->custom_v6opts[i].val, len);
+		offset += len;
+	}
+
+	return offset;
+}
+
 /**
  * dhcpv6() - Check if this is a DHCPv6 message, reply as needed
  * @c:		Execution context
@@ -936,6 +971,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


  parent reply	other threads:[~2026-06-04 10:52 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-04 10:51 [PATCH 0/3] [PATCH 0/3] dhcpv6: Add --dhcpv6-opt for custom DHCPv6 options Anshu Kumari
2026-06-04 10:51 ` [PATCH 1/3] conf: Add --dhcpv6-opt command-line option Anshu Kumari
2026-06-04 10:51 ` [PATCH 2/3] dhcpv6: Add option type table and value parser Anshu Kumari
2026-06-04 10:51 ` Anshu Kumari [this message]
2026-06-04 11:00 ` [PATCH 0/3] [PATCH 0/3] dhcpv6: Add --dhcpv6-opt for custom DHCPv6 options Anshu Kumari

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=20260604105150.1977905-4-anskuma@redhat.com \
    --to=anskuma@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --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).