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=202602 header.b=NvZfnhdr; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 99E4F5A0265 for ; Tue, 02 Jun 2026 04:54:53 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780368890; bh=oHOgjlghcyQaCcwudK1+SL+vMisMx4xs/o0ESMoyZ2U=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NvZfnhdrCMfjnbtMYSLvTaz6sOFKH401LxKbCSoZUgSTFxgBRcBkk2bwJJxDGJjyo cn1KnJ+JvtGWZ6FUoh/N/RsEK9v333NMjaZTQLFDFobmw3hD7VmozNOHcwiQdxAMKc biNdSU4CUR0YrzhZCimwQqZGJ/fvZBiOM++XGJNGxOY471BDST8r0obMNTj8Mk/His UwQ1WQ/ii43rNfQkLG3HHAcwnkauFOfVsf++QSvYU3gdloJC0VshSPyrZJBQb/fUos wdMDobk3CEKH+834IQsMge+91LID+vq75h6WnoRsqGlycUdR1uFsUMcaUv2CRGVtg5 Mw/Q5h/yFTrOw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gTwRG3ksNz4wKK; Tue, 02 Jun 2026 12:54:50 +1000 (AEST) Date: Tue, 2 Jun 2026 12:50:54 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v3 5/6] dhcp: Add option overload Message-ID: References: <20260601073758.1571317-1-anskuma@redhat.com> <20260601073758.1571317-6-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="/FQ7JrdWTazZr7ep" Content-Disposition: inline In-Reply-To: <20260601073758.1571317-6-anskuma@redhat.com> Message-ID-Hash: AWGA6DXSWB4AW6RIRUAFWTQQL5W4XMWJ X-Message-ID-Hash: AWGA6DXSWB4AW6RIRUAFWTQQL5W4XMWJ 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: --/FQ7JrdWTazZr7ep Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 01, 2026 at 01:07:55PM +0530, Anshu Kumari wrote: > A user can enter lots of options in command-line which may not fit in > existing buffer, So when the options field is full, overflow remaining > DHCP options into the file and sname fields per RFC 2132 option 52. >=20 > Also, when the file field is not used for overload, copy the boot > file URL there directly for legacy PXE clients. >=20 > Link: https://bugs.passt.top/show_bug.cgi?id=3D192 > Signed-off-by: Anshu Kumari Reviewed-by: David Gibson For the code proper. The commit message is perhaps buries the lede in that in that this is also the patch that actually starts putting the custom_opts into DHCP replies. Mind you, that would change if we parsed directly into opts[], which might be nicer anyway. > --- > 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 | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 81 insertions(+), 10 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 5c6a492..a9d56fd 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -372,14 +372,64 @@ static bool fill_one(uint8_t *buf, size_t size, int= o, int *offset) > return false; > } > =20 > +/* RFC 2132, Section 9.3 - Option Overload*/ > +#define DHCP_OVERLOAD_FILE 1 > +#define DHCP_OVERLOAD_SNAME 2 > + > /** > - * fill() - Fill options in message > + * fill_overflow() - Fill remaining options into sname and file fields > + * @m: Message whose sname/file fields may be used for overflow > + * > + * Try the smaller sname field first: small options go there, leaving > + * the larger file field available for big options and for the boot > + * file name (option 67) if set. > + * > + * Return: option 52 overload value: 0 if no overflow, > + * DHCP_OVERLOAD_FILE for file, DHCP_OVERLOAD_SNAME for sname, > + * or both OR'd together > + */ > +static int fill_overflow(struct msg *m) > +{ > + int sname_off =3D 0, file_off =3D 0, overload =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); > + } > + > + 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); > + } > + > + 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) > * > * Return: current size of options field > */ > -static int fill(struct msg *m) > +static int fill(struct msg *m, int *overload) > { > + /* 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++) > @@ -390,20 +440,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)) > - if (fill_one(m->o, OPT_MAX, 53, &offset)) > - debug("DHCP: skipping option 53"); > + 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) > - if (fill_one(m->o, OPT_MAX, o, &offset)) > - debug("DHCP: skipping option %i", o); > + fill_one(m->o, size, o, &offset); > } > =20 > for (o =3D 0; o < 255; o++) { > if (opts[o].slen !=3D -1 && !opts[o].sent) > - if (fill_one(m->o, OPT_MAX, o, &offset)) > - debug("DHCP: skipping option %i", o); > + fill_one(m->o, size, o, &offset); > + } > + > + *overload =3D fill_overflow(m); > + > + if (*overload) { > + m->o[offset++] =3D 52; > + m->o[offset++] =3D 1; > + m->o[offset++] =3D *overload; > } > =20 > m->o[offset++] =3D 255; > @@ -528,6 +583,7 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > struct msg const *m; > struct msg reply; > unsigned int i; > + int overload; > =20 > eh =3D IOV_REMOVE_HEADER(data, eh_storage); > iph =3D IOV_PEEK_HEADER(data, iph_storage); > @@ -677,9 +733,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); > + > + for (i =3D 0; i < (unsigned int)c->custom_opts_count; i++) { > + uint8_t code =3D c->custom_opts[i].code; > + > + opts[code].slen =3D c->custom_opts[i].len; > + memcpy(opts[code].s, c->custom_opts[i].val, > + c->custom_opts[i].len); > + } > + > + dlen =3D offsetof(struct msg, o) + fill(&reply, &overload); > =20 > - dlen =3D offsetof(struct msg, o) + fill(&reply); > + /* Copy boot file name into the file field for legacy PXE clients, > + * unless the file field is already used for option overload. > + */ > + if (!(overload & DHCP_OVERLOAD_FILE) && > + opts[67].slen > 0 && (size_t)opts[67].slen < sizeof(reply.file)) > + memcpy(reply.file, opts[67].s, opts[67].slen); > =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 --/FQ7JrdWTazZr7ep Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoeRQ0ACgkQzQJF27ox 2GcNkg//Zqa7Ay649ZRU+3EZyta1as+XempofMF0JMKLLkH82L/FG9GGV1qo1f42 H4Lx8MvcEDx87PYDx4O7AJovvyqHEzG/XzcJhQ5AD3NwPu0c3CP8qIf4Xmf2yi/R QsJvKmja/YzD607mNeF5b2JDYFgeXjeQJsm9/haw/ilzxWxQsgGFOxiMyYIaRBOU nahOvjsDOTfXe4/3PTXPElH4QtQqvuQudB0YJTMCrNk9iXzNbsd7/zS63VQt+GWt xEiJy8DCKefa8wDQlAATitXSg58PD3t4QSNHDV9iuaGt5z25ObTY2oFkHCuKnTT6 kJjZnL+hKOCWMniUshRwFXNOjqixxprJJMcutdQzB5UEC4otbWakMGKlU1+jB+bS sGMAb1ap/W3E40e44MihKnHqy+4XGB1nd8tyd6EGPrAfo+sY/P3EGyZxk4VN9AJE OH0krPNDAVaDbTIiqlVjFPbJ7EqwCJmh9aiwXTIsEZgNBu8f+NVxeicPMnFu01h7 x0i8cnrWs4Q9bvVRcTZg3Nxfy5+Rw1h9eeyJQLDQywhxq0ftSBgdJv2jEGP9XtKO /n02VzfrakCWHkmBAd0Y5Mzp1ca8P/FhvEJWWQ5IXWGc2sZRSMOptpACEmEMC8NL 6A9NTacDHe9bskvxq/Sg+URdv7nX1ryCSDtQu0Up+1uNULNo4gU= =F8C+ -----END PGP SIGNATURE----- --/FQ7JrdWTazZr7ep--