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=nrLWHZgq; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id CBAF15A026D for ; Wed, 27 May 2026 06:16:19 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779855376; bh=xPTnXHyGATRx6dHMP3Sf7Usat0Q2jqYL+1ppn5xDnnA=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=nrLWHZgqHwY6IcFGJmJwKufs4c0HTe9Akmx3vQoWoUqy/2cmWG0B4h4aMU3gNJlRT HNsJDU+6DXls4g3RqrqmdPLF7Zr4hMfhnuaPLdZoxeT0HhQY8PIiqMtnI6cYdgFkCp 6YBjC72f8E8shO5Q3oOrKPbF/XEjnfUZTs1Q/HfOicGYNK2PcHDkGBD2R6nJyKS7Tc 7dcJ3iSf119bpMRlKH7U/z1PUdonGliDghEf/+paLzi79T2rvstGVO0FGeGoHusZ/T R0HbJA87UPJKnvFPM9MtWMab6CkEv2P8gYahZFTpcURSPnYV6BZpTBV0C5mRkEe/x1 VMrutb3+E8VPQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gQGX05pSlz4wCH; Wed, 27 May 2026 14:16:16 +1000 (AEST) Date: Wed, 27 May 2026 14:03:44 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v2 5/6] dhcp: Add option overload Message-ID: References: <20260526123115.1226166-1-anskuma@redhat.com> <20260526123115.1226166-6-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="rwCmi0Op71HukHcO" Content-Disposition: inline In-Reply-To: <20260526123115.1226166-6-anskuma@redhat.com> Message-ID-Hash: K3F4KADWCL4UR5EGGNW4ZO5MECLLNCVV X-Message-ID-Hash: K3F4KADWCL4UR5EGGNW4ZO5MECLLNCVV 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: --rwCmi0Op71HukHcO Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, May 26, 2026 at 06:01:12PM +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 > --- > 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 | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 75 insertions(+), 9 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index e126063..a49a05a 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -306,14 +306,59 @@ static bool fill_one(uint8_t *buf, size_t size, int= o, int *offset) > return false; > } > =20 > +#define DHCP_OVERLOAD_FILE 1 > +#define DHCP_OVERLOAD_SNAME 2 IIUC, these values are from the RFC - might be worth referencing the relevant section in a comment to make it clear they can't be changed arbitrarily. > + > +/** > + * fill_overflow() - Fill remaining options into file and sname fields > + * @m: Message whose file/sname fields may be used for overflow > + * > + * 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 file_off =3D 0, sname_off =3D 0, overload =3D 0; > + int o; > + > + for (o =3D 0; o < 255; o++) { You could use ARRAY_size(opts) instead of raw 255, yes? > + if (opts[o].slen =3D=3D -1 || opts[o].sent) > + continue; > + fill_one(m->file, sizeof(m->file) - 1, o, &file_off); > + } > + > + for (o =3D 0; o < 255; o++) { > + if (opts[o].slen =3D=3D -1 || opts[o].sent) > + continue; > + if (fill_one(m->sname, sizeof(m->sname) - 1, o, &sname_off)) > + debug("DHCP: skipping option %i (overload full)", o); > + } > + > + if (file_off) { > + m->file[file_off] =3D 255; > + overload |=3D DHCP_OVERLOAD_FILE; > + } > + > + if (sname_off) { > + m->sname[sname_off] =3D 255; > + overload |=3D DHCP_OVERLOAD_SNAME; > + } > + > + return overload; > +} > + > /** > - * fill() - Fill options in message > + * 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++) > @@ -324,20 +369,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; > @@ -462,6 +512,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); > @@ -613,7 +664,22 @@ int dhcp(const struct ctx *c, struct iov_tail *data) > if (!c->no_dhcp_dns_search) > opt_set_dns_search(c, sizeof(m->o)); > =20 > - dlen =3D offsetof(struct msg, o) + fill(&reply); > + 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); > + > + /* Copy boot file name into the file field for legacy PXE clients, > + * unless the file field is already used for option overload. Given we do this, would it make more sense to use the slen field in preference to the file field for overloads? The logic above appears to do it the other way around, > + */ > + 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 + 1); > =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 --rwCmi0Op71HukHcO Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoWbR8ACgkQzQJF27ox 2GfkaQ/+Lj4zVDb4zYPz0j/0mU4v4UTVqT8m1TSzQKN+evId/cmFs1iVGRQ2E6ks m5C/gz8/BrZ/pcaumAy/cjO/LfWg1HyyLn52/29HfEAPEqhI9OTCTTS6h9GG/RFY DAvefK8PBrTDYfNYCBeHWBJUaAQXqMAjT8j1/ncj+2+kjdaVS2nQhGV8n+3V7Acs G0CGHhEgLEo8WZl1s0+icc5gNz8LP+B0KdngEInQC2R/l7JjaCEx2iwEeLsm4qjI qsIrkqzAHSi0BYX/y8ajfGPhPihUnXXj0i/iNagMXsaLVKVnd/jLT3TCoR5IEIc6 5SXnlffbvawQQ+P8oJ3hA4RrrTv1vwZTDN+qZsWN0HEhgyhBLEfP0sWhhebkRVQL TMsgiioj67qxoB9/M9bKCmi4bu/dYiTcpNeborHGSAB5ZJL83FW6xIPuvdYvsdip 7kgaXgy7AefPIefub1HJAitud5H/X3BoPn6r6vPgFmNGicwBeXIQPUnt96hEPQUb qNVW1SD/hFQy/eEJ+l/46UVDx//ENmcgPiS/tICUDOFwomtby7vEENTSz8EsJLWt jZRNJkA1gaSPpNCjTexGIWlTCGComrT7GEyRQbJX/0kykZ+22z53XljR0sycZDXm Zo9pJY1HY0cTJMys7KK4S0cQrrjELVnOJEtW9LuqYEUDG8sFc0U= =U1b1 -----END PGP SIGNATURE----- --rwCmi0Op71HukHcO--