Blame SOURCES/0007-netsniff-ng-Account-skipped-packets-as-seen-and-drop.patch

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