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=eRV4U4R+; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id CE1BA5A061B for ; Tue, 19 May 2026 08:12:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202602; t=1779171122; bh=Ld+0VJEVHhPtcQ5DC3sTH60APkeOgE0kz91C2bii4ps=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eRV4U4R+/L9QPamsNZfkYItEOwd2/SOmjjR7QKvwGz9UX5ri0NpwG7NrvTvA82Ya0 j1aTYXHZv1Hho9NUCNuZwfBzDn9wWyugC1d7sDI/zysYpKuAT/M0NUxW0A3UUoQJ9H ij12WHCKqQ3GTsmt5FEoIcLLE26ud63LprYlkz0IrUfgBVaQSf+D4kNyERVkrTihI8 so62ae46NtqsYctdbkAcIIq8aJLFoKV9iX8YeiDpRslArZ/7+GhVI+BXdjryW32mQT kHL3ks0/mIC0BuDuJGQVDIdZwp8u3GnQL40yHk73WabUbiitSU3Z+ZxTltm6ffyN40 YM3aRKfedJhTA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4gKPTG1Np5z4wT1; Tue, 19 May 2026 16:12:02 +1000 (AEST) Date: Tue, 19 May 2026 16:02:14 +1000 From: David Gibson To: Anshu Kumari Subject: Re: [PATCH 4/6] dhcp: Refactor fill_one() to operate on a generic buffer 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> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="tuz06wNGd/f+Kqx2" Content-Disposition: inline In-Reply-To: <20260518132002.418296-5-anskuma@redhat.com> Message-ID-Hash: H3ZNZGUDG3FMWAK4LLFPGTZPBB2EPJV4 X-Message-ID-Hash: H3ZNZGUDG3FMWAK4LLFPGTZPBB2EPJV4 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: --tuz06wNGd/f+Kqx2 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, May 18, 2026 at 06:50:00PM +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 Though one cosmetic flaw noted below. > --- > dhcp.c | 27 +++++++++++++-------------- > 1 file changed, 13 insertions(+), 14 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index 9220516..a966c34 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -358,28 +358,27 @@ 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 > + * @cap: Usable capacity of @buf (excluding end marker) Nit: I'd suggest "size" or "len". "cap" more commonly means "capability" in the codebase, rather than "capacity". > * @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 cap, 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 > cap) > 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; > @@ -404,19 +403,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 --tuz06wNGd/f+Kqx2 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmoL/OYACgkQzQJF27ox 2GfKRBAAgYsXwKtUS+Qw6S5el5uaC2ms/y0SEtze/wN/BewILzAZFtMFr2z4RcCm O1/dhtoWm1F/ow4mYenhH0c/5l2H2ZL/jYXAI5ejzdH3bNLc+wNYMoKS0HfH3g+R j2mTTiZ5yaqvbftRwPsui6M7GiB9E1mZGon3HlCGWJHlMbm5pkFPT1bfXoztTB5I GRcK0MtWgp3RA7cjMEAmg8ZNcQkU6L2opbKlMigqMrbCewOgOwgqZtkv2hPwGUYb Pv8JXOXEHVAL3DQo083AR6Wnen9VZU7azXNcIeYJKrgd/dLpv6jvv0lfPqNt4sxo XJ6Zls7a/ShiXBEs+Gg5uJ0OQQe2gukgk+Fl9eaQjUB3Qq2VgX9jT/u+td3ZMOug 96NvylmRXIi9WIuqAaANCcRt1cX9CEBmMg/Z+WBPOx5zeJ7vb0mxQ0+mYxQK/YyK FPJAwRWd6hMHYxKj6cuXTn9/baTmfOiKdRGIaO4u4eysTkKLDuh4Ad78GK8qrqhz yzW9VcmbDC/okE85Zr2ZVAoZg61JGqepkSZfif9RvlKwMG7ZVR2XePKKPZMORnF8 +ONiKWqleSQtskOr035xJzJtg164vxIphG29LLSAPcRak9OV4sS0q1RwS+VqDyr8 9zh0+lX6miJHfe4noNzc3zasSVoYJnEX6XOX1aUh+YnrehRxEqM= =yAVb -----END PGP SIGNATURE----- --tuz06wNGd/f+Kqx2--