From: Anshu Kumari <anskuma@redhat.com>
To: David Gibson <david@gibson.dropbear.id.au>
Cc: sbrivio@redhat.com, passt-dev@passt.top, lvivier@redhat.com,
jmaloy@redhat.com
Subject: Re: [PATCH v5 6/7] dhcp: Add RFC 3396 option splitting for concatenation-requiring options
Date: Mon, 20 Jul 2026 14:44:34 +0530 [thread overview]
Message-ID: <CADJNnVJg8iJ_RuHbC=uAODaoDdtFC4GvLJGOqv=afyiHZMxvXg@mail.gmail.com> (raw)
In-Reply-To: <al2iMfJFtImkHI2e@zatzit>
[-- Attachment #1: Type: text/plain, Size: 9329 bytes --]
On Mon, Jul 20, 2026 at 9:54 AM David Gibson <david@gibson.dropbear.id.au>
wrote:
> On Fri, Jul 17, 2026 at 11:26:43PM +0530, Anshu Kumari wrote:
> > Implement option splitting per RFC 3396 for options that may exceed
> > 255 bytes. A new DHCP_OPT_STR_CONCAT type marks concatenation-
> > requiring options (currently option 81, Client FQDN per RFC 4702).
> >
> > The opts[].s buffer is resized from 255 to 496 bytes to hold the
> > maximum data that can be split across the options field, file field,
> > and sname field.
> >
> > When a concatenation-requiring option does not fit as a single option
> > in any field, fill() splits it across fields in RFC 3396 order:
> > options field first, then file, then sname.
> >
> > Link: https://bugs.passt.top/show_bug.cgi?id=192
> > Signed-off-by: Anshu Kumari <anskuma@redhat.com>
> > ---
> > v5:
> > - New patch: implement option splitting per RFC 3396 for options
> exceeding 255 bytes
> > - Add DHCP_OPT_STR_CONCAT type, is_concat_opt(), fill_split() helpers
> > - Resize opts[].s from 255 to OPT_CONCAT_MAX (496) bytes
> > - Add /* fallthrough */ between DHCP_OPT_STR and DHCP_OPT_STR_CONCAT
> case
> >
> > ---
> > dhcp.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++++++--
> > 1 file changed, 106 insertions(+), 3 deletions(-)
> >
> > diff --git a/dhcp.c b/dhcp.c
> > index cc910ee..6bebb5f 100644
> > --- a/dhcp.c
> > +++ b/dhcp.c
> > @@ -34,6 +34,11 @@
> > #include "log.h"
> > #include "dhcp.h"
> >
> > +/* RFC 3396: maximum option data that can be split across options field,
> > + * file field, and sname field (minus code+length overhead per portion).
> > + */
> > +#define OPT_CONCAT_MAX 496
> > +
> > /**
> > * enum opt_state - DHCP option state
> > * @OPT_UNSET: Option not configured
> > @@ -58,7 +63,7 @@ enum opt_state {
> > struct opt {
> > int sent;
> > int slen;
> > - uint8_t s[255];
> > + uint8_t s[OPT_CONCAT_MAX];
> > int clen;
> > uint8_t c[255];
> > enum opt_state state;
> > @@ -159,6 +164,7 @@ struct msg {
> > * @DHCP_OPT_UINT16: Unsigned 16-bit integer
> > * @DHCP_OPT_UINT32: Unsigned 32-bit integer
> > * @DHCP_OPT_INT32: Signed 32-bit integer
> > + * @DHCP_OPT_STR_CONCAT:Concatenation-requiring string (RFC 3396)
>
> It's not entirely clear to me that encoding this in the opt_type enum
> makes sense. Generally the dhcp_opt_type is saying how the option is
> encoded as a string for the user. This is saying how it's encoded
> within the DHCP packet itself, which seems qualitatively different
> information.
>
> Since we don't limit on the string length that user can set via
--dhcp-opt, DHCP_OPT_STR rejects
anything over 255 bytes but with STR_CONCAT longer input can be parsed.
is_concat_opt() checks dhcp_opt_types[] for STR_CONCAT to decide which
options need splitting in fill().
I think these two concerns are coupled: an option that accepts long strings
from the CLI
is exactly the same option that needs splitting on the wire.
> > */
> > enum dhcp_opt_type {
> > DHCP_OPT_NONE,
> > @@ -169,6 +175,7 @@ enum dhcp_opt_type {
> > DHCP_OPT_UINT16,
> > DHCP_OPT_UINT32,
> > DHCP_OPT_INT32,
> > + DHCP_OPT_STR_CONCAT,
> > };
> >
> > /**
> > @@ -319,6 +326,10 @@ static int dhcp_opt_parse(uint8_t code, const char
> *str,
> >
> > return width;
> > case DHCP_OPT_STR:
> > + if (strlen(str) > 255)
> > + return -1;
> > + /* fallthrough */
> > + case DHCP_OPT_STR_CONCAT:
> > slen = strlen(str);
> >
> > if (slen >= buf_len)
> > @@ -465,6 +476,53 @@ enum dhcp_overload {
> > DHCP_OVERLOAD_SNAME,
> > };
> >
> > +/**
> > + * is_concat_opt() - Check if option requires RFC 3396 concatenation
> support
> > + * @o: Option number
> > + *
> > + * Return: true if option is a concatenation-requiring type
> > + */
> > +static bool is_concat_opt(int o)
> > +{
> > + if ((size_t)o >= ARRAY_SIZE(dhcp_opt_types))
> > + return false;
>
> IIUC, passing an out of bounds option code here would already be a bug
> in our code, so an assert() might make more sense.
>
> > + return dhcp_opt_types[o] == DHCP_OPT_STR_CONCAT;
> > +}
> > +
> > +/**
> > + * fill_split() - Write a split portion of an option into a buffer
> > + * @buf: Buffer to write into
> > + * @size: Usable size of @buf
> > + * @o: Option number (code)
> > + * @offset: Current offset within @buf, updated on write
> > + * @data: Pointer to remaining option data to write
> > + * @remaining: Bytes of option data still to write
> > + *
> > + * Return: number of data bytes written (excluding code+length header)
> > + */
> > +static size_t fill_split(uint8_t *buf, size_t size, int o, int *offset,
> > + const uint8_t *data, size_t remaining)
> > +{
> > + size_t avail, chunk;
> > +
> > + if (*offset + 2 >= (int)size)
> > + return 0;
> > +
> > + avail = size - *offset - 2;
> > + chunk = remaining < avail ? remaining : avail;
>
> You can use the existing MIN() macro here.
>
> > + if (!chunk)
> > + return 0;
> > +
> > + buf[*offset] = o;
> > + buf[*offset + 1] = chunk;
> > + *offset += 2;
> > +
> > + memcpy(buf + *offset, data, chunk);
> > + *offset += chunk;
> > +
> > + return chunk;
> > +}
> > +
> > /**
> > * fill() - Fill options in message, with overload into file/sname if
> needed
> > * @m: Message to fill
> > @@ -513,14 +571,59 @@ static int fill(struct msg *m, enum dhcp_overload
> *overload, bool has_bootfile)
> > for (o = 0; (size_t)o < ARRAY_SIZE(opts); o++) {
> > if (opts[o].state == OPT_UNSET || opts[o].sent)
> > continue;
> > -
> > if (!has_bootfile &&
> > fill_one(m->file, sizeof(m->file) - 1, o,
> > - &file_off))
> > + &file_off))
> > + if (!is_concat_opt(o))
> > debug("DHCP: skipping option %i"
> > " (overload full)", o);
> > }
> >
> > + /* RFC 3396: split concatenation-requiring options that didn't fit
> > + * as a single option. Split order: options, file, sname.
> > + */
> > + for (o = 0; (size_t)o < ARRAY_SIZE(opts); o++) {
> > + size_t file_cap, sname_cap, total, written;
> > +
> > + if (opts[o].state == OPT_UNSET || opts[o].sent ||
> > + !is_concat_opt(o))
> > + continue;
> > +
> > + sname_cap = sizeof(m->sname) - 1 > (size_t)sname_off ?
> > + sizeof(m->sname) - 1 - sname_off : 0;
> > +
> > + if (has_bootfile || sizeof(m->file) - 1 <=
> (size_t)file_off)
> > + file_cap = 0;
> > + else
> > + file_cap = sizeof(m->file) - 1 - file_off;
> > +
> > + total = (size > (size_t)offset ? size - offset : 0)
> > + + file_cap + sname_cap;
> > +
> > + if (total < (size_t)opts[o].slen) {
> >
>
> This doesn't account for the extra 2 bytes per chunk of option code
> and length, right?
>
yes, I missed it by chance while calculating the total available bytes.
>
> + debug("DHCP: skipping option %i (no space to
> split)",
> > + o);
> > + continue;
> > + }
> > +
> > + written = 0;
> > + written += fill_split(m->o, size, o, &offset,
> > + opts[o].s, opts[o].slen);
> > + if (written < (size_t)opts[o].slen && !has_bootfile)
> > + written += fill_split(m->file,
> > + sizeof(m->file) - 1, o,
> > + &file_off,
> > + opts[o].s + written,
> > + opts[o].slen - written);
> > + if (written < (size_t)opts[o].slen)
> > + fill_split(m->sname,
> > + sizeof(m->sname) - 1, o,
> > + &sname_off,
> > + opts[o].s + written,
> > + opts[o].slen - written);
> > + opts[o].sent = 1;
>
> Since you didn't account for the per-chunk header, I think you need to
> check for written < opts[o].slen and not set sent in that case.
>
> > + }
> > +
> > if (sname_off) {
> > m->sname[sname_off] = 255;
> > *overload |= DHCP_OVERLOAD_SNAME;
> > --
> > 2.54.0
> >
>
> --
> David Gibson (he or they) | I'll have my music baroque, and my code
> david AT gibson.dropbear.id.au | minimalist, thank you, not the other way
> | around.
> http://www.ozlabs.org/~dgibson
>
--
Anshu
[-- Attachment #2: Type: text/html, Size: 12528 bytes --]
next prev parent reply other threads:[~2026-07-20 9:14 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-17 17:56 [PATCH v5 0/7] Add --dhcp-boot and --dhcp-opt options Anshu Kumari
2026-07-17 17:56 ` [PATCH v5 1/7] dhcp: Refactor fill_one() to operate on a generic buffer Anshu Kumari
2026-07-20 1:18 ` David Gibson
2026-07-17 17:56 ` [PATCH v5 2/7] dhcp: Add option state management with enum opt_state Anshu Kumari
2026-07-20 1:36 ` David Gibson
2026-07-17 17:56 ` [PATCH v5 3/7] dhcp: Add option overload Anshu Kumari
2026-07-20 2:03 ` David Gibson
2026-07-17 17:56 ` [PATCH v5 4/7] dhcp: Add --dhcp-opt with option table and value parser Anshu Kumari
2026-07-20 3:58 ` David Gibson
2026-07-17 17:56 ` [PATCH v5 5/7] dhcp: Add --dhcp-boot command-line option Anshu Kumari
2026-07-20 4:06 ` David Gibson
2026-07-17 17:56 ` [PATCH v5 6/7] dhcp: Add RFC 3396 option splitting for concatenation-requiring options Anshu Kumari
2026-07-20 4:21 ` David Gibson
2026-07-20 9:14 ` Anshu Kumari [this message]
2026-07-17 17:56 ` [PATCH v5 7/7] dhcp: Handle FQDN option with RFC 3396 concatenation Anshu Kumari
2026-07-20 4:23 ` David Gibson
2026-07-20 7:38 ` Anshu Kumari
2026-07-21 0:34 ` 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='CADJNnVJg8iJ_RuHbC=uAODaoDdtFC4GvLJGOqv=afyiHZMxvXg@mail.gmail.com' \
--to=anskuma@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=jmaloy@redhat.com \
--cc=lvivier@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).