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=G/O5r56x; dkim-atps=neutral Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id 759575A026D for ; Tue, 02 Jun 2026 04:25:29 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1780367126; bh=y2FDYDuYpkjAUcfdONcvF91YHWL7X+45cCL1J7b/6Bc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=G/O5r56xFAcBb6+oWmfdXBpm3iZ9goSOGO/34lqbgx74gBBnC1pVuTPMjI2Mg/ozn J1nRn8GnlnEEf5rljVKYXxqJWf+q906x8hAmEp7P0XDwMFCYsFXXwH2AKpm6wfHU15 brcmrGlPXjabVgTTCUs9iqHSH1jnw6YfJwNcgmjBRo3vbHtxLcW6rqzB0LZdNnNGH1 BC/S15sgg7HLTh5iAczIGQ9tfdvTQmA4w2iY2Jldp2EC+PKQYS/1mQ+OzAQQ/6izek W0kxYJoa42BXGU6ar4oTgcNYDjyS3AoqRRSrbmZGylmG2VO1tFths1/PKgL1Ko/5ME qU/IvUR8VY+dg== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gTvnL0rvlz4wKr; Tue, 02 Jun 2026 12:25:26 +1000 (AEST) Date: Tue, 2 Jun 2026 12:25:19 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH v3 4/6] dhcp: Refactor fill_one() to operate on a generic buffer Message-ID: References: <20260601073758.1571317-1-anskuma@redhat.com> <20260601073758.1571317-5-anskuma@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="bmD7G/fEPFKlfwD/" Content-Disposition: inline In-Reply-To: <20260601073758.1571317-5-anskuma@redhat.com> Message-ID-Hash: K3IZSTTILNOWKTVJ6M4PDWP7Z2AE72F7 X-Message-ID-Hash: K3IZSTTILNOWKTVJ6M4PDWP7Z2AE72F7 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: --bmD7G/fEPFKlfwD/ Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Jun 01, 2026 at 01:07:54PM +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 > --- > 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 | 25 +++++++++++++------------ > 1 file changed, 13 insertions(+), 12 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 07a42b9..5c6a492 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -343,28 +343,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 + 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; > @@ -389,19 +390,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)) > + 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 --bmD7G/fEPFKlfwD/ Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoePw4ACgkQzQJF27ox 2Gd0ig//QQT9DB58fK+qn1s3WEWD9g6JNKuIKtBZYhj1ydo5NJV8fVA+xSV2Y530 LdN8O6s6kKuAwU4Gyx7rOAisxoAyGT96lwSsaQXSxwutdEwDVfX8piGn8VViXDKI oFH67oAk2cGle4LItJVKlf2vj6dzcbV58dyhf0MvsxBS9L7mHjJcaPPm/DlZX7B5 JjyvtX5bmQaNX3PHPwMdjUzQuGgKMeQNmR7hm9ffyynv90Ye9/H5A+shm+qIhwDI IKYYJ27x+pq8S+5kQhpGXEDDppw4Ojb1axCyyewNH5G+EknnvhO8eRHhyPjKnibV zdTCZKCfx79XITg5lPqjh82+pGSzul2mqNhRnSVUWV0ZEijJkI5wyFGMCRv0GATw Q5atLyXRDFM2uhxhCUlsfAG1k0QXoYvJXoAPU/rrnO/W737B9+fx5OrBRWwRRJe5 zF9ILcLbBO6M+uRxfs39iHcu9NfcYJmExfO31Hz1oXOUjT5fC+nAvJM0gHpS1wTe w8ZFYE2IrNEoDLFysmXYwdQLIIrjUZ2PiP2XycA6F9ezwSB7LFDa8P8/nUvBmgjX tUgP5o2Eprcjy+4Ex8M5JIj+Omkb+UHNWQf8vbK/EXVUoRtPK7NM8dN17SP2uhPX 2SddG6THa15J+xF6IF4o+WIRj8VyiAGKX9eQbBA56W/EXc/evck= =5nzT -----END PGP SIGNATURE----- --bmD7G/fEPFKlfwD/--