From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=fail (p=quarantine dis=none) header.from=redhat.com Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by passt.top (Postfix) with ESMTPS id 0F32F5A0625 for ; Thu, 29 Oct 2026 19:13:17 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1793297596; 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=qHAj4AcflKeTSBKthOIu6jJmDW+TPk1Ids4CpLIRedY=; b=ZrNBrQWpklA6bj716sxAzZjYJqqvkOidl80qz+c4Dq9S62Ghv70KXGFtLnPvhuh0ged2Lz voOtl/zq0I54CJppZfTQYrW5e2JiABRkWolkkTxWNOmOU4WvENCL+7jnROdP9YznDKt3tX XlEr2NFcw3lIu2EmpeR6AWHC2kOwhmk= 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-359-7UXYknlVOU2KCtZRair38w-1; Thu, 29 Oct 2026 14:13:15 -0400 X-MC-Unique: 7UXYknlVOU2KCtZRair38w-1 X-Mimecast-MFC-AGG-ID: 7UXYknlVOU2KCtZRair38w_1793297594 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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 40753180065F for ; Thu, 29 Oct 2026 18:13:14 +0000 (UTC) Received: from anskuma-thinkpadp1gen7.bengluru.csb (unknown [10.74.80.10]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C75E118005B7; Thu, 29 Oct 2026 18:13:11 +0000 (UTC) From: Anshu Kumari To: sbrivio@redhat.com, passt-dev@passt.top Subject: [PATCH v5 2/2] dhcpv6: Inject custom options into DHCPv6 replies Date: Thu, 29 Oct 2026 23:43:02 +0530 Message-ID: <20261029181303.714616-3-anskuma@redhat.com> In-Reply-To: <20261029181303.714616-1-anskuma@redhat.com> References: <20261029181303.714616-1-anskuma@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: FW-TUIVeOUbGgVDkR6KhMXgNXxZGZYuXUCRvjCl6_LM_1793297594 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 3A4OIU5OJHW2UM7W5MKIHWWMYVBJLBPE X-Message-ID-Hash: 3A4OIU5OJHW2UM7W5MKIHWWMYVBJLBPE 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 rate-limited warning. Link: https://bugs.passt.top/show_bug.cgi?id=192 Signed-off-by: Anshu Kumari --- v5: - Replaced warn() with warn_ratelimit(now, ...) 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 | 44 +++++++++++++++++++++++++++++++++++++++++++- dhcpv6.h | 3 ++- tap.c | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/dhcpv6.c b/dhcpv6.c index a98f1a9c..9bafa99e 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -891,17 +891,58 @@ 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 + * @now: Current timestamp + * + * Return: offset after appended user options + */ +static size_t dhcpv6_user_opts_fill(char *buf, size_t offset, + const struct timespec *now) +{ + 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_ratelimit(now, + "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 * @data: Single packet starting from UDP header * @saddr: Source IPv6 address of original message * @daddr: Destination IPv6 address of original message + * @now: Current timestamp * * Return: 0 if it's not a DHCPv6 message, 1 if handled, -1 on failure */ int dhcpv6(struct ctx *c, struct iov_tail *data, - const struct in6_addr *saddr, const struct in6_addr *daddr) + const struct in6_addr *saddr, const struct in6_addr *daddr, + const struct timespec *now) { const struct opt_server_id *server_id = NULL; const struct opt_hdr *client_id = NULL; @@ -1029,6 +1070,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, now); resp.hdr.xid = mh->xid; diff --git a/dhcpv6.h b/dhcpv6.h index 6cefd15b..00cf51af 100644 --- a/dhcpv6.h +++ b/dhcpv6.h @@ -7,7 +7,8 @@ #define DHCPV6_H int dhcpv6(struct ctx *c, struct iov_tail *data, - const struct in6_addr *saddr, const struct in6_addr *daddr); + const struct in6_addr *saddr, const struct in6_addr *daddr, + const struct timespec *now); void dhcpv6_init(const struct ctx *c); void dhcpv6_set_opt(uint16_t code, const char *val_str); const char *dhcpv6_opt_to_str(uint16_t code, char *buf, size_t buf_len, diff --git a/tap.c b/tap.c index dfa66c71..0a9938de 100644 --- a/tap.c +++ b/tap.c @@ -1041,7 +1041,7 @@ resume: if (proto == IPPROTO_UDP) { struct iov_tail uh_data = data; - if (dhcpv6(c, &uh_data, saddr, daddr)) + if (dhcpv6(c, &uh_data, saddr, daddr, now)) continue; } -- 2.55.0