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=EeFmHVRA; 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 3DCCE5A0262 for ; Thu, 18 Jun 2026 14:06:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1781784364; 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=nXERDkXiYWhBcZCSPMk38WwFeMbd2a7OafzuQibqnvs=; b=EeFmHVRAfHtw6YLTb3V8nVuAXjhA+o6jOA8Z47g6AtTFun8Sw3MVhc59hGfBKOUZt3s6ph PUIfPcnTz+xB+C8QUkOSeNtvFV8rO6AhQBnVnPJ4Dv7zfRJmu8Nx7Nwf/7NeHaaIBqlRMp OHiMGNoYLAh6vPYM9vIYa865hGGH7Ag= 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-440-2OgI59I6OKa55oGaWcsb3Q-1; Thu, 18 Jun 2026 08:06:00 -0400 X-MC-Unique: 2OgI59I6OKa55oGaWcsb3Q-1 X-Mimecast-MFC-AGG-ID: 2OgI59I6OKa55oGaWcsb3Q_1781784359 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (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 838BB1956067; Thu, 18 Jun 2026 12:05:59 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (unknown [10.74.64.160]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C37671800480; Thu, 18 Jun 2026 12:05:54 +0000 (UTC) From: Anshu Kumari To: sbrivio@redhat.com, anskuma@redhat.com, passt-dev@passt.top Subject: [PATCH v2 2/2] dhcpv6: Inject custom options into DHCPv6 replies Date: Thu, 18 Jun 2026 17:35:29 +0530 Message-ID: <20260618120529.1768765-3-anskuma@redhat.com> In-Reply-To: <20260618120529.1768765-1-anskuma@redhat.com> References: <20260618120529.1768765-1-anskuma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: N1JhNjpkqY3csyltDlJMmK215TBZV9YWsJhqBEuN0DU_1781784359 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: EE5AZFISBAF3GJN4OY27RVROFN5LJHJN X-Message-ID-Hash: EE5AZFISBAF3GJN4OY27RVROFN5LJHJN 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, lvivier@redhat.com, jmaloy@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 parsed from the stored string value at reply time using dhcpv6_opt_parse(), 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 --- v2: - Updated dhcpv6_custom_opts_fill() to parse str at reply time using dhcpv6_opt_parse() instead of copying cached val/len. --- dhcpv6.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/dhcpv6.c b/dhcpv6.c index 1e1dd0d..6b1e90b 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -748,6 +748,49 @@ 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->dhcpv6_opts_count; i++) { + uint16_t code = c->dhcpv6_opts[i].code; + struct opt_hdr *hdr; + uint8_t val[255]; + int vlen; + + vlen = dhcpv6_opt_parse(code, c->dhcpv6_opts[i].str, + val, sizeof(val)); + if (vlen < 0) + continue; + + if ((size_t)offset + sizeof(struct opt_hdr) + vlen > + OPT_MAX_SIZE) { + debug("DHCPv6: custom option %u doesn't fit," + " skipping", code); + continue; + } + + hdr = (struct opt_hdr *)(buf + offset); + hdr->t = htons(code); + hdr->l = htons(vlen); + offset += sizeof(struct opt_hdr); + + memcpy(buf + offset, val, vlen); + offset += vlen; + } + + return offset; +} + /** * dhcpv6() - Check if this is a DHCPv6 message, reply as needed * @c: Execution context @@ -886,6 +929,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