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=NeSEr+7c; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 1A6E25A027B for ; Wed, 06 Aug 2025 04:23:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202508; t=1754447034; bh=uNBrhQm+AmKO7YVU2Pj7xqhCJrw6eYkSxvGQlgGG7zw=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=NeSEr+7cFnZFz5sCsxBIJ4Rc0RucXF0lvT+je73hVWazS4LHnaPs16eR9WujgfqS2 am560PUdjcjepESBZ83mXz1JhCqeR/SIUq8U7eTB02hLcqzL1cpMtKz4BWKxFhVXAh cLzpjAfakyctzNdIwgF9hdaEp0jWS/kj2IPkYLsXXSksXIx/Qu1JC8prnmDNiLQWel B9X1O9iB0QMdDy9GOCf4/pIenlLqE7qaEXsodwNupAxMygDElgJB27LENWt7A+Oc9t 4Tiep1X6CbdzXaFlkJnxdKoOynWdXKeGZzOmFEjG0h0gxqArW4RTOu8P+PhKxozNVs lyKjVVQ8/gwIQ== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4bxYy248Bpz4wbY; Wed, 6 Aug 2025 12:23:54 +1000 (AEST) Date: Wed, 6 Aug 2025 12:23:44 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v8 10/30] udp: Convert to iov_tail Message-ID: References: <20250805154628.301343-1-lvivier@redhat.com> <20250805154628.301343-11-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="iHVlBBbLN8QlYUUw" Content-Disposition: inline In-Reply-To: <20250805154628.301343-11-lvivier@redhat.com> Message-ID-Hash: DPOKQKIXW5WWASWUIWUEHZC34O2RVEAN X-Message-ID-Hash: DPOKQKIXW5WWASWUIWUEHZC34O2RVEAN 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: --iHVlBBbLN8QlYUUw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Tue, Aug 05, 2025 at 05:46:08PM +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 > --- > iov.c | 1 - > udp.c | 33 ++++++++++++++++++++++----------- > 2 files changed, 22 insertions(+), 12 deletions(-) >=20 > diff --git a/iov.c b/iov.c > index 9d99beb32532..f519eb3cfeaf 100644 > --- a/iov.c > +++ b/iov.c > @@ -334,7 +334,6 @@ void *iov_remove_header_(struct iov_tail *tail, void = *v, size_t len, size_t alig > * iov array, a negative value if there is not enough room in the > * destination iov array > */ > -/* cppcheck-suppress unusedFunction */ > ssize_t iov_tail_clone(struct iovec *dst_iov, size_t dst_iov_cnt, > struct iov_tail *tail) > { > diff --git a/udp.c b/udp.c > index 75edc2054d4a..3c25f2e0ae97 100644 > --- a/udp.c > +++ b/udp.c > @@ -978,9 +978,11 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, > struct mmsghdr mm[UIO_MAXIOV]; > union sockaddr_inany to_sa; > struct iovec m[UIO_MAXIOV]; > + struct udphdr uh_storage; > const struct udphdr *uh; > struct udp_flow *uflow; > - int i, s, count =3D 0; > + int i, j, s, count =3D 0; > + struct iov_tail data; > flow_sidx_t tosidx; > in_port_t src, dst; > uint8_t topif; > @@ -988,7 +990,10 @@ int udp_tap_handler(const struct ctx *c, uint8_t pif, > =20 > ASSERT(!c->no_udp); > =20 > - uh =3D packet_get(p, idx, 0, sizeof(*uh), NULL); > + if (!packet_data(p, idx, &data)) > + return 1; > + > + uh =3D IOV_PEEK_HEADER(&data, uh_storage); > if (!uh) > return 1; > =20 > @@ -1025,23 +1030,29 @@ int udp_tap_handler(const struct ctx *c, uint8_t = pif, > =20 > pif_sockaddr(c, &to_sa, &sl, topif, &toside->eaddr, toside->eport); > =20 > - for (i =3D 0; i < (int)p->count - idx; i++) { > - struct udphdr *uh_send; > - size_t len; > + for (i =3D 0, j =3D 0; i < (int)p->count - idx && j < UIO_MAXIOV; i++) { > + const struct udphdr *uh_send; > =20 > - uh_send =3D packet_get(p, idx + i, 0, sizeof(*uh), &len); > + if (!packet_data(p, idx + i, &data)) > + return p->count - idx; > + > + uh_send =3D IOV_REMOVE_HEADER(&data, uh_storage); > if (!uh_send) > return p->count - idx; > =20 > mm[i].msg_hdr.msg_name =3D &to_sa; > mm[i].msg_hdr.msg_namelen =3D sl; > =20 > - if (len) { > - m[i].iov_base =3D (char *)(uh_send + 1); > - m[i].iov_len =3D len; > + if (data.cnt) { > + int cnt; > + > + cnt =3D iov_tail_clone(&m[j], UIO_MAXIOV - j, &data); > + if (cnt < 0) > + return p->count - idx; > =20 > - mm[i].msg_hdr.msg_iov =3D m + i; > - mm[i].msg_hdr.msg_iovlen =3D 1; > + mm[i].msg_hdr.msg_iov =3D &m[j]; > + mm[i].msg_hdr.msg_iovlen =3D cnt; > + j +=3D cnt; > } else { > mm[i].msg_hdr.msg_iov =3D NULL; > mm[i].msg_hdr.msg_iovlen =3D 0; --=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 --iHVlBBbLN8QlYUUw Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCgAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmiSvKMACgkQzQJF27ox 2Gegng/9HQ0ARrx11w29DUDVsLH/AZzFBN+BJEJjdRnVKpnnzeJpOs6WBfkDnYPG hgLLTxjPQ6k1Jcx2MUJWlp6uSFnjhdV81+hzHfHs09u7s1kdqdmSDc0d2CW2qoXG oVmckejZBedMzfeRfQcn4xq0cr2IC1s8a/ZAJfWyvvh4A3Nd2srDBWtYajJ7USVp Hk6c/8VmC+LxFkqrRyuhaumsQ3azir0P282fRxGcdQiNPpjZGqmoVEVdevIW8TlJ vu6+5ohEnc9i8tejI2EFrFmn4j97cDmtcUELHWMnkr+Mtn7YxFeg9MDnSbOdvgVU OFcTfeWDfHicbXfBK4iigrEjt2cgfbh3FgmFOcDI76kt0ZH1GuuEV5DoooswRx3G PncGbMOz9eXJhFFKq4ASWX97Uo6jdC1sWPO1d1runFTuQgh4irmyZA5niPH80E7X SmHhTdD5llHOuhLmpQmlmvFbD6g+Fvt0vzoQJpmzs2VA7OSE7GnNN+uT+7dHsskz H85WaBxVEbY57C5wRFS/kbRsBLMx76QlLXGA+YSfl90FKwRtaeqHioE+vJs/tX4b zhj+Be6wRMzFJaX84GwzS01RzfNf7K7lFn1Cp29YUexHnaBGBxpCjAgkQ+jhGaEU Pntbcte9thabNe69lHNsoHWciG7zEiPfDyuS+8z6XWmvtYYvFVw= =jU+r -----END PGP SIGNATURE----- --iHVlBBbLN8QlYUUw--