public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Stefano Brivio <sbrivio@redhat.com>
To: Anshu Kumari <anskuma@redhat.com>
Cc: passt-dev@passt.top, lvivier@redhat.com, jmaloy@redhat.com,
	david@gibson.dropbear.id.au
Subject: Re: [PATCH 1/6] conf: Add --dhcp-opt command-line option
Date: Wed, 20 May 2026 02:38:14 +0200 (CEST)	[thread overview]
Message-ID: <20260520023813.1bb36a9a@elisabeth> (raw)
In-Reply-To: <20260518132002.418296-2-anskuma@redhat.com>

On Mon, 18 May 2026 18:49:57 +0530
Anshu Kumari <anskuma@redhat.com> wrote:

> Introduce the --dhcp-opt flag that allows setting arbitrary DHCP
> options from command-line in the form of [Option CODE,VALUE].
> This patch adds the option storage in struct ctx and CLI parsing;
> the type-aware value parser and DHCP reply injection follow
> in subsequent patches.
> 
> Link: https://bugs.passt.top/show_bug.cgi?id=192
> Signed-off-by: Anshu Kumari <anskuma@redhat.com>
> ---
>  conf.c  | 36 +++++++++++++++++++++++++++++++++++-
>  passt.h | 10 ++++++++++
>  2 files changed, 45 insertions(+), 1 deletion(-)
> 
> diff --git a/conf.c b/conf.c
> index 029b9c7..2624e58 100644
> --- a/conf.c
> +++ b/conf.c
> @@ -47,6 +47,7 @@
>  #include "lineread.h"
>  #include "isolation.h"
>  #include "log.h"
> +#include "dhcp.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"
> +		"  --dhcp-opt CODE,VAL	Set DHCP option by code\n");
>  	if (strstr(name, "pasta"))
>  		FPRINTF(f, "    default: don't use any search list\n");
>  	else
> @@ -844,6 +846,10 @@ static void conf_print(const struct ctx *c)
>  			info("    router: %s",
>  			     inet_ntop(AF_INET, &c->ip4.guest_gw,
>  				       buf, sizeof(buf)));
> +			for (i = 0; i < c->custom_opts_count; i++)
> +				info("    option %u: %s",
> +				     c->custom_opts[i].code,
> +				     c->custom_opts[i].str);
>  		}
>  
>  		for (i = 0; i < ARRAY_SIZE(c->ip4.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' },
> +		{"dhcp-opt", required_argument,		NULL,		33 },
>  		{ 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:";
> @@ -1465,6 +1472,33 @@ 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 33: {
> +			unsigned long code;
> +			const char *comma;
> +			char *end;
> +
> +			comma = strchr(optarg, ',');
> +			if (!comma)
> +				die("--dhcp-opt requires Option CODE,VALUE format");
> +
> +			code = strtoul(optarg, &end, 0);
> +			if (end != comma || code < 1 || code > 254)
> +				die("DHCP option code must be 1-254: %s",
> +				    optarg);
> +
> +			if (c->custom_opts_count >= MAX_CUSTOM_DHCP_OPTS)
> +				die("Too many --dhcp-opt entries (max %d)",
> +				    MAX_CUSTOM_DHCP_OPTS);
> +
> +			c->custom_opts[c->custom_opts_count].code = code;
> +			if (snprintf_check(c->custom_opts[c->custom_opts_count].str,
> +					   sizeof(c->custom_opts[0].str),
> +					   "%s", comma + 1))
> +				die("DHCP option value too long: %s",
> +				    comma + 1);
> +			c->custom_opts_count++;
> +			break;
> +		}
>  		case 'd':
>  			c->debug = 1;
>  			c->quiet = 0;
> diff --git a/passt.h b/passt.h
> index 1726965..acb57dd 100644
> --- a/passt.h
> +++ b/passt.h
> @@ -263,6 +263,16 @@ struct ctx {
>  	char hostname[PASST_MAXDNAME];
>  	char fqdn[PASST_MAXDNAME];
>  
> +#define MAX_CUSTOM_DHCP_OPTS	32
> +
> +	struct {
> +		uint8_t code;
> +		uint8_t len;
> +		uint8_t val[255];
> +		char str[256];
> +	} custom_opts[MAX_CUSTOM_DHCP_OPTS];
> +	int custom_opts_count;

Assuming you actually need those fields here (but the same reasoning
would apply to another struct as well): we document structs and fields
(and enums, and functions) using the so-called kerneldoc style:

  https://docs.kernel.org/doc-guide/kernel-doc.html

Just look at the beginning of struct ctx: you'll find those comments.
They need to be updated when you add / change / remove fields.

> +
>  	int ifi6;
>  	struct ip6_ctx ip6;
>  

-- 
Stefano


  parent reply	other threads:[~2026-05-20  0:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-18 13:19 [PATCH 0/6] Add --dhcp-boot and --dhcp-opt options Anshu Kumari
2026-05-18 13:19 ` [PATCH 1/6] conf: Add --dhcp-opt command-line option Anshu Kumari
2026-05-18 13:19   ` [PATCH 2/6] conf: Add --dhcp-boot " Anshu Kumari
2026-05-18 13:19     ` [PATCH 3/6] dhcp: Add option type table and value parser Anshu Kumari
2026-05-18 13:20       ` [PATCH 4/6] dhcp: Refactor fill_one() to operate on a generic buffer Anshu Kumari
2026-05-18 13:20         ` [PATCH 5/6] dhcp: Add option overload Anshu Kumari
2026-05-18 13:20           ` [PATCH 6/6] doc: Add --dhcp-boot and --dhcp-opt to man page Anshu Kumari
2026-05-19  6:11           ` [PATCH 5/6] dhcp: Add option overload David Gibson
2026-05-19  6:02         ` [PATCH 4/6] dhcp: Refactor fill_one() to operate on a generic buffer David Gibson
2026-05-19  5:59       ` [PATCH 3/6] dhcp: Add option type table and value parser David Gibson
2026-05-20  0:39       ` Stefano Brivio
2026-05-19  5:35     ` [PATCH 2/6] conf: Add --dhcp-boot command-line option David Gibson
2026-05-19  5:33   ` [PATCH 1/6] conf: Add --dhcp-opt " David Gibson
2026-05-20  0:38   ` Stefano Brivio [this message]
2026-05-19  5:30 ` [PATCH 0/6] Add --dhcp-boot and --dhcp-opt options David Gibson
2026-05-20  0:38   ` Stefano Brivio
2026-05-20  1:31     ` David Gibson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260520023813.1bb36a9a@elisabeth \
    --to=sbrivio@redhat.com \
    --cc=anskuma@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=jmaloy@redhat.com \
    --cc=lvivier@redhat.com \
    --cc=passt-dev@passt.top \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://passt.top/passt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).