From 8935a149e580ea91b3ef5941439f59f740f22e3a Mon Sep 17 00:00:00 2001 From: David Schweizer Date: Wed, 12 Jan 2022 12:30:59 +0100 Subject: [PATCH] ospf6d: add LSA statistics to LSA database Signed-off-by: David Schweizer --- ospf6d/ospf6_lsdb.c | 12 ++++++++++++ ospf6d/ospf6_lsdb.h | 1 + 2 files changed, 13 insertions(+) diff --git a/ospf6d/ospf6_lsdb.c b/ospf6d/ospf6_lsdb.c index 039c65d739..889ab16b11 100644 --- a/ospf6d/ospf6_lsdb.c +++ b/ospf6d/ospf6_lsdb.c @@ -92,6 +92,16 @@ static void _lsdb_count_assert(struct ospf6_lsdb *lsdb) #define ospf6_lsdb_count_assert(t) ((void) 0) #endif /*DEBUG*/ +static inline void ospf6_lsdb_stats_update(struct ospf6_lsa *lsa, + struct ospf6_lsdb *lsdb, int count) +{ + uint16_t stat = ntohs(lsa->header->type) & OSPF6_LSTYPE_FCODE_MASK; + + if (stat >= OSPF6_LSTYPE_SIZE) + stat = OSPF6_LSTYPE_UNKNOWN; + lsdb->stats[stat] += count; +} + void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb) { struct prefix_ipv6 key; @@ -112,6 +122,7 @@ void ospf6_lsdb_add(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb) if (!old) { lsdb->count++; + ospf6_lsdb_stats_update(lsa, lsdb, 1); if (OSPF6_LSA_IS_MAXAGE(lsa)) { if (lsdb->hook_remove) @@ -161,6 +172,7 @@ void ospf6_lsdb_remove(struct ospf6_lsa *lsa, struct ospf6_lsdb *lsdb) node->info = NULL; lsdb->count--; + ospf6_lsdb_stats_update(lsa, lsdb, -1); if (lsdb->hook_remove) (*lsdb->hook_remove)(lsa); diff --git a/ospf6d/ospf6_lsdb.h b/ospf6d/ospf6_lsdb.h index 9789e8c4e0..07c331af64 100644 --- a/ospf6d/ospf6_lsdb.h +++ b/ospf6d/ospf6_lsdb.h @@ -29,6 +29,7 @@ struct ospf6_lsdb { void *data; /* data structure that holds this lsdb */ struct route_table *table; uint32_t count; + uint32_t stats[OSPF6_LSTYPE_SIZE]; void (*hook_add)(struct ospf6_lsa *); void (*hook_remove)(struct ospf6_lsa *); }; -- 2.39.5