From da6e1d1108ad22d68ccbff07fb569afebb265bf7 Mon Sep 17 00:00:00 2001 From: Paolo Abeni Date: Wed, 27 Jul 2016 15:59:08 +0200 Subject: netsniff-ng: Account skipped packets as 'seen' and 'dropped' The packets filtered out due to pkt_type are incoming packets effectively dropped and should be accounted as such. This patch explicitly accounts for the skipped packets number in skip_packet() and adds this number to the 'drop' and 'seen' counters in update_rx_stats(). Signed-off-by: Paolo Abeni Signed-off-by: Tobias Klauser --- 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; -- cgit v1.2.3-54-g00ecf