From: Stefano Brivio <sbrivio@redhat.com>
To: Anshu Kumari <anskuma@redhat.com>
Cc: passt-dev@passt.top, jmaloy@redhat.com,
david@gibson.dropbear.id.au, lvivier@redhat.com
Subject: Re: [PATCH v4 1/4] dhcp: Refactor fill_one() to operate on a generic buffer
Date: Wed, 01 Jul 2026 09:51:29 +0200 (CEST) [thread overview]
Message-ID: <20260701095128.4640ca6f@elisabeth> (raw)
In-Reply-To: <20260617132243.1499556-2-anskuma@redhat.com>
On Wed, 17 Jun 2026 18:52:35 +0530
Anshu Kumari <anskuma@redhat.com> 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>
> ---
> v4:
> - Unchanged from v3.
>
> 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 | 28 +++++++++++++---------------
> 1 file changed, 13 insertions(+), 15 deletions(-)
>
> diff --git a/dhcp.c b/dhcp.c
> index 1ff8cba..8e3ffd6 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 + slen > size)
This looks like an automatic linter dropping comments, but I think the
original comment is quite useful. See also Laurent's review of v2:
https://archives.passt.top/passt-dev/3b36426b-798c-489c-aad2-abcde13d2e93@redhat.com/
> 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);
I think slightly more idiomatic: buf + *offset. Otherwise you have a
pointer, dereference it, and then take its address. It looks a bit
convoluted.
Conversely, using buf[*offset] above makes sense because you need to
dereference buf anyway.
>
> opts[o].sent = 1;
> *offset += slen;
> @@ -177,20 +178,17 @@ 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");
> + fill_one(m->o, OPT_MAX, 53, &offset);
>
> for (i = 0; i < opts[55].clen; i++) {
> o = opts[55].c[i];
> if (opts[o].slen != -1)
> - if (fill_one(m, o, &offset))
> - debug("DHCP: skipping option %i", o);
> + fill_one(m->o, OPT_MAX, o, &offset);
> }
>
> for (o = 0; o < 255; o++) {
> if (opts[o].slen != -1 && !opts[o].sent)
> - if (fill_one(m, o, &offset))
> - debug("DHCP: skipping option %i", o);
> + fill_one(m->o, OPT_MAX, o, &offset);
> }
>
> m->o[offset++] = 255;
I also had the same comment as David's about dropping debug()
messages... until I reached 2/4, which is a good indication that they
should go away later.
--
Stefano
next prev parent reply other threads:[~2026-07-01 7:51 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-17 13:22 [PATCH v4 0/4] Add --dhcp-boot and --dhcp-opt options Anshu Kumari
2026-06-17 13:22 ` [PATCH v4 1/4] dhcp: Refactor fill_one() to operate on a generic buffer Anshu Kumari
2026-06-19 3:26 ` David Gibson
2026-07-01 7:51 ` Stefano Brivio [this message]
2026-06-17 13:22 ` [PATCH v4 2/4] dhcp: Add option overload Anshu Kumari
2026-06-19 3:39 ` David Gibson
2026-06-19 7:55 ` Anshu Kumari
2026-06-22 2:43 ` David Gibson
2026-07-01 7:51 ` Stefano Brivio
2026-07-01 17:00 ` Stefano Brivio
2026-06-17 13:22 ` [PATCH v4 3/4] dhcp: Add --dhcp-opt with option table and value parser Anshu Kumari
2026-06-19 3:52 ` David Gibson
2026-06-19 7:29 ` Anshu Kumari
2026-06-22 2:42 ` David Gibson
2026-07-01 7:51 ` Stefano Brivio
2026-07-01 17:00 ` Stefano Brivio
2026-06-17 13:22 ` [PATCH v4 4/4] conf: Add --dhcp-boot command-line option Anshu Kumari
2026-06-19 3:53 ` 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=20260701095128.4640ca6f@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).