From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: passt.top; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=Ua6EdNCt; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by passt.top (Postfix) with ESMTPS id 550BF5A0262 for ; Thu, 04 Jun 2026 12:52:17 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780570335; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f3PAOMGW7SOtyDm4H5d1TNV5/LktZV+mJQBugsiGe1E=; b=Ua6EdNCtkKkTEQTnADBEWt4qFZGSBHvcbwFuXyFNV5cp0U6griSbVGdk/BOHVrA0irSFm4 bVpIeZbU01fma39p6oVappU/YCEFKD8m+SCPLADd2+QV+oYQjrHcoY6DFHyzv5fryVanhI hPl+RGTSMnFtJOuOIMwJfSXUS0xibQI= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-288-yceg1V2BPBCEHap5T1Uf3w-1; Thu, 04 Jun 2026 06:52:10 -0400 X-MC-Unique: yceg1V2BPBCEHap5T1Uf3w-1 X-Mimecast-MFC-AGG-ID: yceg1V2BPBCEHap5T1Uf3w_1780570329 Received: from mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.95]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 6112C18004D4; Thu, 4 Jun 2026 10:52:08 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (polycom_64167f9778de.blr.redhat.com [10.76.98.106]) by mx-prod-int-10.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 82F2D27A; Thu, 4 Jun 2026 10:52:05 +0000 (UTC) From: Anshu Kumari To: passt-dev@passt.top, sbrivio@redhat.com, anskuma@redhat.com Subject: [PATCH 3/3] dhcpv6: Inject custom options into DHCPv6 replies Date: Thu, 4 Jun 2026 16:21:50 +0530 Message-ID: <20260604105150.1977905-4-anskuma@redhat.com> In-Reply-To: <20260604105150.1977905-1-anskuma@redhat.com> References: <20260604105150.1977905-1-anskuma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.6 on 10.30.177.95 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: JcAYoMFL0GqWvfhKecYTuM5JMp46DnfyBpdp-tmY-NU_1780570329 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: WOVRBFK7I4HWJ2ZSX5W2JEPEFYCZPMJD X-Message-ID-Hash: WOVRBFK7I4HWJ2ZSX5W2JEPEFYCZPMJD X-MailFrom: anskuma@redhat.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: david@gibson.dropbear.id.au, jmaloy@redhat.com, lvivier@redhat.com X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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