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=eKtqCGWc; 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 2F0C45A0275 for ; Mon, 24 Aug 2026 14:14:14 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1787573653; 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=O2M3Ma2IbdwUauAuJ86m2YEapFBY4tsIJh55QazQxhs=; b=eKtqCGWcMt3F8ZYdlD9OiOuY741obPtNamwxlVfT5I9Ze+IVOEMgnX6akVNvakgoF2fxsY 5qQ4gCsbMk4uAbaNGMDbXbjjJ4Pcqm71wBTeGREULot2z+2O/ehKAB0/b8ZTEELHABns+1 FASxb4n3CI/zqLJwIaTMU5qe58d8spw= Received: from mx-prod-mc-06.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-498-RcOUfvK1MbSR8RVzVrsglQ-1; Mon, 24 Aug 2026 08:14:10 -0400 X-MC-Unique: RcOUfvK1MbSR8RVzVrsglQ-1 X-Mimecast-MFC-AGG-ID: RcOUfvK1MbSR8RVzVrsglQ_1787573650 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 69C1C185FCE8; Mon, 24 Aug 2026 12:14:09 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (unknown [10.74.80.6]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 36F2730002EA; Mon, 24 Aug 2026 12:14:04 +0000 (UTC) From: Anshu Kumari To: sbrivio@redhat.com, passt-dev@passt.top, anskuma@redhat.com Subject: [PATCH v3 2/2] dhcpv6: Inject custom options into DHCPv6 replies Date: Mon, 24 Aug 2026 17:43:52 +0530 Message-ID: <20260824121352.244081-3-anskuma@redhat.com> In-Reply-To: <20260824121352.244081-1-anskuma@redhat.com> References: <20260824121352.244081-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: YYZcxiJPJDWyZnUJZaFWC5WIYw42Yx2gs0CSCFtKLLM_1787573650 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: XYS53T5IZHLA6BBECOWL6UE3IPYD3LID X-Message-ID-Hash: XYS53T5IZHLA6BBECOWL6UE3IPYD3LID 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: 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 --- 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(+) 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); + 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); -- 2.55.0