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=Lk7QzviK; 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 ABDD05A0275 for ; Tue, 06 Oct 2026 11:05:07 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1791277506; 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=cwAc4h8yEiiJH2CT2yqeG/5NmmVuUVSqq5HpoC5m0XE=; b=Lk7QzviK6mixU9Gx4Vbk7ihdP7khfYNLNpKraAr9eU3lBMAxkGIuqZLx+4fuQ0h4mzB4qa D+14BwLl8A8U0LGNxtDc63UbOBv6HMxj0ai5lAC7kuRUv2TQn/T961isfopjaxmOoF03fu tOHepsY7Q/8Ed+J1f72XnVsNsScL1Ac= Received: from mx-prod-mc-03.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-274-ZeFnY_AlPvu-Umh3vqaG3Q-1; Tue, 06 Oct 2026 05:05:05 -0400 X-MC-Unique: ZeFnY_AlPvu-Umh3vqaG3Q-1 X-Mimecast-MFC-AGG-ID: ZeFnY_AlPvu-Umh3vqaG3Q_1791277504 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (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-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4100D19540C8 for ; Tue, 6 Oct 2026 09:05:04 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (unknown [10.74.80.177]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 41E4D30000E3; Tue, 6 Oct 2026 09:05:01 +0000 (UTC) From: Anshu Kumari To: sbrivio@redhat.com, passt-dev@passt.top Subject: [PATCH v4 2/2] dhcpv6: Inject custom options into DHCPv6 replies Date: Tue, 6 Oct 2026 14:34:53 +0530 Message-ID: <20261006090454.1474409-3-anskuma@redhat.com> In-Reply-To: <20261006090454.1474409-1-anskuma@redhat.com> References: <20261006090454.1474409-1-anskuma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: t7xfZAz7_W3C9s2fM7g5jOyKPs4-sfxGQutrf-LmRMI_1791277504 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: U4RXZRPEUNT5CZASWB2CH7YSMUBX4OAV X-Message-ID-Hash: U4RXZRPEUNT5CZASWB2CH7YSMUBX4OAV 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: lvivier@redhat.com, anskuma@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: 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 --- 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); + 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; -- 2.55.0