From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=none (p=none dis=none) header.from=gibson.dropbear.id.au Authentication-Results: passt.top; dkim=pass (2048-bit key; secure) header.d=gibson.dropbear.id.au header.i=@gibson.dropbear.id.au header.a=rsa-sha256 header.s=202606 header.b=Pm64VvGJ; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id D39545A0272 for ; Fri, 19 Jun 2026 05:54:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1781841241; bh=2shYGc0qMWTAAYVOWGOcN3/B7JV0x044h3JcE0TMigw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Pm64VvGJYJ6F7d4MOy+gO11iYzFR2AK/+5K5z776sA0zLk/6ofFe+z7CWAkXD09d8 4/GB2SXX+YDi56bI8Yz3lGoGDSg9fI0Qcs3VJzBzKRrb/28AlE/QsPSY81b5cMVBcr X3KYu/6rznGhQZ8rISC5YSPauSjQ15LI+e7x1a5jLwt6H1+dpn9/ilsvniBI6iEUAK huWAb2cYQtCBm7qsvGzEkBg3kJklmmvw7Cubrbf1M6JCzYOd3REIzihi2zXz4QDNe4 BiCnIYZn8xVLTOJR1DDAt2geVEsnnAPMzINXIH5sdBxxFH3gHQ1b9ljLjdAmPbNcOx DHAncKKkbdqdQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ghNxj6f4Hz58sj; Fri, 19 Jun 2026 13:54:01 +1000 (AEST) Date: Fri, 19 Jun 2026 13:39:25 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v4 2/4] dhcp: Add option overload Message-ID: References: <20260617132243.1499556-1-anskuma@redhat.com> <20260617132243.1499556-3-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="wR/ODb/FjZyuiN7c" Content-Disposition: inline In-Reply-To: <20260617132243.1499556-3-anskuma@redhat.com> Message-ID-Hash: LYAGEEUUINNQVLSUUVDOOFLYSSEYZOVI X-Message-ID-Hash: LYAGEEUUINNQVLSUUVDOOFLYSSEYZOVI X-MailFrom: dgibson@gandalf.ozlabs.org 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: passt-dev@passt.top, sbrivio@redhat.com, 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: --wR/ODb/FjZyuiN7c Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Wed, Jun 17, 2026 at 06:52:36PM +0530, Anshu Kumari wrote: > When the options field is full, overflow remaining DHCP options into > the sname and file fields per RFC 2132 option 52. >=20 > Per RFC 2132, Section 9.5, the boot file name is always placed in the > 'file' header field. When a boot file is set, the file field is > reserved from overload and overflow uses only the sname field. >=20 > Link: https://bugs.passt.top/show_bug.cgi?id=3D192 > Signed-off-by: Anshu Kumari > --- > v4: > - Converted overload #defines to enum dhcp_overload. > - Fixed missing whitespace in comment before */. > - Boot file name always placed in 'file' header field per RFC 2132, > Section 9.5; file field reserved from overload when bootfile is > set; option 67 suppressed from options area. >=20 > v3: > - Added RFC 2132 Section 9.3 reference comment on overload > constants. > - Use ARRAY_SIZE(opts) instead of raw 255 in fill_overflow(). > - Swapped overflow order: try sname (64 bytes) first, then file > (128 bytes) =E2=80=94 better packing and keeps file field available f= or > boot file name. > - Removed '&' from &reply.file. > - Removed '+1' from memcpy =E2=80=94 reply.file already zeroed. > - opt_set_dns_search() max_len: OPT_MAX - 3 instead of > sizeof(m->o). >=20 > v2: > - Added #define DHCP_OVERLOAD_FILE and #define DHCP_OVERLOAD_SNAME cons= tants > - Added comment documenting space reservation: /* Reserve 3 bytes for o= ption 52 */ > - Fixed DNS search length: sizeof(m->o) only, not combined with file+sn= ame > - Removed dhcp_boot references =E2=80=94 reply.file copy now reads from= opts[67] > - Used DHCP_OVERLOAD_FILE constant in reply.file guard > --- > dhcp.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- > 1 file changed, 100 insertions(+), 8 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 8e3ffd6..78790d8 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -160,14 +160,79 @@ static bool fill_one(uint8_t *buf, size_t size, int= o, int *offset) > return false; > } > =20 > +/* RFC 2132, Section 9.3 - Option Overload */ > +enum dhcp_overload { > + DHCP_OVERLOAD_NONE =3D 0, > + DHCP_OVERLOAD_FILE =3D 1, > + DHCP_OVERLOAD_SNAME =3D 2, > +}; > + > /** > - * fill() - Fill options in message > - * @m: Message to fill > + * fill_overflow() - Fill remaining options into sname and file fields > + * @m: Msg whose sname/file fields may be used for overflow > + * @has_bootfile: If true, reserve the file field for the boot file name > + * > + * Try the smaller sname field first: small options go there, leaving > + * the larger file field available for big options. When @has_bootfile > + * is set, the file field is reserved for the boot file name per > + * RFC 2132, Section 9.5 and is not used for option overflow. > + * > + * Return: option 52 overload value > + */ > +static enum dhcp_overload fill_overflow(struct msg *m, bool has_bootfile) > +{ > + enum dhcp_overload overload =3D DHCP_OVERLOAD_NONE; > + int sname_off =3D 0, file_off =3D 0; > + int o; > + > + for (o =3D 0; (size_t)o < ARRAY_SIZE(opts); o++) { > + if (opts[o].slen =3D=3D -1 || opts[o].sent) > + continue; > + fill_one(m->sname, sizeof(m->sname) - 1, o, &sname_off); Ah, I think I see now. The earlier debug() messages were removed in favour of the ones later, because we don't want spurious messages if the option doesn't fit in the main area but does fit in the overload. That's a reasonable change, but needs to be better explained. It also all belongs in this patch, so the bits that leaked into the previous patch should be here instead. > + } > + > + if (!has_bootfile) { > + for (o =3D 0; (size_t)o < ARRAY_SIZE(opts); o++) { > + if (opts[o].slen =3D=3D -1 || opts[o].sent) > + continue; > + if (fill_one(m->file, sizeof(m->file) - 1, o, > + &file_off)) > + debug("DHCP: skipping option %i" > + " (overload full)", o); > + } > + } else { Rather that checking for fill_one() failures only on the last pass, then having this fallback case, you can have a single unconditional pass at the end looking for skipped options. Then fill_one()s signature can be changed to void to match. > + for (o =3D 0; (size_t)o < ARRAY_SIZE(opts); o++) { > + if (opts[o].slen =3D=3D -1 || opts[o].sent) > + continue; > + debug("DHCP: skipping option %i (overload full)", o); > + } > + } > + > + if (sname_off) { > + m->sname[sname_off] =3D 255; > + overload |=3D DHCP_OVERLOAD_SNAME; > + } > + > + if (file_off) { > + m->file[file_off] =3D 255; > + overload |=3D DHCP_OVERLOAD_FILE; > + } > + > + return overload; > +} > + > +/** > + * fill() - Fill options in message, with overload into file/sname if ne= eded > + * @m: Message to fill > + * @overload: Set to option 52 value (0 if none, 1/2/3 per RFC 2132) > + * @has_bootfile: Reserve file field for boot file name > * > * Return: current size of options field > */ > -static int fill(struct msg *m) > +static int fill(struct msg *m, enum dhcp_overload *overload, bool has_bo= otfile) > { > + /* Reserve 3 bytes for option 52 (overload) if needed */ > + size_t size =3D OPT_MAX - 3; > int i, o, offset =3D 0; > =20 > for (o =3D 0; o < 255; o++) > @@ -178,17 +243,25 @@ 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)) > - fill_one(m->o, OPT_MAX, 53, &offset); > + fill_one(m->o, size, 53, &offset); > =20 > for (i =3D 0; i < opts[55].clen; i++) { > o =3D opts[55].c[i]; > if (opts[o].slen !=3D -1) > - fill_one(m->o, OPT_MAX, o, &offset); > + fill_one(m->o, size, o, &offset); > } > =20 > for (o =3D 0; o < 255; o++) { > if (opts[o].slen !=3D -1 && !opts[o].sent) > - fill_one(m->o, OPT_MAX, o, &offset); > + fill_one(m->o, size, o, &offset); > + } > + > + *overload =3D fill_overflow(m, has_bootfile); Is there a particular reason to put fill_overflow() in its own function, rather than just inline here? > + > + if (*overload) { > + m->o[offset++] =3D 52; > + m->o[offset++] =3D 1; > + m->o[offset++] =3D *overload; > } > =20 > m->o[offset++] =3D 255; > @@ -301,6 +374,7 @@ static void opt_set_dns_search(const struct ctx *c, s= ize_t max_len) > int dhcp(const struct ctx *c, struct iov_tail *data) > { > char macstr[ETH_ADDRSTRLEN]; > + enum dhcp_overload overload; > size_t mlen, dlen, opt_len; > struct in_addr mask, dst; > struct ethhdr eh_storage; > @@ -309,9 +383,12 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > const struct ethhdr *eh; > const struct iphdr *iph; > const struct udphdr *uh; > + uint8_t bootfile[128]; > struct msg m_storage; > struct msg const *m; > + bool has_bootfile; > struct msg reply; > + int bootfile_len; > unsigned int i; > =20 > eh =3D IOV_REMOVE_HEADER(data, eh_storage); > @@ -462,9 +539,24 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > } > =20 > if (!c->no_dhcp_dns_search) > - opt_set_dns_search(c, sizeof(m->o)); > + opt_set_dns_search(c, OPT_MAX - 3); > + > + /* RFC 2132, Section 9.5: put boot file name in the 'file' header > + * field. Suppress option 67 from the options area and reserve > + * the file field from overload. > + */ > + has_bootfile =3D opts[67].slen > 0 && > + (size_t)opts[67].slen < sizeof(reply.file); > + if (has_bootfile) { > + memcpy(bootfile, opts[67].s, opts[67].slen); > + bootfile_len =3D opts[67].slen; > + opts[67].slen =3D -1; > + } > + > + dlen =3D offsetof(struct msg, o) + fill(&reply, &overload, has_bootfile= ); > =20 > - dlen =3D offsetof(struct msg, o) + fill(&reply); > + if (has_bootfile) > + memcpy(reply.file, bootfile, bootfile_len); > =20 > if (m->flags & FLAG_BROADCAST) > dst =3D in4addr_broadcast; > --=20 > 2.54.0 >=20 --=20 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 --wR/ODb/FjZyuiN7c Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmo0ud0ACgkQzQJF27ox 2GdAGQ//T9JM0nixAwfbdvQv5TO6Pb4NKlUe1BLdoF26ILnuMxz6ZMSCT17HQWYd zFgdskcIbxlEKkCQXDaIvgeCTmtNOnLkDZD2YLmKaWkvgAk5QVenQAID7JBNIOmw E+ozVuK0PBJRkXe/T82wyJ+4eZoAZnaGOHH0DkCgbbaMSYWrNEtnMbNAnwH+hgys YQCnAviNPOTttMk0pulAONe+ckxnRFs5adL10AGkR6TICxbAsfno0ssk+pm5XMY4 qNx1A1Qbf9ifH17Rad7iHefV/Z6q+8bmruiW2UbZQ8iD0s948jeKIVybHy/1MmdX 22WFitV4qiXzygRaMCa8mR6QctfWHjURpOGb9gw/gnKETxNPBxpi7Jb2n71xTQwK MFgHBIhj7HmJfldppV8U1F1gGmZ12uc10AJJPn5SEr0dATdqbuRusQeAzR6m+mE9 enP40hg1SF3U8hwbXrtmrUYid8Ust8vOnk/jD8ijKsI9Gs/EWwomUhbRUZq407aw VjJXZPEnnD1X5lC8pnwRpORcZqY05Ga1vjgAw/aOon/Tztlr7DmmmrEzfAn7rFGq CluxiieVL9FJdIfDhI6fJ1Rnd5HNMVisWQ5HBykK6BeFueDATZsqyvavzD+PETzC vJddexvPPfJUq45LznJwUmyYzLimSfwFNNhe/s53Uac3bqf4c1g= =eGGN -----END PGP SIGNATURE----- --wR/ODb/FjZyuiN7c--