From: Laurent Vivier <lvivier@redhat.com>
To: passt-dev@passt.top
Cc: Laurent Vivier <lvivier@redhat.com>,
David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH v5 1/9] pcap: add pcap_iov()
Date: Sun, 3 Mar 2024 14:51:06 +0100 [thread overview]
Message-ID: <20240303135114.1023026-2-lvivier@redhat.com> (raw)
In-Reply-To: <20240303135114.1023026-1-lvivier@redhat.com>
Introduce a new function pcap_iov() to capture packet desribed by an IO
vector.
Update pcap_frame() to manage iovcnt > 1.
Signed-off-by: Laurent Vivier <lvivier@redhat.com>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
---
Notes:
v5:
- add David's R-b
v4:
- use pcap_frame()
v3:
- update rationale
- update comment
- use strerror(errno)
- use size_t for io vector length
v2:
- introduce pcap_header(), a common helper to write
packet header
- use writev() rather than write() in a loop
- add functions comment
pcap.c | 26 ++++++++++++++++++++++----
pcap.h | 1 +
2 files changed, 23 insertions(+), 4 deletions(-)
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"
#define PCAP_VERSION_MINOR 4
@@ -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 = iov->iov_len - offset;
+ size_t len = iov_size(iov, iovcnt) - offset;
struct pcap_pkthdr h = {
.tv_sec = tv->tv_sec,
.tv_usec = tv->tv_usec,
@@ -87,10 +88,8 @@ static void pcap_frame(const struct iovec *iov, size_t iovcnt,
};
struct iovec hiov = { &h, sizeof(h) };
- (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 frame_parts, unsigned int n,
pcap_frame(iov + i * frame_parts, frame_parts, offset, &tv);
}
+/*
+ * 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 == -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);
#endif /* 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);
#endif /* PCAP_H */
--
2.42.0
next prev parent reply other threads:[~2024-03-03 13:51 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-03 13:51 [PATCH v5 0/9] Add vhost-user support to passt (part 1) Laurent Vivier
2024-03-03 13:51 ` Laurent Vivier [this message]
2024-03-03 13:51 ` [PATCH v5 2/9] checksum: align buffers Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 3/9] checksum: add csum_iov() Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 4/9] util: move IP stuff from util.[ch] to ip.[ch] Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 5/9] udp: little cleanup in udp_update_hdrX() to prepare future changes Laurent Vivier
2024-03-04 0:46 ` David Gibson
2024-03-03 13:51 ` [PATCH v5 6/9] checksum: use csum_ip4_header() in udp.c and tcp.c Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 7/9] checksum: introduce functions to compute the header part checksum for TCP/UDP Laurent Vivier
2024-03-04 0:52 ` David Gibson
2024-03-03 13:51 ` [PATCH v5 8/9] tap: make tap_update_mac() generic Laurent Vivier
2024-03-03 13:51 ` [PATCH v5 9/9] tcp: Introduce ipv4_fill_headers()/ipv6_fill_headers() Laurent Vivier
2024-03-04 0:54 ` David Gibson
2024-03-05 22:12 ` [PATCH v5 0/9] Add vhost-user support to passt (part 1) Stefano Brivio
2024-03-06 3:22 ` David Gibson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240303135114.1023026-2-lvivier@redhat.com \
--to=lvivier@redhat.com \
--cc=david@gibson.dropbear.id.au \
--cc=passt-dev@passt.top \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).