diff options
author | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-06 00:54:28 +0200 |
---|---|---|
committer | Matthias Schiffer <mschiffer@universe-factory.net> | 2014-09-06 00:54:28 +0200 |
commit | 1e540bed623cb6080f1aa2b6afd39600ed25a8dd (patch) | |
tree | 19f8ff41ccf7d3c028308299431bf85e1bcbe641 | |
parent | fc250931e87ae258d7367e65b2195e359ee72738 (diff) | |
download | fastd-1e540bed623cb6080f1aa2b6afd39600ed25a8dd.tar fastd-1e540bed623cb6080f1aa2b6afd39600ed25a8dd.zip |
Don't count stats when WITH_STATUS_SOCKET is not set
-rw-r--r-- | src/fastd.h | 12 | ||||
-rw-r--r-- | src/receive.c | 3 | ||||
-rw-r--r-- | src/send.c | 16 |
3 files changed, 17 insertions, 14 deletions
diff --git a/src/fastd.h b/src/fastd.h index 6eaf831..464a7fd 100644 --- a/src/fastd.h +++ b/src/fastd.h @@ -147,8 +147,10 @@ struct fastd_socket { /** Some kind of network transfer stratistics */ struct fastd_stats { +#ifdef WITH_STATUS_SOCKET uint64_t packets; /**< The number of packets transferred */ uint64_t bytes; /**< The number of bytes transferred */ +#endif }; /** A data structure keeping track of an unknown addresses that a handshakes was received from recently */ @@ -379,6 +381,16 @@ static inline size_t fastd_max_payload(void) { } } +/** Adds statistics for a single packet of a given size */ +static inline void fastd_stats_add(fastd_stats_t *stats UNUSED, size_t stat_size UNUSED) { +#ifdef WITH_STATUS_SOCKET + if (stat_size) { + stats->packets++; + stats->bytes += stat_size; + } +#endif +} + /** Checks if a fastd_peer_address_t is an IPv6 link-local address */ static inline bool fastd_peer_address_is_v6_ll(const fastd_peer_address_t *addr) { return (addr->sa.sa_family == AF_INET6 && IN6_IS_ADDR_LINKLOCAL(&addr->in6.sin6_addr)); diff --git a/src/receive.c b/src/receive.c index ce20c4d..134564c 100644 --- a/src/receive.c +++ b/src/receive.c @@ -267,8 +267,7 @@ void fastd_handle_receive(fastd_peer_t *peer, fastd_buffer_t buffer) { fastd_peer_eth_addr_add(peer, src_addr); } - ctx.rx.packets++; - ctx.rx.bytes += buffer.len; + fastd_stats_add(&ctx.rx, buffer.len); fastd_tuntap_write(buffer); @@ -75,14 +75,6 @@ static inline void add_pktinfo(struct msghdr *msg, const fastd_peer_address_t *l } } -/** Adds statistics for a single packet of a given size */ -static inline void count_stat(fastd_stats_t *stats, size_t stat_size) { - if (stat_size) { - stats->packets++; - stats->bytes += stat_size; - } -} - /** Sends a packet of a given type */ static void send_type(const fastd_socket_t *sock, const fastd_peer_address_t *local_addr, const fastd_peer_address_t *remote_addr, fastd_peer_t *peer, uint8_t packet_type, fastd_buffer_t buffer, size_t stat_size) { if (!sock) @@ -151,23 +143,23 @@ static void send_type(const fastd_socket_t *sock, const fastd_peer_address_t *lo case EWOULDBLOCK: #endif pr_debug2_errno("sendmsg"); - count_stat(&ctx.tx_dropped, stat_size); + fastd_stats_add(&ctx.tx_dropped, stat_size); break; case ENETDOWN: case ENETUNREACH: case EHOSTUNREACH: pr_debug_errno("sendmsg"); - count_stat(&ctx.tx_error, stat_size); + fastd_stats_add(&ctx.tx_error, stat_size); break; default: pr_warn_errno("sendmsg"); - count_stat(&ctx.tx_error, stat_size); + fastd_stats_add(&ctx.tx_error, stat_size); } } else { - count_stat(&ctx.tx, stat_size); + fastd_stats_add(&ctx.tx, stat_size); } fastd_buffer_free(buffer); |