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=Bw0vz2co; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 5BDCD5A026D for ; Tue, 19 May 2026 08:12:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779171122; bh=x+j3+HLAQS7qTBloavBa8PUndoQogovXpaI80gShSHc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=Bw0vz2cohUHLgP+jxPALtBGU/V0kDO0SuT1VNtmHlvGcgT7WwG39sYM8e6PANZdh/ cdbYwIXsX++KwLmFoAKJiHwVj1H76NBTaUEqtl1mKrEd2IB7d5L8KgDk5KinpXWOXr w+aeCUbOB1Bt2T1yd1//UyvLXcqa0YX7MN5MsArzNjkn+m0GCR8DKGPkZel0JXzACt Dz2JLI5ZjTM+nJ/jW/G+6rLUCbfYdBdS/cjyaJOj7RZMq7ZWRtKbeyqK5lIUXd/mE6 dLcGgvkIHnnUQl3oQfxo/EfvOBXw5/pcCevVJAgScXVFk89mzUiTMR4dV/Mw4H6BY4 oFVVVmCyp7PZw== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gKPTG1H7Rz4wQl; Tue, 19 May 2026 16:12:02 +1000 (AEST) Date: Tue, 19 May 2026 16:11:24 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH 5/6] dhcp: Add option overload Message-ID: References: <20260518132002.418296-1-anskuma@redhat.com> <20260518132002.418296-2-anskuma@redhat.com> <20260518132002.418296-3-anskuma@redhat.com> <20260518132002.418296-4-anskuma@redhat.com> <20260518132002.418296-5-anskuma@redhat.com> <20260518132002.418296-6-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="6SGotpujEduodW5p" Content-Disposition: inline In-Reply-To: <20260518132002.418296-6-anskuma@redhat.com> Message-ID-Hash: HCBMMDOTBYDPZZK5OCMTYA3MYX7VWRQS X-Message-ID-Hash: HCBMMDOTBYDPZZK5OCMTYA3MYX7VWRQS 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: sbrivio@redhat.com, passt-dev@passt.top, lvivier@redhat.com, jmaloy@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: --6SGotpujEduodW5p Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 18, 2026 at 06:50:01PM +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 > --- > dhcp.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 78 insertions(+), 10 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index a966c34..fde5d57 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -386,13 +386,53 @@ static bool fill_one(uint8_t *buf, size_t cap, int = o, int *offset) > } > =20 > /** > - * fill() - Fill options in message > + * 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, 1 for file, > + * 2 for sname, 3 for both > + */ > +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++) { > + 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 1; Some #defined constants for the overload bits would probably be a good idea. > + } > + > + if (sname_off) { > + m->sname[sname_off] =3D 255; > + overload |=3D 2; > + } > + > + 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) > { > + size_t cap =3D OPT_MAX - 3; > int i, o, offset =3D 0; > =20 > for (o =3D 0; o < 255; o++) > @@ -403,20 +443,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, cap, 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, cap, 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, cap, o, &offset); > + } > + > + *overload =3D fill_overflow(m); > + > + if (*overload) { > + m->o[offset++] =3D 52; > + m->o[offset++] =3D 1; > + m->o[offset++] =3D *overload; If we reach this path then we've near-filled the normal option area. What guarantees we'll have space for option 52 itself? > } > =20 > m->o[offset++] =3D 255; > @@ -541,6 +586,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); > @@ -690,9 +736,31 @@ 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, sizeof(m->o) + sizeof(m->file) > + + sizeof(m->sname)); Does passing the combined length here actually make sense? IIUC each single option still needs to fit within one of the buffer areas. > + > + if (c->dhcp_boot[0]) { > + size_t boot_len =3D strlen(c->dhcp_boot); > + > + if (boot_len <=3D sizeof(opts[67].s)) { > + opts[67].slen =3D boot_len; > + memcpy(opts[67].s, c->dhcp_boot, boot_len); > + } > + } > + > + 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); > + if (!(overload & 1) && > + c->dhcp_boot[0] && strlen(c->dhcp_boot) < sizeof(reply.file)) > + memcpy(&reply.file, c->dhcp_boot, strlen(c->dhcp_boot) + 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 --6SGotpujEduodW5p Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoL/wsACgkQzQJF27ox 2Ge0dw//UD8zg5dZc/3R2e4fFIdOqzSK8XHaiHb5v2/qceXjANcZQRg03lXPYFdq unvK8aUVuBb9yccDd9FXo20InVbxezAPou/vfQcXd1uFjYLuZQKMHNVvJwXl8oTS LOwkEqlnbEhX4aYQvfS+kO7UedheuyWI4hJzMhL+0rgiGFSnVyg+5R2hC+5tqujB FkYhYOYvVHZSorb753frz+VUinOd3Oo04Ph/V/qnMBywojr9rX5guuOdvfMt4G1v D7zl9Kryb4KM5f3HVFbaqe/I/rL1XxiSRutVsPrn9aflkOhyimhw8ahsnWOrnvU9 Frz+k5tGFwDb+oYJ35/Y4xoZFzpBZvqsSy1ePslH1GvxZx1g/CEtYhHKSS5Zew+4 SPZCXQ5xVLUEcD6IoBL29RVpaRTlhI1LlZ4YlzX6hLN/mypUwN5ymdwGBPqpO7fz IxMGuC3YZREOsrKurL3f8W9eNSeGhWHLdpbcuEDkXa2/2hwHAJuz2mcwqxyeuPNr zQ5jdwVkKcOidNaP27EE+2qS39hcNHqNSXWOrbHWAk4yWnHVdhfTnS/d1b4CXfkJ Hf0oVKM/83oJrPRVQDGW8acJMmL88DySwRUXRxiiGOmbnS0bjnHNpkMGXdnVmSzx 0UE2tG6v4jIzzLbkgi4XkQHcso022RzNdouf59YQHpW24a0EHyE= =9Dv+ -----END PGP SIGNATURE----- --6SGotpujEduodW5p--