diff options
author | Daniel Borkmann <dborkman@redhat.com> | 2013-06-03 23:24:18 +0200 |
---|---|---|
committer | Daniel Borkmann <dborkman@redhat.com> | 2013-06-03 23:26:45 +0200 |
commit | 3e071a78f2a5c7424340b4c8b446d51e82413c13 (patch) | |
tree | 2a411f35daeae48be99a8d325f88dcbd63bb0f2a /netsniff-ng.c | |
parent | dc5f7a04f2b446b5224be356c2fc79e88a5d3e8f (diff) |
netsniff-ng: v3: fix packet accounting on --num
We need to carry frame_count through multiple calls of walk function
to account correctly for --num <pkts>. Also, move socket stats printing
into rx ring, since it belongs there.
Todo: the kernel socket seems to have a different count that what we
see. This needs to be fixed one way or the other. Not yet sure what's
causing this.
Signed-off-by: Daniel Borkmann <dborkman@redhat.com>
Diffstat (limited to 'netsniff-ng.c')
-rw-r--r-- | netsniff-ng.c | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/netsniff-ng.c b/netsniff-ng.c index 899a148..b61dec9 100644 --- a/netsniff-ng.c +++ b/netsniff-ng.c @@ -476,7 +476,7 @@ static void receive_to_xmit(struct ctx *ctx) timer_purge(); - sock_print_net_stats(rx_sock); + sock_rx_net_stats(rx_sock); bpf_release(&bpf_ops); @@ -809,11 +809,10 @@ static void print_pcap_file_stats(int sock, struct ctx *ctx) } static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, - int sock, int fd) + int sock, int fd, unsigned long *frame_count) { uint8_t *packet; int num_pkts = pbd->h1.num_pkts, i, ret; - unsigned long frame_count = 0; struct tpacket3_hdr *hdr; pcap_pkthdr_t phdr; struct sockaddr_ll *sll; @@ -824,12 +823,13 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, for (i = 0; i < num_pkts && likely(sigint == 0); ++i) { __label__ next; packet = ((uint8_t *) hdr + hdr->tp_mac); - frame_count++; if (ctx->packet_type != -1) if (ctx->packet_type != sll->sll_pkttype) goto next; + (*frame_count)++; + if (dump_to_pcap(ctx)) { tpacket3_hdr_to_pcap_pkthdr(hdr, sll, &phdr, ctx->magic); @@ -849,7 +849,7 @@ static void walk_t3_block(struct block_desc *pbd, struct ctx *ctx, sll = (void *) ((uint8_t *) hdr + TPACKET_ALIGN(sizeof(*hdr))); if (frame_count_max != 0) { - if (frame_count >= frame_count_max) { + if (unlikely(*frame_count >= frame_count_max)) { sigint = 1; break; } @@ -885,6 +885,7 @@ static void recv_only_or_dump(struct ctx *ctx) struct sock_fprog bpf_ops; struct timeval start, end, diff; struct block_desc *pbd; + unsigned long frame_count = 0; sock = pf_socket(); @@ -967,7 +968,7 @@ static void recv_only_or_dump(struct ctx *ctx) while (likely(sigint == 0)) { while (user_may_pull_from_rx_block((pbd = (void *) rx_ring.frames[it].iov_base))) { - walk_t3_block(pbd, ctx, sock, fd); + walk_t3_block(pbd, ctx, sock, fd, &frame_count); kernel_may_pull_from_rx_block(pbd); it = (it + 1) % rx_ring.layout3.tp_block_nr; @@ -983,7 +984,7 @@ static void recv_only_or_dump(struct ctx *ctx) timersub(&end, &start, &diff); if (!(ctx->dump_dir && ctx->print_mode == PRINT_NONE)) { - sock_print_net_stats(sock); + sock_rx_net_stats(sock); printf("\r%12lu sec, %lu usec in total\n", diff.tv_sec, diff.tv_usec); |