public inbox for passt-dev@passt.top
 help / color / mirror / code / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: passt-dev@passt.top, Stefano Brivio <sbrivio@redhat.com>
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH 1/2] pcap comment hacks
Date: Fri,  7 Feb 2025 16:50:44 +1100	[thread overview]
Message-ID: <20250207055045.1753013-2-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <20250207055045.1753013-1-david@gibson.dropbear.id.au>

---
 pcap.c      | 20 ++++++++++++++++++++
 pcap.h      |  2 ++
 tap.c       |  1 +
 tcp_vu.c    |  6 ++++++
 vu_common.c |  1 +
 5 files changed, 30 insertions(+)

diff --git a/pcap.c b/pcap.c
index 3d623cfe..cb843033 100644
--- a/pcap.c
+++ b/pcap.c
@@ -92,6 +92,26 @@ static void pcap_frame(const struct iovec *iov, size_t iovcnt,
 		debug_perror("Cannot log packet, length %zu", l2len);
 }
 
+void pcap_comment(const char *fmt, ...)
+{
+	struct ethhdr eh = {
+		.h_proto = htons(0xffff),
+	};
+	struct timespec ts = { 0 };
+	char payload[1024];
+	struct iovec iov[] = {
+		{ &eh, sizeof(eh) },
+		{ payload, sizeof(payload) },
+	};
+	va_list ap;
+
+	va_start(ap, fmt);
+	iov[1].iov_len = vsnprintf(payload, sizeof(payload), fmt, ap);
+	va_end(ap);
+
+	pcap_frame(iov, ARRAY_SIZE(iov), 0, &ts);
+}
+
 /**
  * pcap() - Capture a single frame to pcap file
  * @pkt:	Pointer to data buffer, including L2 headers
diff --git a/pcap.h b/pcap.h
index 9795f2e8..963a4172 100644
--- a/pcap.h
+++ b/pcap.h
@@ -12,4 +12,6 @@ void pcap_multiple(const struct iovec *iov, size_t frame_parts, unsigned int n,
 void pcap_iov(const struct iovec *iov, size_t iovcnt, size_t offset);
 void pcap_init(struct ctx *c);
 
+void pcap_comment(const char *fmt, ...);
+
 #endif /* PCAP_H */
diff --git a/tap.c b/tap.c
index d0673e58..e2100878 100644
--- a/tap.c
+++ b/tap.c
@@ -972,6 +972,7 @@ void tap_add_packet(struct ctx *c, ssize_t l2len, char *p)
 {
 	const struct ethhdr *eh;
 
+	pcap_comment("tap_add_packet()");
 	pcap(p, l2len);
 
 	eh = (struct ethhdr *)p;
diff --git a/tcp_vu.c b/tcp_vu.c
index fad7065e..6f00770b 100644
--- a/tcp_vu.c
+++ b/tcp_vu.c
@@ -140,6 +140,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
 			 NULL, seq, !*c->pcap);
 
 	if (*c->pcap) {
+		pcap_comment("tcp_vu_send_flag()");
 		pcap_iov(&flags_elem[0].in_sg[0], 1,
 			 sizeof(struct virtio_net_hdr_mrg_rxbuf));
 	}
@@ -159,6 +160,7 @@ int tcp_vu_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
 			nb_ack++;
 
 			if (*c->pcap) {
+				pcap_comment("tcp_vu_send_flag() dup_ack");
 				pcap_iov(&flags_elem[1].in_sg[0], 1,
 					 sizeof(struct virtio_net_hdr_mrg_rxbuf));
 			}
@@ -247,6 +249,8 @@ static ssize_t tcp_vu_sock_recv(const struct ctx *c,
 		return -errno;
 	}
 
+	pcap_comment("received %zd", ret);
+
 	if (!peek_offset_cap)
 		ret -= already_sent;
 
@@ -457,6 +461,8 @@ int tcp_vu_data_from_sock(const struct ctx *c, struct tcp_tap_conn *conn)
 		tcp_vu_prepare(c, conn, iov, buf_cnt, &check, !*c->pcap, push);
 
 		if (*c->pcap) {
+			pcap_comment("tcp_vu_data_from_sock() i=%d, head_cnt=%d, len=%zd, iov_cnt=%d",
+				     i, head_cnt, len, iov_cnt);
 			pcap_iov(iov, buf_cnt,
 				 sizeof(struct virtio_net_hdr_mrg_rxbuf));
 		}
diff --git a/vu_common.c b/vu_common.c
index 48826b13..5ad619e8 100644
--- a/vu_common.c
+++ b/vu_common.c
@@ -290,6 +290,7 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size)
 		     buf, total);
 
 	if (*c->pcap) {
+		pcap_comment("vu_send_single()");
 		pcap_iov(in_sg, elem_cnt,
 			 sizeof(struct virtio_net_hdr_mrg_rxbuf));
 	}
-- 
@@ -290,6 +290,7 @@ int vu_send_single(const struct ctx *c, const void *buf, size_t size)
 		     buf, total);
 
 	if (*c->pcap) {
+		pcap_comment("vu_send_single()");
 		pcap_iov(in_sg, elem_cnt,
 			 sizeof(struct virtio_net_hdr_mrg_rxbuf));
 	}
-- 
2.48.1


  reply	other threads:[~2025-02-07  5:50 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-07  5:50 [PATCH 0/2] Migration debugging hacks David Gibson
2025-02-07  5:50 ` David Gibson [this message]
2025-02-07  5:50 ` [PATCH 2/2] debug 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=20250207055045.1753013-2-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=passt-dev@passt.top \
    --cc=sbrivio@redhat.com \
    /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).