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=YqE9OyNy; dkim-atps=neutral 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 036495A026E for ; Thu, 04 Jun 2026 12:52:04 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1780570323; 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=j7xqYWRvhDItk9J73oXyyf4Bll+yL+dWEEzDUTRMfbg=; b=YqE9OyNyX/1rghyklcVnCjyhLPv5DGhiqv40pK/gaWP7grxTJ4ndJGopWcg1x31HWit9LH 0cl3EAS25RMlZ8+MpiWhtQiiUvz+ZlJOTZckwYvIeldp7t6oB/xwA2rCst9RyK5ITZZ+n3 CSn4128lMy02tqQLL7Th5xwhmJQgDe4= 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-281-AX_zuNhTPmOG_JtWeGUyEA-1; Thu, 04 Jun 2026 06:52:02 -0400 X-MC-Unique: AX_zuNhTPmOG_JtWeGUyEA-1 X-Mimecast-MFC-AGG-ID: AX_zuNhTPmOG_JtWeGUyEA_1780570321 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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 1D2E5180034E; Thu, 4 Jun 2026 10:52:01 +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 6C926414; Thu, 4 Jun 2026 10:51:58 +0000 (UTC) From: Anshu Kumari To: passt-dev@passt.top, sbrivio@redhat.com, anskuma@redhat.com Subject: [PATCH 1/3] conf: Add --dhcpv6-opt command-line option Date: Thu, 4 Jun 2026 16:21:48 +0530 Message-ID: <20260604105150.1977905-2-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: 9wUoxQG7KLHEJ5W4jzBSehsLVMMQ9515-0vqDvSFlPQ_1780570321 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit content-type: text/plain; charset="US-ASCII"; x-default=true Message-ID-Hash: 63IWH4XT4YSZLYQXQA5TSELPAXDQLP3J X-Message-ID-Hash: 63IWH4XT4YSZLYQXQA5TSELPAXDQLP3J 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 a --dhcpv6-opt CODE,VALUE option for injecting custom DHCPv6 options into server replies. This patch adds the CLI parsing in conf.c, storage in struct ctx, and a simple dhcpv6_add_option() that stores the option code and raw string value. Signed-off-by: Anshu Kumari --- conf.c | 26 +++++++++++++++++++++++++- dhcpv6.c | 37 +++++++++++++++++++++++++++++++++++++ dhcpv6.h | 1 + passt.1 | 6 ++++++ passt.h | 12 ++++++++++++ 5 files changed, 81 insertions(+), 1 deletion(-) diff --git a/conf.c b/conf.c index 6f86940..ac7e6e5 100644 --- a/conf.c +++ b/conf.c @@ -47,6 +47,7 @@ #include "lineread.h" #include "isolation.h" #include "log.h" +#include "dhcpv6.h" #include "vhost_user.h" #include "epoll_ctl.h" #include "conf.h" @@ -616,7 +617,8 @@ static void usage(const char *name, FILE *f, int status) " -S, --search LIST Space-separated list, search domains\n" " a single, empty option disables the DNS search list\n" " -H, --hostname NAME Hostname to configure client with\n" - " --fqdn NAME FQDN to configure client with\n"); + " --fqdn NAME FQDN to configure client with\n" + " --dhcpv6-opt CODE,VAL Set DHCPv6 option by code\n"); if (strstr(name, "pasta")) FPRINTF(f, " default: don't use any search list\n"); else @@ -884,6 +886,10 @@ static void conf_print(const struct ctx *c) info(" our link-local: %s", inet_ntop(AF_INET6, &c->ip6.our_tap_ll, buf, sizeof(buf))); + for (i = 0; i < c->custom_v6opts_count; i++) + info(" v6 option %u: %s", + c->custom_v6opts[i].code, + c->custom_v6opts[i].str); dns6: for (i = 0; i < ARRAY_SIZE(c->ip6.dns); i++) { @@ -1233,6 +1239,7 @@ void conf(struct ctx *c, int argc, char **argv) {"migrate-no-linger", no_argument, NULL, 30 }, {"stats", required_argument, NULL, 31 }, {"conf-path", required_argument, NULL, 'c' }, + {"dhcpv6-opt", required_argument, NULL, 34 }, { 0 }, }; const char *optstring = "+dqfel:hs:c:F:I:p:P:m:a:n:M:g:i:o:D:S:H:461t:u:T:U:"; @@ -1248,10 +1255,13 @@ void conf(struct ctx *c, int argc, char **argv) uint8_t prefix_len_from_opt = 0; unsigned int ifi4 = 0, ifi6 = 0; const char *logfile = NULL; + unsigned long v6optcode; char *runas = NULL; size_t logsize = 0; + const char *comma; long fd_tap_opt; int name, ret; + char *end; uid_t uid; gid_t gid; @@ -1465,6 +1475,20 @@ void conf(struct ctx *c, int argc, char **argv) die("Can't display statistics if not running in foreground"); c->stats = strtol(optarg, NULL, 0); break; + case 34: + comma = strchr(optarg, ','); + if (!comma) + die("--dhcpv6-opt requires CODE,VALUE format"); + + errno = 0; + v6optcode = strtoul(optarg, &end, 0); + if (end != comma || errno || + v6optcode < 1 || v6optcode > 255) + die("DHCPv6 option code must be 1-255: %s", + optarg); + + dhcpv6_add_option(c, v6optcode, comma + 1); + break; case 'd': c->debug = 1; c->quiet = 0; diff --git a/dhcpv6.c b/dhcpv6.c index 97c04e2..a0fb77c 100644 --- a/dhcpv6.c +++ b/dhcpv6.c @@ -32,6 +32,43 @@ #include "tap.h" #include "log.h" +/** + * dhcpv6_add_option() - Add or update a custom DHCPv6 option + * @c: Execution context + * @code: DHCPv6 option code + * @val_str: Value string from command line + * + * Stores the option code and raw string value. Binary encoding and + * injection into DHCPv6 replies are handled by later patches. + * + * Return: 0 on success + */ +int dhcpv6_add_option(struct ctx *c, uint16_t code, const char *val_str) +{ + int idx; + + for (idx = 0; idx < c->custom_v6opts_count; idx++) { + if (c->custom_v6opts[idx].code == code) + break; + } + + if (idx == c->custom_v6opts_count) { + if (c->custom_v6opts_count >= MAX_CUSTOM_DHCPV6_OPTS) + die("Too many --dhcpv6-opt entries (max %d)", + MAX_CUSTOM_DHCPV6_OPTS); + c->custom_v6opts_count++; + } + + c->custom_v6opts[idx].code = code; + + if (snprintf_check(c->custom_v6opts[idx].str, + sizeof(c->custom_v6opts[0].str), + "%s", val_str)) + die("DHCPv6 option value too long: %s", val_str); + + return 0; +} + /** * struct opt_hdr - DHCPv6 option header * @t: Option type diff --git a/dhcpv6.h b/dhcpv6.h index c706dfd..c01bc36 100644 --- a/dhcpv6.h +++ b/dhcpv6.h @@ -9,5 +9,6 @@ int dhcpv6(struct ctx *c, struct iov_tail *data, struct in6_addr *saddr, struct in6_addr *daddr); void dhcpv6_init(const struct ctx *c); +int dhcpv6_add_option(struct ctx *c, uint16_t code, const char *val_str); #endif /* DHCPV6_H */ diff --git a/passt.1 b/passt.1 index 908fd4a..9c25214 100644 --- a/passt.1 +++ b/passt.1 @@ -430,6 +430,12 @@ Send \fIname\fR as DHCP option 12 (hostname). FQDN to configure the client with. Send \fIname\fR as Client FQDN: DHCP option 81 and DHCPv6 option 39. +.TP +.BR \-\-dhcpv6-opt " " \fICODE\fR,\fIVALUE\fR +Set a DHCPv6 option by numeric code. The value format is determined +automatically from the option code. This option can be specified multiple +times. If the same option code is given more than once, the last value wins. + .TP .BR \-t ", " \-\-tcp-ports " " \fIspec Configure TCP port forwarding to guest or namespace. \fIspec\fR can be one of: diff --git a/passt.h b/passt.h index 1726965..91509df 100644 --- a/passt.h +++ b/passt.h @@ -182,6 +182,10 @@ struct ip6_ctx { * @dns_search: DNS search list * @hostname: Guest hostname * @fqdn: Guest FQDN + * @custom_v6opts: User-specified DHCPv6 options from --dhcpv6-opt + * @custom_v6opts.code: DHCPv6 option code + * @custom_v6opts.str: Original string value from command line + * @custom_v6opts_count:Number of entries in @custom_v6opts * @ifi6: Template interface for IPv6, -1: none, 0: IPv6 disabled * @ip6: IPv6 configuration * @pasta_ifn: Name of namespace interface for pasta @@ -263,6 +267,14 @@ struct ctx { char hostname[PASST_MAXDNAME]; char fqdn[PASST_MAXDNAME]; +#define MAX_CUSTOM_DHCPV6_OPTS 32 + + struct { + uint16_t code; + char str[256]; + } custom_v6opts[MAX_CUSTOM_DHCPV6_OPTS]; + int custom_v6opts_count; + int ifi6; struct ip6_ctx ip6; -- 2.54.0