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 266255A0272 for ; Mon, 5 Feb 2024 07:26:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707114369; bh=lOY+7GUM6iPuRjpKPIExbyGMXmQuis3pVliWvXODlCM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=PdS4KMsZNeBIFTjUOB5UjDZFuVu7sdDbhYqHpWV2q7miDAoUp9FV93Ao2/4DyrHow XDXQixQHsYZNOpiveZUN4kgjXkqTyCxaU0yihdkx097iHAb6OilwUhOOhOP4X0RcAr B54fguDgB4+WbEUrUrY+s8jsZ2vZiDUnFMNtaft0nbeEpxw3+Hl6fuk7ffkT4cTZyO Vpts4r5dATeboQFTOIXbMfZjn0a9qkLkOfAkTBzfj+BwbjJNO3tm3Y3ZTu8h7i4qwV 1EbuJyJROpgeH0Y5uo7LAQFdvMA4HHRtWBwT0/gWvvE4Y3PDFXd7LInd9BKVH1J2H4 ZO0Sp3VzPU4Ag== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TSxGT1Wydz4wxx; Mon, 5 Feb 2024 17:26:09 +1100 (AEDT) Date: Mon, 5 Feb 2024 17:25:21 +1100 From: David Gibson To: Laurent Vivier Subject: Re: [PATCH 02/24] pcap: add pcap_iov() Message-ID: References: <20240202141151.3762941-1-lvivier@redhat.com> <20240202141151.3762941-3-lvivier@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="KvcPu9gI4h5xPGxB" Content-Disposition: inline In-Reply-To: <20240202141151.3762941-3-lvivier@redhat.com> Message-ID-Hash: 6SK5XUHZ33H3MBFWKYJEVOOHSRA4ZZFM X-Message-ID-Hash: 6SK5XUHZ33H3MBFWKYJEVOOHSRA4ZZFM 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: --KvcPu9gI4h5xPGxB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Fri, Feb 02, 2024 at 03:11:29PM +0100, Laurent Vivier wrote: > Signed-off-by: Laurent Vivier > --- > pcap.c | 32 ++++++++++++++++++++++++++++++++ > pcap.h | 1 + > 2 files changed, 33 insertions(+) >=20 > diff --git a/pcap.c b/pcap.c > index 501d52d4992b..b002bb01314c 100644 > --- a/pcap.c > +++ b/pcap.c > @@ -31,6 +31,7 @@ > #include "util.h" > #include "passt.h" > #include "log.h" > +#include "iov.h" > =20 > #define PCAP_VERSION_MINOR 4 > =20 > @@ -130,6 +131,37 @@ void pcap_multiple(const struct iovec *iov, unsigned= int n, size_t offset) > } > } Function comment. > +void pcap_iov(const struct iovec *iov, unsigned int n) > +{ > + struct timeval tv; > + struct pcap_pkthdr h; > + size_t len; > + unsigned int i; > + > + if (pcap_fd =3D=3D -1) > + return; > + > + gettimeofday(&tv, NULL); > + > + len =3D iov_size(iov, n); > + > + h.tv_sec =3D tv.tv_sec; > + h.tv_usec =3D tv.tv_usec; > + h.caplen =3D h.len =3D len; > + > + if (write(pcap_fd, &h, sizeof(h)) < 0) { > + debug("Cannot write pcap header"); > + return; > + } It would be nice to have a common helper for writing the header used by pcap_iov() and pcap_frame(). > + for (i =3D 0; i < n; i++) { > + if (write(pcap_fd, iov[i].iov_base, iov[i].iov_len) < 0) { You should be able to avoid the loop by using writev() no? Although, both here and the existing code we should, technically, be looping on short write()s to make sure we've written everything. That's more awkward with an iov. > + debug("Cannot log packet, iov %d length %lu\n", > + i, iov[i].iov_len); > + } > + } > +} > + > /** > * pcap_init() - Initialise pcap file > * @c: Execution context > diff --git a/pcap.h b/pcap.h > index da5a7e846b72..732a0ddf14cc 100644 > --- a/pcap.h > +++ b/pcap.h > @@ -8,6 +8,7 @@ > =20 > void pcap(const char *pkt, size_t len); > void pcap_multiple(const struct iovec *iov, unsigned int n, size_t offse= t); > +void pcap_iov(const struct iovec *iov, unsigned int 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 --KvcPu9gI4h5xPGxB Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEO+dNsU4E3yXUXRK2zQJF27ox2GcFAmXAf1AACgkQzQJF27ox 2GfuiBAAjs7MPJohi6wbIF4VZSRIbFbbO+S13uHIMhvObVKk2EH/WhbWOOcD41bQ RfdXTl0gXkYV1qXEMJXS1WMP8yPb7+8Ykb9MRA2k93XcVHwjvyYOJT3Zk7GOQkg7 Bkdfo5TO5xXnL7fL9QEU0mmqODOylkswBVk0vmfRZeNABtQuTAW7Zj2YMTSL5IZh rEu29UL8IGLUNc3ESj/lMuvlK/8dOsOTYk1EXlt0sYUrpudd+5vvkCJ+fjDurh6e Ex6elxdcOEr7tiyQ4/j2aoTb/c1fn4by6xoHNxHQtA85c7K/czJd7y8XoPsMbn0v xtS4LPvZ5XTGDYxpaZBsBke3jb9YnekzREhEg+vgyqlM8TAIF6eHImw1lHwPNtno bM487xBDVA/AnllcLvc+cWN3h0C3QJyAaM8PJj/dwdmtJYxTA896eFjq94W+iCjM l6BMppYi3oYHnL9d48fH0QA1aur0EbRkcEgmHivPYixmYrYVlysJ0cYSpDXDG8pC KY0stFw1l4aZu+WjuOoUmhO5gmvu3m1wsDJCayUaeqNmIuybJNAzHklX+NVQmZSy ZW8L/4pRRGSQmvnY9dL2Ijqa3qMfd+BisRuC3iA9bDZvd0kgbxVN/lAZNNwdajcN NzBcc/2MOj82ddMpHCj5ziJeVBpV5S6y/BtiaLu2F5YfXMgR+yk= =IWa9 -----END PGP SIGNATURE----- --KvcPu9gI4h5xPGxB--