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=202508 header.b=fvlsgVCR; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 65B405A0279 for ; Wed, 13 Aug 2025 05:27:09 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1755055626; bh=KArV+vFPyVuq7aJS44LuGZdHtpTOV5SnNVTghJvH5vU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=fvlsgVCR1hqofFirGUTJTcNUm39RKNuc0QbnFWO/Zxrapi4xsYfobDFbzjLluVPtk N/bKt+ukDiBpIbqe0g4nJ+67ZasbChFbJFnyPOkd8wjtTN+FDz0M/6TQOUrnvMUvM/ MbWBPLuMYqDGgDMwgyktYz2uDvV4PGh5dtXwjYhqX4hU9QK1WDFeVrjE5fvwt5M3Yc EGLypaBNQxVcqbdaaepS8O5FkYnBPXH80O56JmaWl8TSQu1i9kmQj3gMMhnJ1bvjEs XP5GVn2gPJgSMFw2dmeH0MtpOlEY+Ny3VdgJ72BBSFMkxBheJR6hJmPPUOWr6sBKbV 9DoPGQja9b+MQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4c1v1k50GGz4x6J; Wed, 13 Aug 2025 13:27:06 +1000 (AEST) Date: Wed, 13 Aug 2025 13:17:59 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v9 17/30] dhcp: Convert to iov_tail Message-ID: References: <20250808140142.3404325-1-lvivier@redhat.com> <20250808140142.3404325-18-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="pxhx4C6SjoKYQUh8" Content-Disposition: inline In-Reply-To: <20250808140142.3404325-18-lvivier@redhat.com> Message-ID-Hash: 7RSU5QAARJRW6JWDEZENAJVUFKWFJFLM X-Message-ID-Hash: 7RSU5QAARJRW6JWDEZENAJVUFKWFJFLM 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 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: --pxhx4C6SjoKYQUh8 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Aug 08, 2025 at 04:01:29PM +0200, Laurent Vivier wrote: > Use packet_data() and extract headers using IOV_REMOVE_HEADER() > and IOV_PEEK_HEADER() rather than packet_get(). >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- > dhcp.c | 46 ++++++++++++++++++++++++++++------------------ > 1 file changed, 28 insertions(+), 18 deletions(-) >=20 > diff --git a/dhcp.c b/dhcp.c > index b0de04be6f27..cf73d4b07767 100644 > --- a/dhcp.c > +++ b/dhcp.c > @@ -302,27 +302,33 @@ static void opt_set_dns_search(const struct ctx *c,= size_t max_len) > */ > int dhcp(const struct ctx *c, const struct pool *p) > { > - size_t mlen, dlen, offset =3D 0, opt_len, opt_off =3D 0; > char macstr[ETH_ADDRSTRLEN]; > + size_t mlen, dlen, opt_len; > struct in_addr mask, dst; > + struct ethhdr eh_storage; > + struct iphdr iph_storage; > + struct udphdr uh_storage; > const struct ethhdr *eh; > const struct iphdr *iph; > const struct udphdr *uh; > + struct iov_tail data; > struct msg const *m; =2E.. be nice to get rid of this weird const* in a follow up, though, I'm pretty sure it does nothing useful. > struct msg reply; > unsigned int i; > + struct msg m_storage; > =20 > - eh =3D packet_get(p, 0, offset, sizeof(*eh), NULL); > - offset +=3D sizeof(*eh); > + if (!packet_data(p, 0, &data)) > + return -1; > =20 > - iph =3D packet_get(p, 0, offset, sizeof(*iph), NULL); > + eh =3D IOV_REMOVE_HEADER(&data, eh_storage); > + iph =3D IOV_PEEK_HEADER(&data, iph_storage); > if (!eh || !iph) > return -1; > =20 > - offset +=3D iph->ihl * 4UL; > - uh =3D packet_get(p, 0, offset, sizeof(*uh), &mlen); > - offset +=3D sizeof(*uh); > + if (!iov_tail_drop(&data, iph->ihl * 4UL)) > + return -1; > =20 > + uh =3D IOV_REMOVE_HEADER(&data, uh_storage); > if (!uh) > return -1; > =20 > @@ -332,7 +338,10 @@ int dhcp(const struct ctx *c, const struct pool *p) > if (c->no_dhcp) > return 1; > =20 > - m =3D packet_get(p, 0, offset, offsetof(struct msg, o), &opt_len); > + mlen =3D iov_tail_size(&data); > + m =3D (struct msg const *)iov_remove_header_(&data, &m_storage, > + offsetof(struct msg, o), > + __alignof__(struct msg)); > if (!m || > mlen !=3D ntohs(uh->len) - sizeof(*uh) || > mlen < offsetof(struct msg, o) || > @@ -355,27 +364,28 @@ int dhcp(const struct ctx *c, const struct pool *p) > memset(&reply.file, 0, sizeof(reply.file)); > reply.magic =3D m->magic; > =20 > - offset +=3D offsetof(struct msg, o); > - > for (i =3D 0; i < ARRAY_SIZE(opts); i++) > opts[i].clen =3D -1; > =20 > - while (opt_off + 2 < opt_len) { > - const uint8_t *olen, *val; > + opt_len =3D iov_tail_size(&data); > + while (opt_len >=3D 2) { > + uint8_t olen_storage, type_storage; > + const uint8_t *olen; > uint8_t *type; > =20 > - type =3D packet_get(p, 0, offset + opt_off, 1, NULL); > - olen =3D packet_get(p, 0, offset + opt_off + 1, 1, NULL); > + type =3D IOV_REMOVE_HEADER(&data, type_storage); > + olen =3D IOV_REMOVE_HEADER(&data, olen_storage); > if (!type || !olen) > return -1; > =20 > - val =3D packet_get(p, 0, offset + opt_off + 2, *olen, NULL); > - if (!val) > + opt_len =3D iov_tail_size(&data); > + if (opt_len < *olen) > return -1; > =20 > - memcpy(&opts[*type].c, val, *olen); > + iov_to_buf(&data.iov[0], data.cnt, data.off, &opts[*type].c, *olen); > opts[*type].clen =3D *olen; > - opt_off +=3D *olen + 2; > + iov_tail_drop(&data, *olen); > + opt_len -=3D *olen; > } > =20 > opts[80].slen =3D -1; --=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 --pxhx4C6SjoKYQUh8 Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmicA+cACgkQzQJF27ox 2GfIOw/9EDxJDUaT5frYObj8hkCboDSafHmmbTMwsrc52yPYktV0wrpa0bij0pOu BfAsAicfPV34oEcwU8p2VF9wI35TZg3baGWr2WRcZFWR1UhAET6Z68k7VA6mAIut XOpxBJG3dIw3tSRDNdxFinNK2PX+/3PuRcrqTb5a0MdJuYnAFXk6eQpXI5qgA6N7 U0L6PncYxQPYW5DZrc3pFO+GYbeVCNa3PK/j/Lmh+9HGEOrdaObR4gYGyx5daKzX q8rDQnOITf4xYzWJs4mdsASHLhRxXFL9uBHO5cQKbR/QTrIgDKYRVkIdfZcFyIa5 1mFKTWVhOxx9Mkrd7zWP0fQMQa+Vs7CiL+/8nJl0/AxBddlm0WBJSdjw7QGLW+Mg L3DFcxn1H2w9NPtHM7UiBBDbKVQZzdnsOhPyxvtnrrPC83ETVcCbTX+9bGVxRx4m P2GZHNd1m3rCWeDZnXnYndvivHSSywa1u+DoCGFlkwDYReQXddcvK7yJPeCIXVae Mts1+tbfRRPS7fdovPZVFNf0y1+H4sTHzVhbOSEwNwN6O+dYJ78AtyGjkZGqihOf YpyfgP+dWVgGMvJVcxlAv3qvODlwaeRjvxXr28mWMV44iXulCvA1++qnxO8fSEd0 plAb323MD3sZcsCVhcCA6S1McWXylKTwx50OSaRhVUwOwEpEI68= =f4OH -----END PGP SIGNATURE----- --pxhx4C6SjoKYQUh8--