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=WkKhgU3f; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 59F005A0262 for ; Mon, 20 Jul 2026 04:06:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202606; t=1784513214; bh=Z1h0x8dUuR7Gg7zfL2bxgIIE1n5XqOWhkM9G/pfG0wo=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=WkKhgU3fY/uek8JggX5LLr5IaTNd6NnCL6NSyVWQtsiejXXK2eSOXU66bEF5GPgjx 3sv5ezT7SW1KySQx0e8HJOvxk4ExffHIVd0eTqyIh5nr5av6f3aRc+p9jVNWFLaaRa RbhVCEqFt5Z149Z0Llz5AIz2xhFchh6jsLNfOZWVOrZzJLsIFckHRNvhNsS/yalx5D mjJWprRaJzsjHomy2PW39urt/Q/qNN0MpXQRWCAHt5NiXYjNvjM1NKlLnxK87lI/7D 0b6GW75Lt/Y7p2R2t4hOWzIBmzbAQd+FoCKw/cXYBn6duvpDH0dhmnE+Y7+z4IZlQ0 nOgiL3hGH5b9A== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4h3P5p43zkz4w2F; Mon, 20 Jul 2026 12:06:54 +1000 (AEST) Date: Mon, 20 Jul 2026 11:18:53 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v5 1/7] dhcp: Refactor fill_one() to operate on a generic buffer Message-ID: References: <20260717175648.879152-1-anskuma@redhat.com> <20260717175648.879152-2-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="kQjCRH3c79n7GYeq" Content-Disposition: inline In-Reply-To: <20260717175648.879152-2-anskuma@redhat.com> Message-ID-Hash: RXYA6PI23FJMFFSYYAKKE5QXQOIWYJL6 X-Message-ID-Hash: RXYA6PI23FJMFFSYYAKKE5QXQOIWYJL6 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: --kQjCRH3c79n7GYeq Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Jul 17, 2026 at 11:26:38PM +0530, Anshu Kumari wrote: > Change fill_one() to accept a buffer pointer and capacity instead of > a struct msg pointer. This is a pure refactor with no behavior change, > preparing for option overload support where fill_one() will also write > into the file and sname fields. >=20 > Link: https://bugs.passt.top/show_bug.cgi?id=3D192 > Signed-off-by: Anshu Kumari Reviewed-by: David Gibson > --- > v5: > - Restore debug messages for skipped options in fill() > - Add /* code and length of option */ comment in size check > - Use buf + *offset instead of &buf[*offset] for memcpy >=20 > v3: > - Restored removed comments: "If we don't have space to write the > option, then just skip" and "Move to option". >=20 > v2: > - Renamed parameter cap =E2=86=92 size. > --- > dhcp.c | 27 ++++++++++++++------------- > 1 file changed, 14 insertions(+), 13 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index c3c7422..bb72b72 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -131,28 +131,29 @@ struct msg { > } __attribute__((__packed__)); > =20 > /** > - * fill_one() - Fill a single option in message > - * @m: Message to fill > + * fill_one() - Fill a single option into a buffer > + * @buf: Buffer to write option > + * @size: Usable size of @buf (excluding end marker) > * @o: Option number > - * @offset: Current offset within options field, updated on insertion > + * @offset: Current offset within @buf, updated on insertion > * > - * Return: false if m has space to write the option, true otherwise > + * Return: false if @buf has space to write the option, true otherwise > */ > -static bool fill_one(struct msg *m, int o, int *offset) > +static bool fill_one(uint8_t *buf, size_t size, int o, int *offset) > { > size_t slen =3D opts[o].slen; > =20 > /* If we don't have space to write the option, then just skip */ > - if (*offset + 2 /* code and length of option */ + slen > OPT_MAX) > + if (*offset + 2 /* code and length of option */ + slen > size) > return true; > =20 > - m->o[*offset] =3D o; > - m->o[*offset + 1] =3D slen; > + buf[*offset] =3D o; > + buf[*offset + 1] =3D slen; > =20 > /* Move to option */ > *offset +=3D 2; > =20 > - memcpy(&m->o[*offset], opts[o].s, slen); > + memcpy(buf + *offset, opts[o].s, slen); > =20 > opts[o].sent =3D 1; > *offset +=3D slen; > @@ -177,19 +178,19 @@ 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, 53, &offset)) > - debug("DHCP: skipping option 53"); > + if (fill_one(m->o, OPT_MAX, 53, &offset)) > + debug("DHCP: skipping option 53"); > =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, &offset)) > + if (fill_one(m->o, OPT_MAX, o, &offset)) > debug("DHCP: skipping option %i", o); > } > =20 > for (o =3D 0; o < 255; o++) { > if (opts[o].slen !=3D -1 && !opts[o].sent) > - if (fill_one(m, o, &offset)) > + if (fill_one(m->o, OPT_MAX, o, &offset)) > debug("DHCP: skipping option %i", o); > } > =20 > --=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 --kQjCRH3c79n7GYeq Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmpdd3wACgkQzQJF27ox 2GdZIA//SD+vCH0pQVpono3TYrG3kJs/CpMqixFAJOC+3gW0qt4UhsDnYj8gxYNh 9MEZ2V+zQeyXLk9u8phJMpw01RBPIszZOt2klUPnA0PRJiK9xeqX+1wejizUYXcM lbeTVxSB+mpfPeNIUO/ZIwBtzGjADa2N3MMLId+Av6HNndZIa13qQMBY5IYgC2iw WGEIG7EME4yQY24lzEMGG9XZxyTuqY6zrvAVktBn39o3e5ZqVIbwxZ+BaP0KibXp u9TLmlKYQKVBprs7beXTL8x0udZyumIK6MmI2v/0QPLh2tJ+CgXr6Areav0z7Dth JunqAPXXV/eH4z78BlkuELe9FfwU/IIlwj844sqs3IkvjWDB06+9kNBXdFA1Uu5W l0xuzHWA7EOjQ4Fm2gVQ5phW8Q1O1R3nCRxbBJquEXUxbrmV1JDUFwGP/jMDELut +YXIltr4gem3CIyePTYhQS8/xW2Ta0MbWegqroenLS8GkgO84S6FfH/ICFfdWraJ o1odLWn+nvD8hRxRvA5VMBUTZjHnuG783kcU7qLa+hQp3ZOtSrcMQyDnmTFymhDT 5Td0U7W/btzzscFUIbCWOpIFfF+F/yIthvZBPzNQH88rAXkxXM9Z5Mc8oPqtkUTL L8bnxQBui+q1FQxB8U95G1sRzlkY0cChhjxZkTFZ7PHiExJh/Gg= =VJGS -----END PGP SIGNATURE----- --kQjCRH3c79n7GYeq--