public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: Laurent Vivier <lvivier@redhat.com>
To: Anshu Kumari <anskuma@redhat.com>,
	sbrivio@redhat.com, passt-dev@passt.top
Cc: david@gibson.dropbear.id.au, jmaloy@redhat.com
Subject: Re: [PATCH v6 1/6] dhcp: Refactor fill_one() to operate on a generic buffer
Date: Tue, 25 Aug 2026 17:13:27 +0200	[thread overview]
Message-ID: <34e2ec79-fec5-4694-8a38-060da24c77d2@redhat.com> (raw)
In-Reply-To: <20260824134436.282300-2-anskuma@redhat.com>

On 8/24/26 15:44, Anshu Kumari wrote:
> Change fill_one() to accept a buffer pointer and capacity instead of
> a struct msg pointer.  This is a pure refactor with no behavior change,
> preparing for option overload support where fill_one() will also write
> into the file and sname fields.
> 
> Link: https://bugs.passt.top/show_bug.cgi?id=192
> Signed-off-by: Anshu Kumari <anskuma@redhat.com>
> ---
> v6:
>    - no changes.
> 
> v5:
>    - Restore debug messages for skipped options in fill()
>    - Add /* code and length of option */ comment in size check
>    - Use buf + *offset instead of &buf[*offset] for memcpy
> 
> v3:
>    - Restored removed comments: "If we don't have space to write the
>      option, then just skip" and "Move to option".
> 
> v2:
>    - Renamed parameter cap → size.
> ---
>   dhcp.c | 27 ++++++++++++++-------------
>   1 file changed, 14 insertions(+), 13 deletions(-)

Reviewed-by: Laurent Vivier <lvivier@redhat.com>

> 
> diff --git a/dhcp.c b/dhcp.c
> index c3c7422..bb72b72 100644
> --- a/dhcp.c
> +++ b/dhcp.c
> @@ -131,28 +131,29 @@ struct msg {
>   } __attribute__((__packed__));
>   
>   /**
> - * fill_one() - Fill a single option in message
> - * @m:		Message to fill
> + * fill_one() - Fill a single option into a buffer
> + * @buf:	Buffer to write option
> + * @size:	Usable size of @buf (excluding end marker)
>    * @o:		Option number
> - * @offset:	Current offset within options field, updated on insertion
> + * @offset:	Current offset within @buf, updated on insertion
>    *
> - * Return: false if m has space to write the option, true otherwise
> + * Return: false if @buf has space to write the option, true otherwise
>    */
> -static bool fill_one(struct msg *m, int o, int *offset)
> +static bool fill_one(uint8_t *buf, size_t size, int o, int *offset)
>   {
>   	size_t slen = opts[o].slen;
>   
>   	/* If we don't have space to write the option, then just skip */
> -	if (*offset + 2 /* code and length of option */ + slen > OPT_MAX)
> +	if (*offset + 2 /* code and length of option */ + slen > size)
>   		return true;
>   
> -	m->o[*offset] = o;
> -	m->o[*offset + 1] = slen;
> +	buf[*offset] = o;
> +	buf[*offset + 1] = slen;
>   
>   	/* Move to option */
>   	*offset += 2;
>   
> -	memcpy(&m->o[*offset], opts[o].s, slen);
> +	memcpy(buf + *offset, opts[o].s, slen);
>   
>   	opts[o].sent = 1;
>   	*offset += slen;
> @@ -177,19 +178,19 @@ static int fill(struct msg *m)
>   	 * Put it there explicitly, unless requested via option 55.
>   	 */
>   	if (opts[55].clen > 0 && !memchr(opts[55].c, 53, opts[55].clen))
> -		if (fill_one(m, 53, &offset))
> -			 debug("DHCP: skipping option 53");
> +		if (fill_one(m->o, OPT_MAX, 53, &offset))
> +			debug("DHCP: skipping option 53");
>   
>   	for (i = 0; i < opts[55].clen; i++) {
>   		o = opts[55].c[i];
>   		if (opts[o].slen != -1)
> -			if (fill_one(m, o, &offset))
> +			if (fill_one(m->o, OPT_MAX, o, &offset))
>   				debug("DHCP: skipping option %i", o);
>   	}
>   
>   	for (o = 0; o < 255; o++) {
>   		if (opts[o].slen != -1 && !opts[o].sent)
> -			if (fill_one(m, o, &offset))
> +			if (fill_one(m->o, OPT_MAX, o, &offset))
>   				debug("DHCP: skipping option %i", o);
>   	}
>   


  reply	other threads:[~2026-08-25 15:13 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-24 13:44 [PATCH v6 0/6] Add --dhcp-boot and --dhcp-opt options Anshu Kumari
2026-08-24 13:44 ` [PATCH v6 1/6] dhcp: Refactor fill_one() to operate on a generic buffer Anshu Kumari
2026-08-25 15:13   ` Laurent Vivier [this message]
2026-08-24 13:44 ` [PATCH v6 2/6] dhcp: Add option state management with enum opt_state Anshu Kumari
2026-08-25 15:35   ` Laurent Vivier
2026-08-24 13:44 ` [PATCH v6 3/6] dhcp: Add option overload Anshu Kumari
2026-08-26  7:56   ` Laurent Vivier
2026-08-24 13:44 ` [PATCH v6 4/6] dhcp: Add --dhcp-opt with option table and value parser Anshu Kumari
2026-08-26 10:00   ` Laurent Vivier
2026-08-24 13:44 ` [PATCH v6 5/6] dhcp: Add --dhcp-boot command-line option Anshu Kumari
2026-08-26  8:09   ` Laurent Vivier
2026-08-24 13:44 ` [PATCH v6 6/6] dhcp: Add RFC 3396 option splitting for concatenation-requiring options Anshu Kumari
2026-08-26 14:11   ` Laurent Vivier

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=34e2ec79-fec5-4694-8a38-060da24c77d2@redhat.com \
    --to=lvivier@redhat.com \
    --cc=anskuma@redhat.com \
    --cc=david@gibson.dropbear.id.au \
    --cc=jmaloy@redhat.com \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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).