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=202504 header.b=hqPefuPT; dkim-atps=neutral Received: from mail.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 20A465A0008 for ; Mon, 14 Apr 2025 05:21:56 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202504; t=1744600912; bh=egejGBtSWThUNm3vS2kFOX6fYwAD6fXtW6OjHo7tqFQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=hqPefuPTKbKP2q7KYi3eJ7R/yAnSwXAzA8JvHyshOkYZpmQ1Pmr662l5A8t2hyE/j H0VfK6V7JsSV4xRE0QZcwlbeijxNAuLarsT1ByOPRElsqGjLNtdea2ksyCRKDqWMvE zSP0Mir9snhBRJtJO64UdoKjYSDPJLMgn9QHMrrEQKhzOjyWsez//yORKePj+rzUN7 No4Vk/4QU0oCwlMBKgR3KNWDsaP1jJAi0Eiexxx6XcLETBJTNdZKSXHlBFeQKfJ7uQ 3NoRg/EHaC4+1/Yfsmyn5f+Ui4T5aPTZJePxCKdWu6Llu4HkByyvciQiMlj5R0PT8v Z9EWBsNqKSmHA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4ZbXdX0W9Rz4wcd; Mon, 14 Apr 2025 13:21:52 +1000 (AEST) Date: Mon, 14 Apr 2025 13:21:45 +1000 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v2 10/20] udp: Convert to iov_tail Message-ID: References: <20250411131031.1398006-1-lvivier@redhat.com> <20250411131031.1398006-11-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="irln4umUkkczmlDj" Content-Disposition: inline In-Reply-To: <20250411131031.1398006-11-lvivier@redhat.com> Message-ID-Hash: JMNFGA5YMSGPRPDAVVNRK5YGSCVXZBSY X-Message-ID-Hash: JMNFGA5YMSGPRPDAVVNRK5YGSCVXZBSY 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: --irln4umUkkczmlDj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Apr 11, 2025 at 03:10:20PM +0200, Laurent Vivier wrote: > Use packet_base() and extract headers using IOV_REMOVE_HEADER() > and IOV_PEEK_HEADER() rather than packet_get(). >=20 > Signed-off-by: Laurent Vivier > --- > iov.c | 1 - > udp.c | 34 +++++++++++++++++++++++----------- > 2 files changed, 23 insertions(+), 12 deletions(-) >=20 > diff --git a/iov.c b/iov.c > index 9e3786e6efe8..d09e51190d54 100644 > --- a/iov.c > +++ b/iov.c > @@ -175,7 +175,6 @@ size_t iov_size(const struct iovec *iov, size_t iov_c= nt) > * iov array, a negative value if there is no enough room in the > * destination iov array > */ > -/* cppcheck-suppress unusedFunction */ > int iov_slice(struct iovec *dst_iov, size_t dst_iov_cnt, > const struct iovec *iov, size_t iov_cnt, > size_t offset, size_t *bytes) > diff --git a/udp.c b/udp.c > index ab3e9d20fd74..75526f743994 100644 > --- a/udp.c > +++ b/udp.c > @@ -862,15 +862,20 @@ int udp_tap_handler(const struct ctx *c, uint8_t pi= f, > struct iovec m[UIO_MAXIOV]; > 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; > + struct udphdr uhc; > uint8_t topif; > socklen_t sl; > =20 > ASSERT(!c->no_udp); > =20 > - uh =3D packet_get(p, idx, 0, sizeof(*uh), NULL); > + if (!packet_base(p, idx, &data)) > + return 1; > + > + uh =3D IOV_PEEK_HEADER(&data, uhc); > if (!uh) > return 1; > =20 > @@ -907,23 +912,30 @@ int udp_tap_handler(const struct ctx *c, uint8_t pi= f, > =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_base(p, idx + i, &data)) > + return p->count - idx; > + > + uh_send =3D IOV_REMOVE_HEADER(&data, uhc); > 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 len; Variables named 'len' or similar are usually byte counts, not item counts. So maybe a different name here? > + > + len =3D iov_slice(&m[j], UIO_MAXIOV - j, > + &data.iov[0], data.cnt, data.off, NULL); Might be nice to have a wrapper around iov_slice() that turns the whole of an iov_tail into a new plain iov. > + if (len < 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 len; > + j +=3D len; > } 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 --irln4umUkkczmlDj Content-Type: application/pgp-signature; name=signature.asc -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmf8f0gACgkQzQJF27ox 2GcUnQ/9FOIa8prgeLzdNuus6EXv5/KQmCRzAn8d7LZ/ayxuyBnUURRBHxRZjVnL vb07d1g1UdY9sZSTIzrbHsvgDzLL0ZcATOdAyATQL2ffB0PjNGGQO6ZDMKxLk8cD wABV4Ixw+bteJluOefbQHfIuNFkNSPhxduxzL10LePl6jdXzNBHy4zAV6PpiIm/d eZzTOLSgDDmsIGDNofhDnOAdQQ2JxM64TDghteUX4zLEkzsyPSuwvfeHvNGtBScI vK9MssCqYJTo7PFgFrV0PgKRf7qjuBga2V8WSss9Fh/9om1/PDcbpjG7vAa/+ti6 1vIfYsRI9PiJWdneP9juhmsgU/ayEte1aeZKYlzoPIwLwyBEEirNc+Nq5KLPybZk bmDiKBJVuiHk2M1HVqjpmk+tzOU31gqKlfN84xz6uYsafcaCLI9uk8Ov7jwCq9uU pG/wWZrmh7Q/kiZ/g4V0Bl4mF/yLkDBXqp8esUPbxuWe1qq4eiBIq+gEXsmMH8mD ObWxhWbPpOaKP1lbIniNSKBRnLpS7xSfLBTAvt9qPjlCqiac5ezCB8h1D5rmI9jq W19DNJanOhEvsPtk91aHNmIpRYCHFaSwOjIe50eObVZYESeEuae6JbribmfqIYoR z4Koc9cl6tJDx4YXHVbiPXnEqx/h/M+zqeGAlVZondJuKxv7VLE= =zkSn -----END PGP SIGNATURE----- --irln4umUkkczmlDj--