summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/fastd.h11
-rw-r--r--src/peer.c2
-rw-r--r--src/peer.h16
-rw-r--r--src/status.c31
4 files changed, 38 insertions, 22 deletions
diff --git a/src/fastd.h b/src/fastd.h
index 94c9fc7..f38b9e8 100644
--- a/src/fastd.h
+++ b/src/fastd.h
@@ -393,17 +393,6 @@ static inline size_t fastd_max_payload(void) {
}
}
-/** Adds statistics for a single packet of a given size */
-static inline void fastd_stats_add(UNUSED fastd_peer_t *peer, UNUSED fastd_stat_type_t stat, UNUSED size_t bytes) {
-#ifdef WITH_STATUS_SOCKET
- if (!bytes)
- return;
-
- ctx.stats.packets[stat]++;
- ctx.stats.bytes[stat] += bytes;
-#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/peer.c b/src/peer.c
index 30cc52f..a34283f 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -321,6 +321,8 @@ static void reset_peer(fastd_peer_t *peer) {
fastd_peer_hashtable_remove(peer);
+ memset(&peer->stats, 0, sizeof(peer->stats));
+
peer->address.sa.sa_family = AF_UNSPEC;
peer->local_address.sa.sa_family = AF_UNSPEC;
peer->state = STATE_INACTIVE;
diff --git a/src/peer.h b/src/peer.h
index ba97d2b..8c7ef88 100644
--- a/src/peer.h
+++ b/src/peer.h
@@ -72,6 +72,8 @@ struct fastd_peer {
fastd_timeout_t timeout; /**< The timeout after which the peer is reset */
fastd_timeout_t keepalive_timeout; /**< The timeout after which a keepalive is sent to the peer */
+ fastd_stats_t stats; /**< Traffic statistics */
+
const fastd_peer_group_t *group; /**< The peer group the peer belongs to */
VECTOR(fastd_remote_t) remotes; /**< The vector of the peer's remotes */
@@ -270,3 +272,17 @@ fastd_peer_t * fastd_peer_find_by_eth_addr(fastd_eth_addr_t addr);
void fastd_peer_handle_handshake_queue(void);
void fastd_peer_maintenance(void);
+
+/** Adds statistics for a single packet of a given size */
+static inline void fastd_stats_add(UNUSED fastd_peer_t *peer, UNUSED fastd_stat_type_t stat, UNUSED size_t bytes) {
+#ifdef WITH_STATUS_SOCKET
+ if (!bytes)
+ return;
+
+ ctx.stats.packets[stat]++;
+ ctx.stats.bytes[stat] += bytes;
+
+ peer->stats.packets[stat]++;
+ peer->stats.bytes[stat] += bytes;
+#endif
+}
diff --git a/src/status.c b/src/status.c
index e36c2af..0e688a5 100644
--- a/src/status.c
+++ b/src/status.c
@@ -75,8 +75,8 @@ static void * dump_thread(void *p) {
}
-/** Dumps a fastd_stats_t as a JSON object */
-static json_object * dump_stats(const fastd_stats_t *stats, fastd_stat_type_t type) {
+/** Dumps a single traffic stat as a JSON object */
+static json_object * dump_stat(const fastd_stats_t *stats, fastd_stat_type_t type) {
struct json_object *ret = json_object_new_object();
json_object_object_add(ret, "packets", json_object_new_int64(stats->packets[type]));
@@ -85,6 +85,21 @@ static json_object * dump_stats(const fastd_stats_t *stats, fastd_stat_type_t ty
return ret;
}
+/** Dumps a fastd_stats_t as a JSON object */
+static json_object * dump_stats(const fastd_stats_t *stats) {
+ struct json_object *statistics = json_object_new_object();
+
+ json_object_object_add(statistics, "rx", dump_stat(stats, STAT_RX));
+ json_object_object_add(statistics, "rx_reordered", dump_stat(stats, STAT_RX_REORDERED));
+
+ json_object_object_add(statistics, "tx", dump_stat(stats, STAT_TX));
+ json_object_object_add(statistics, "tx_dropped", dump_stat(stats, STAT_TX_DROPPED));
+ json_object_object_add(statistics, "tx_error", dump_stat(stats, STAT_TX_ERROR));
+
+ return statistics;
+}
+
+
/** Dumps a peer's status as a JSON object */
static json_object * dump_peer(const fastd_peer_t *peer) {
struct json_object *ret = json_object_new_object();
@@ -109,6 +124,8 @@ static json_object * dump_peer(const fastd_peer_t *peer) {
json_object_object_add(connection, "method", method);
+ json_object_object_add(connection, "statistics", dump_stats(&peer->stats));
+
if (conf.mode == MODE_TAP) {
struct json_object *mac_addresses = json_object_new_array();
json_object_object_add(connection, "mac_addresses", mac_addresses);
@@ -141,15 +158,7 @@ static json_object * dump_peer(const fastd_peer_t *peer) {
static void dump_status(int fd) {
struct json_object *json = json_object_new_object();
- struct json_object *statistics = json_object_new_object();
- json_object_object_add(json, "statistics", statistics);
-
- json_object_object_add(statistics, "rx", dump_stats(&ctx.stats, STAT_RX));
- json_object_object_add(statistics, "rx_reordered", dump_stats(&ctx.stats, STAT_RX_REORDERED));
-
- json_object_object_add(statistics, "tx", dump_stats(&ctx.stats, STAT_TX));
- json_object_object_add(statistics, "tx_dropped", dump_stats(&ctx.stats, STAT_TX_DROPPED));
- json_object_object_add(statistics, "tx_error", dump_stats(&ctx.stats, STAT_TX_ERROR));
+ json_object_object_add(json, "statistics", dump_stats(&ctx.stats));
struct json_object *peers = json_object_new_object();
json_object_object_add(json, "peers", peers);