From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 662445A0278 for ; Fri, 1 Mar 2024 00:42:21 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1709250137; bh=n2ycwGcH3YGGUaF6U85x2N8GiIzuM1JdAb5dRsypdqk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=XmOKnYCLc7T5WS7GJsZVxNOkTfAeej7AhQGK2xg52J6REV70hR/kYNEa3euLJ/mBb IcnZ5A96UrtC00L0mXPQaVYCqg0n4PUQs10d94RDKCKXJy9bbKMHGX6L9mbcVszB0u yGKiO0lAp+f1Z8pMhVR70WIk6Fyx9RK0G/Kpb1DM2rMiYe7e8Fj3RFSEeogiRdewjf s5u0y7Gh3BPNU09PITigPMeoRWNnantw23woJmfSWgE0AJuLeAjXtVm2auSItN2Dod +SIl9Q74i8gHc6BdnLsHGpUjMXDfTGOsD22FFZ0hCaYHcRiaSobcvscBdZyaL/7E3H rlSo6YbJaT03Q== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4Tm76x26kLz4wcb; Fri, 1 Mar 2024 10:42:17 +1100 (AEDT) Date: Fri, 1 Mar 2024 10:16:39 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH v4 1/8] pcap: add pcap_iov() Message-ID: References: <20240229165955.829476-1-lvivier@redhat.com> <20240229165955.829476-2-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="DQiN2T0WBB3YXhfW" Content-Disposition: inline In-Reply-To: <20240229165955.829476-2-lvivier@redhat.com> Message-ID-Hash: D4R532UYEOCNSFO7M4VNUB7JN2N3BSRS X-Message-ID-Hash: D4R532UYEOCNSFO7M4VNUB7JN2N3BSRS 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: --DQiN2T0WBB3YXhfW Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Thu, Feb 29, 2024 at 05:59:48PM +0100, Laurent Vivier wrote: > Introduce a new function pcap_iov() to capture packet desribed by an IO > vector. >=20 > Update pcap_frame() to manage iovcnt > 1. Yikes. I hadn't actually realised my version only worked for iovcnt =3D=3D 1. >=20 > Signed-off-by: Laurent Vivier Reviewed-by: David Gibson > --- >=20 > Notes: > v4: > - use pcap_frame() > =20 > v3: > - update rationale > - update comment > - use strerror(errno) > - use size_t for io vector length > =20 > v2: > - introduce pcap_header(), a common helper to write > packet header > - use writev() rather than write() in a loop > - add functions comment >=20 > pcap.c | 26 ++++++++++++++++++++++---- > pcap.h | 1 + > 2 files changed, 23 insertions(+), 4 deletions(-) >=20 > diff --git a/pcap.c b/pcap.c > index a4057b5f9c6a..372f02045262 100644 > --- a/pcap.c > +++ b/pcap.c > @@ -32,6 +32,7 @@ > #include "passt.h" > #include "log.h" > #include "pcap.h" > +#include "iov.h" > =20 > #define PCAP_VERSION_MINOR 4 > =20 > @@ -78,7 +79,7 @@ struct pcap_pkthdr { > static void pcap_frame(const struct iovec *iov, size_t iovcnt, > size_t offset, const struct timeval *tv) > { > - size_t len =3D iov->iov_len - offset; > + size_t len =3D iov_size(iov, iovcnt) - offset; > struct pcap_pkthdr h =3D { > .tv_sec =3D tv->tv_sec, > .tv_usec =3D tv->tv_usec, > @@ -87,10 +88,8 @@ static void pcap_frame(const struct iovec *iov, size_t= iovcnt, > }; > struct iovec hiov =3D { &h, sizeof(h) }; > =20 > - (void)iovcnt; > - > if (write_remainder(pcap_fd, &hiov, 1, 0) < 0 || > - write_remainder(pcap_fd, iov, 1, offset) < 0) { > + write_remainder(pcap_fd, iov, iovcnt, offset) < 0) { > debug("Cannot log packet, length %zu: %s", > len, strerror(errno)); > } > @@ -135,6 +134,25 @@ void pcap_multiple(const struct iovec *iov, size_t f= rame_parts, unsigned int n, > pcap_frame(iov + i * frame_parts, frame_parts, offset, &tv); > } > =20 > +/* > + * pcap_iov - Write packet data described by an I/O vector > + * to a pcap file descriptor. > + * > + * @iov: Pointer to the array of struct iovec describing the I/O vector > + * containing packet data to write, including L2 header > + * @iovcnt: Number of buffers (@iov entries) > + */ > +void pcap_iov(const struct iovec *iov, size_t iovcnt) > +{ > + struct timeval tv; > + > + if (pcap_fd =3D=3D -1) > + return; > + > + gettimeofday(&tv, NULL); > + pcap_frame(iov, iovcnt, 0, &tv); > +} > + > /** > * pcap_init() - Initialise pcap file > * @c: Execution context > diff --git a/pcap.h b/pcap.h > index 85fc58e57572..b1c4c909c109 100644 > --- a/pcap.h > +++ b/pcap.h > @@ -9,6 +9,7 @@ > void pcap(const char *pkt, size_t len); > void pcap_multiple(const struct iovec *iov, size_t frame_parts, unsigned= int n, > size_t offset); > +void pcap_iov(const struct iovec *iov, size_t n); > void pcap_init(struct ctx *c); > =20 > #endif /* PCAP_H */ --=20 David Gibson | 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 --DQiN2T0WBB3YXhfW Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXhEFYACgkQzQJF27ox 2GfIYw/+JlWoZJXEIho0x9Js9xroO7xiw/mC5SS8BwfE9bhZkO6Kd8rvLHPvMnJr Qlv3WWRd/+DBJqMrRgBexhuuHlFYBPQm5gC3Gj4LujLQwpIgAOmGN0NQLmoCdxrc gjEHU36wG18hPFi+OCB3nBvDoKCRmMNbeqSLBXibr+hv6XVVyYy7Sr0nKQSLt2/5 xWgZ9ipJBVcUG2zYuPuz6bJ+6NbOhoxlqDm6/XZbTaxIIDQyrZhBTCDyd+y9efMq LiqTYbT1ehRuTrZMcULx8J3EGNK2FM3uTX8OhdzPiM72GbpRbGW1jHjpnNUFQQzK Dglq9Djpt/7UMYuObFXet51oTCIT+z+HP61ufpJru/hFtxLVQ4j3PlntFK2mCcCe XZVV+rYFmUfXObRqn5l3xYre/bsF1qWtToE52fea3GppoKfI+eknIp3ean+k5kSo HxNsQT0cnZlAsFNCAaU/Sf3SuMPjXK+t/eM1wbHgMjOaG/7TcCKBQ+6iZYZO3t/e jyxAsPTM6P0WiGKcPH3g+CH3tpLaWUSf5syvIm4sYB1nKLdSnCPEqe2qv1cG4N11 OOKMMxmr0e84xPX2P/6Veg6bKK7e4Moy7XJnEK+q9A4w0ohTGEVH/XEi4F6IP6qa YrwwdI+oD8X/iXTDfYCF4CBVlku4z/34y7dMe6/AsXfM0T0+e5M= =wPw1 -----END PGP SIGNATURE----- --DQiN2T0WBB3YXhfW--