Skip to content

Commit

Permalink
netsniff-ng: Account skipped packets as 'seen' and 'dropped'
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Paolo Abeni authored and tklauser committed Jul 29, 2016
1 parent 0c85ef0 commit da6e1d1
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions netsniff-ng.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -410,7 +413,7 @@ static void pcap_to_xmit(struct ctx *ctx)
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;
Expand All @@ -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;
Expand Down

0 comments on commit da6e1d1

Please sign in to comment.