diff options
author | Paolo Abeni <pabeni@redhat.com> | 2016-07-27 15:59:08 +0200 |
---|---|---|
committer | Tobias Klauser <tklauser@distanz.ch> | 2016-07-29 10:08:02 +0200 |
commit | da6e1d1108ad22d68ccbff07fb569afebb265bf7 (patch) | |
tree | 9e5ff1b32d7dae4f3a4535ce4211a63e99b76b03 | |
parent | 0c85ef0111b36b14c53898780006d78a2727f360 (diff) |
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 <pabeni@redhat.com>
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
-rw-r--r-- | netsniff-ng.c | 16 |
1 files 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; |