From 02c1cb4ce21dca6cc63545cd5bd7ed621ed61529 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Tue, 3 Sep 2013 21:53:45 +0200 Subject: Add packet/byte statistics --- src/fastd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/fastd.c') diff --git a/src/fastd.c b/src/fastd.c index 6ce10fc..e5c1364 100644 --- a/src/fastd.c +++ b/src/fastd.c @@ -246,6 +246,9 @@ void fastd_handle_receive(fastd_context_t *ctx, fastd_peer_t *peer, fastd_buffer fastd_peer_eth_addr_add(ctx, peer, src_addr); } + ctx->rx.packets++; + ctx->rx.bytes += buffer.len; + fastd_tuntap_write(ctx, buffer); if (ctx->conf->mode == MODE_TAP && ctx->conf->forward) { @@ -360,8 +363,12 @@ static void delete_peers(fastd_context_t *ctx) { } } -static void dump_peers(fastd_context_t *ctx) { - pr_info(ctx, "dumping peers..."); +static void dump_state(fastd_context_t *ctx) { + pr_info(ctx, "TX stats: %U packet(s), %U byte(s); dropped: %U packet(s), %U byte(s); error: %U packet(s), %U byte(s)", + ctx->tx.packets, ctx->tx.bytes, ctx->tx_dropped.packets, ctx->tx_dropped.bytes, ctx->tx_error.packets, ctx->tx_error.bytes); + pr_info(ctx, "RX stats: %U packet(s), %U byte(s)", ctx->rx.packets, ctx->rx.bytes); + + pr_info(ctx, "dumping peers:"); fastd_peer_t *peer; for (peer = ctx->peers; peer; peer = peer->next) { @@ -385,7 +392,7 @@ static void dump_peers(fastd_context_t *ctx) { } } - pr_info(ctx, "peer dump finished."); + pr_info(ctx, "dump finished."); } static inline void update_time(fastd_context_t *ctx) { @@ -849,7 +856,7 @@ int main(int argc, char *argv[]) { if (dump) { dump = false; - dump_peers(&ctx); + dump_state(&ctx); } pthread_sigmask(SIG_SETMASK, &oldset, NULL); -- cgit v1.2.3