The packets filtered out due to pkt_type are incoming packets
effectively dropped and should be accounted as such.
This patch explicitly accounts the skipped packets number in
skip_packet() and add such number to the 'drop' and 'seen'
counters in update_rx_stats().

Signed-off-by: Paolo Abeni <[email protected]>
---
 netsniff-ng.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/netsniff-ng.c b/netsniff-ng.c
index ab99bb1..ce37e10 100644
--- a/netsniff-ng.c
+++ b/netsniff-ng.c
@@ -66,7 +66,7 @@ struct ctx {
        uint32_t link_type, magic;
        uint32_t fanout_group, fanout_type;
        uint64_t pkts_seen, pkts_recvd, pkts_drops;
-       uint64_t pkts_recvd_last, pkts_drops_last;
+       uint64_t pkts_recvd_last, pkts_drops_last, pkts_skipd_last;
 };
 
 static volatile sig_atomic_t sigint = 0, sighup = 0;
@@ -218,10 +218,13 @@ static int update_rx_stats(struct ctx *ctx, int sock, 
bool is_v3)
        if (ret)
                return ret;
 
+       drops += ctx->pkts_skipd_last;
+       ctx->pkts_seen += ctx->pkts_skipd_last;
        ctx->pkts_recvd += packets;
        ctx->pkts_drops += drops;
        ctx->pkts_recvd_last = packets;
        ctx->pkts_drops_last = drops;
+       ctx->pkts_skipd_last = 0;
 
        return 0;
 }
@@ -410,7 +413,7 @@ out:
        printf("\r%12lu sec, %lu usec in total\n", diff.tv_sec, diff.tv_usec);
 }
 
-static inline bool skip_packet(struct ctx *ctx, struct sockaddr_ll *sll)
+static inline bool __skip_packet(struct ctx *ctx, struct sockaddr_ll *sll)
 {
        if (ctx->packet_type != -1)
                return ctx->packet_type != sll->sll_pkttype;
@@ -422,6 +425,15 @@ static inline bool skip_packet(struct ctx *ctx, struct 
sockaddr_ll *sll)
               (sll->sll_pkttype == PACKET_OUTGOING);
 }
 
+static inline bool skip_packet(struct ctx *ctx, struct sockaddr_ll *sll)
+{
+       bool skip = __skip_packet(ctx, sll);
+
+       if (skip)
+               ctx->pkts_skipd_last++;
+       return skip;
+}
+
 static void receive_to_xmit(struct ctx *ctx)
 {
        short ifflags = 0;
-- 
1.8.3.1

-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to