Blob Blame History Raw
From f5bf1c56b98126c4f09aabf8e4c17900a43795ea Mon Sep 17 00:00:00 2001
From: Eric Garver <egarver@redhat.com>
Date: Tue, 2 Aug 2016 15:32:00 -0400
Subject: [PATCH] netsniff-ng: Account skipped packets as 'seen' and 'dropped'

Similar to upstream da6e1d1108ad ("netsniff-ng: Account skipped packets
as 'seen' and 'dropped'")

Signed-off-by: Eric Garver <egarver@redhat.com>
---
 netsniff-ng.c | 13 ++++++++-----
 ring_rx.c     |  6 ++++--
 ring_rx.h     |  2 +-
 3 files changed, 13 insertions(+), 8 deletions(-)

diff --git a/netsniff-ng.c b/netsniff-ng.c
index 75b5ca0f7444..302a52fbc0f4 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -500,7 +500,7 @@ static void receive_to_xmit(struct ctx *ctx)
 
 	timer_purge();
 
-	sock_rx_net_stats(rx_sock, 0);
+	sock_rx_net_stats(rx_sock, 0, 0);
 
 	bpf_release(&bpf_ops);
 
@@ -832,7 +832,7 @@ static void print_pcap_file_stats(int sock, struct ctx *ctx)
 }
 
 static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
-			  int sock, int *fd, unsigned long *frame_count)
+			  int sock, int *fd, unsigned long *frame_count, unsigned long *skip_count)
 {
 	uint8_t *packet;
 	int num_pkts = pbd->h1.num_pkts, i, ret;
@@ -847,8 +847,10 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx,
 		__label__ next;
 		packet = ((uint8_t *) hdr + hdr->tp_mac);
 
-		if (skip_packet(ctx, sll))
+		if (skip_packet(ctx, sll)) {
+			(*skip_count)++;
 			goto next;
+		}
 
 		(*frame_count)++;
 
@@ -908,6 +910,7 @@ static void recv_only_or_dump(struct ctx *ctx)
 	struct timeval start, end, diff;
 	struct block_desc *pbd;
 	unsigned long frame_count = 0;
+	unsigned long skip_count = 0;
 
 	sock = pf_socket();
 
@@ -993,7 +996,7 @@ static void recv_only_or_dump(struct ctx *ctx)
 	while (likely(sigint == 0)) {
 		while (user_may_pull_from_rx_block((pbd = (void *)
 				rx_ring.frames[it].iov_base))) {
-			walk_t3_block(pbd, ctx, sock, &fd, &frame_count);
+			walk_t3_block(pbd, ctx, sock, &fd, &frame_count, &skip_count);
 
 			kernel_may_pull_from_rx_block(pbd);
 			it = (it + 1) % rx_ring.layout3.tp_block_nr;
@@ -1009,7 +1012,7 @@ static void recv_only_or_dump(struct ctx *ctx)
 	timersub(&end, &start, &diff);
 
 	if (!(ctx->dump_dir && ctx->print_mode == PRINT_NONE)) {
-		sock_rx_net_stats(sock, frame_count);
+		sock_rx_net_stats(sock, frame_count, skip_count);
 
 		printf("\r%12lu  sec, %lu usec in total\n",
 		       diff.tv_sec, diff.tv_usec);
diff --git a/ring_rx.c b/ring_rx.c
index 24a8c6d038e9..95df4bc5def5 100644
--- a/ring_rx.c
+++ b/ring_rx.c
@@ -147,7 +147,7 @@ void join_fanout_group(int sock, uint32_t fanout_group, uint32_t fanout_type)
 		panic("Cannot set fanout ring mode!\n");
 }
 
-void sock_rx_net_stats(int sock, unsigned long seen)
+void sock_rx_net_stats(int sock, unsigned long seen, unsigned long skip)
 {
 	int ret;
 	bool v3 = get_sockopt_tpacket(sock) == TPACKET_V3;
@@ -157,11 +157,13 @@ void sock_rx_net_stats(int sock, unsigned long seen)
 	} stats;
 	socklen_t slen = v3 ? sizeof(stats.k3) : sizeof(stats.k2);
 
+	seen += skip;
+
 	memset(&stats, 0, sizeof(stats));
 	ret = getsockopt(sock, SOL_PACKET, PACKET_STATISTICS, &stats, &slen);
 	if (ret > -1) {
 		uint64_t packets = stats.k3.tp_packets;
-		uint64_t drops = stats.k3.tp_drops;
+		uint64_t drops = stats.k3.tp_drops + skip;
 
 		printf("\r%12ld  packets incoming (%ld unread on exit)\n",
 		       v3 ? seen : packets, v3 ? packets - seen : 0);
diff --git a/ring_rx.h b/ring_rx.h
index 17912fd2b0e9..77fc64c79267 100644
--- a/ring_rx.h
+++ b/ring_rx.h
@@ -21,7 +21,7 @@ extern void setup_rx_ring_layout(int sock, struct ring *ring,
 				 unsigned int size, bool jumbo_support, bool v3);
 extern void join_fanout_group(int sock, uint32_t fanout_group,
                               uint32_t fanout_type);
-extern void sock_rx_net_stats(int sock, unsigned long seen);
+extern void sock_rx_net_stats(int sock, unsigned long seen, unsigned long skip);
 
 static inline int user_may_pull_from_rx(struct tpacket2_hdr *hdr)
 {
-- 
2.5.5