--- 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)); } -- 2.48.1