napt/stats: Move some napt counters to stats module

This commit is contained in:
David Cermak
2023-09-22 23:26:56 +10:00
committed by Abhik Roy
parent a7e0a50c4d
commit b55e64aedb
6 changed files with 80 additions and 26 deletions
+2
View File
@@ -390,7 +390,9 @@ dhcp_check(struct netif *netif)
static void static void
dhcp_handle_offer(struct netif *netif, struct dhcp_msg *msg_in) dhcp_handle_offer(struct netif *netif, struct dhcp_msg *msg_in)
{ {
#if ESP_DHCP && !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER
u8_t n; u8_t n;
#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER */
struct dhcp *dhcp = netif_dhcp_data(netif); struct dhcp *dhcp = netif_dhcp_data(netif);
LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n", LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n",
+24 -17
View File
@@ -56,6 +56,7 @@
#include "lwip/lwip_napt.h" #include "lwip/lwip_napt.h"
#include "lwip/ip4_napt.h" #include "lwip/ip4_napt.h"
#include "lwip/timeouts.h" #include "lwip/timeouts.h"
#include "lwip/stats.h"
#define NO_IDX ((u16_t)-1) #define NO_IDX ((u16_t)-1)
#define NT(x) ((x) == NO_IDX ? NULL : &ip_napt_table[x]) #define NT(x) ((x) == NO_IDX ? NULL : &ip_napt_table[x])
@@ -97,7 +98,7 @@ struct ip_portmap_entry {
#endif #endif
static u16_t napt_list = NO_IDX, napt_list_last = NO_IDX, napt_free = 0; static u16_t napt_list = NO_IDX, napt_list_last = NO_IDX, napt_free = 0;
static u8_t ip_napt_max = 0; static u16_t ip_napt_max = 0;
#if IP_NAPT_PORTMAP #if IP_NAPT_PORTMAP
static uint8_t ip_portmap_max = 0; static uint8_t ip_portmap_max = 0;
#endif #endif
@@ -107,8 +108,6 @@ static struct ip_napt_entry *ip_napt_table = NULL;
static struct ip_portmap_entry *ip_portmap_table = NULL; static struct ip_portmap_entry *ip_portmap_table = NULL;
#endif #endif
static struct ip_napt_stats napt_stats;
static void ip_napt_gc(uint32_t now, bool force); static void ip_napt_gc(uint32_t now, bool force);
static void ip_napt_tmr(void *arg); static void ip_napt_tmr(void *arg);
@@ -123,10 +122,12 @@ napt_debug_print(void)
{ {
int i, next, p; int i, next, p;
u32_t now = sys_now(); u32_t now = sys_now();
u32_t nr_total = napt_stats.nr_active_tcp + napt_stats.nr_active_udp + napt_stats.nr_active_icmp; #if LWIP_STATS
u32_t nr_total = STATS_GET(ip_napt.nr_active_tcp) + STATS_GET(ip_napt.nr_active_udp) + STATS_GET(ip_napt.nr_active_icmp);
DPRINTF(("NAPT table (%"U16_F"+%"U16_F"+%"U16_F"=%"U32_F" / %"U16_F"):\n", DPRINTF(("NAPT table (%"U16_F"+%"U16_F"+%"U16_F"=%"U32_F" / %"U16_F"):\n",
napt_stats.nr_active_tcp, napt_stats.nr_active_udp, napt_stats.nr_active_icmp, nr_total, napt_stats.max_entries)); STATS_GET(ip_napt.nr_active_tcp), STATS_GET(ip_napt.nr_active_udp), STATS_GET(ip_napt.nr_active_icmp), nr_total, ip_napt_max));
if (nr_total == 0) return; if (nr_total == 0) return;
#endif
DPRINTF(("+-----------------------+-----------------------+-------+---------+----------+\n")); DPRINTF(("+-----------------------+-----------------------+-------+---------+----------+\n"));
DPRINTF(("| src | dest | mport | flags | age |\n")); DPRINTF(("| src | dest | mport | flags | age |\n"));
@@ -175,7 +176,7 @@ static void
ip_napt_deinit(void) ip_napt_deinit(void)
{ {
napt_list = NO_IDX; napt_list = NO_IDX;
napt_stats.max_entries = 0; ip_napt_max = 0;
#if IP_NAPT_PORTMAP #if IP_NAPT_PORTMAP
ip_portmap_max = 0; ip_portmap_max = 0;
#endif #endif
@@ -218,7 +219,6 @@ ip_napt_init(uint16_t max_nat, uint8_t max_portmap)
for (i = 0; i < max_nat - 1; i++) for (i = 0; i < max_nat - 1; i++)
ip_napt_table[i].next = i + 1; ip_napt_table[i].next = i + 1;
ip_napt_table[i].next = NO_IDX; ip_napt_table[i].next = NO_IDX;
napt_stats.max_entries = max_nat;
sys_timeout(NAPT_TMR_INTERVAL, ip_napt_tmr, NULL); sys_timeout(NAPT_TMR_INTERVAL, ip_napt_tmr, NULL);
} }
@@ -366,20 +366,22 @@ ip_napt_insert(struct ip_napt_entry *t)
if (napt_list_last == NO_IDX) if (napt_list_last == NO_IDX)
napt_list_last = ti; napt_list_last = ti;
#if LWIP_STATS
#if LWIP_TCP #if LWIP_TCP
if (t->proto == IP_PROTO_TCP) if (t->proto == IP_PROTO_TCP)
napt_stats.nr_active_tcp++; STATS_INC(ip_napt.nr_active_tcp);
#endif #endif
#if LWIP_UDP #if LWIP_UDP
if (t->proto == IP_PROTO_UDP) if (t->proto == IP_PROTO_UDP)
napt_stats.nr_active_udp++; STATS_INC(ip_napt.nr_active_udp);
#endif #endif
#if LWIP_ICMP #if LWIP_ICMP
if (t->proto == IP_PROTO_ICMP) if (t->proto == IP_PROTO_ICMP)
napt_stats.nr_active_icmp++; STATS_INC(ip_napt.nr_active_icmp);
#endif #endif
LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_insert(): TCP=%d, UDP=%d, ICMP=%d\n", LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_insert(): TCP=%d, UDP=%d, ICMP=%d\n",
napt_stats.nr_active_tcp, napt_stats.nr_active_udp, napt_stats.nr_active_icmp)); STATS_GET(ip_napt.nr_active_tcp), STATS_GET(ip_napt.nr_active_udp), STATS_GET(ip_napt.nr_active_icmp)));
#endif /* LWIP_STATS */
} }
static void static void
@@ -398,18 +400,21 @@ ip_napt_free(struct ip_napt_entry *t)
t->next = napt_free; t->next = napt_free;
napt_free = ti; napt_free = ti;
#if LWIP_STATS
#if LWIP_TCP #if LWIP_TCP
if (t->proto == IP_PROTO_TCP) if (t->proto == IP_PROTO_TCP)
napt_stats.nr_active_tcp--; STATS_DEC(ip_napt.nr_active_tcp);
#endif #endif
#if LWIP_UDP #if LWIP_UDP
if (t->proto == IP_PROTO_UDP) if (t->proto == IP_PROTO_UDP)
napt_stats.nr_active_udp--; STATS_DEC(ip_napt.nr_active_udp);
#endif #endif
#if LWIP_ICMP #if LWIP_ICMP
if (t->proto == IP_PROTO_ICMP) if (t->proto == IP_PROTO_ICMP)
napt_stats.nr_active_icmp--; STATS_DEC(ip_napt.nr_active_icmp);
#endif #endif
#endif /* LWIP_STATS */
LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_free\n")); LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_free\n"));
#if NAPT_DEBUG #if NAPT_DEBUG
napt_debug_print(); napt_debug_print();
@@ -1007,7 +1012,7 @@ ip_napt_gc(uint32_t now, bool force)
ip_napt_free(&ip_napt_table[oldest]); ip_napt_free(&ip_napt_table[oldest]);
evicted++; evicted++;
forced++; forced++;
napt_stats.nr_forced_evictions++; STATS_INC(ip_napt.nr_forced_evictions);
} }
LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_gc(%d): chk %d evict %d (forced %d), oldest %u\n", LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_gc(%d): chk %d evict %d (forced %d), oldest %u\n",
force, checked, evicted, forced, oldest_age)); force, checked, evicted, forced, oldest_age));
@@ -1042,10 +1047,12 @@ ip_napt_tmr(void *arg)
sys_timeout(NAPT_TMR_INTERVAL, ip_napt_tmr, arg); sys_timeout(NAPT_TMR_INTERVAL, ip_napt_tmr, arg);
} }
#if LWIP_STATS
void void
ip_napt_get_stats(struct ip_napt_stats *stats) ip_napt_get_stats(struct stats_ip_napt *stats)
{ {
*stats = napt_stats; *stats = STATS_GET(ip_napt);
} }
#endif /* LWIP_STATS */
#endif /* ESP_LWIP && LWIP_IPV4 && IP_NAPT */ #endif /* ESP_LWIP && LWIP_IPV4 && IP_NAPT */
+12
View File
@@ -139,6 +139,17 @@ stats_display_sys(struct stats_sys *sys)
} }
#endif /* SYS_STATS */ #endif /* SYS_STATS */
#if IP_NAPT_STATS
void stats_display_ip_napt(struct stats_ip_napt *napt)
{
LWIP_PLATFORM_DIAG(("\nIP NAPT\n\t"));
LWIP_PLATFORM_DIAG(("nr_active_tcp: %"STAT_COUNTER_F"\n\t", napt->nr_active_tcp));
LWIP_PLATFORM_DIAG(("nr_active_udp: %"STAT_COUNTER_F"\n\t", napt->nr_active_udp));
LWIP_PLATFORM_DIAG(("nr_active_icmp: %"STAT_COUNTER_F"\n\t", napt->nr_active_icmp));
LWIP_PLATFORM_DIAG(("nr_forced_evictions: %"STAT_COUNTER_F"\n\t", napt->nr_forced_evictions));
}
#endif /* IP_NAPT_STATS */
void void
stats_display(void) stats_display(void)
{ {
@@ -162,6 +173,7 @@ stats_display(void)
MEMP_STATS_DISPLAY(i); MEMP_STATS_DISPLAY(i);
} }
SYS_STATS_DISPLAY(); SYS_STATS_DISPLAY();
IP_NAPT_STATS_DISPLAY();
} }
#endif /* LWIP_STATS_DISPLAY */ #endif /* LWIP_STATS_DISPLAY */
+3 -9
View File
@@ -141,22 +141,16 @@ u8_t
ip_portmap_remove(u8_t proto, u16_t mport); ip_portmap_remove(u8_t proto, u16_t mport);
struct ip_napt_stats {
u16_t max_entries;
u16_t nr_active_tcp;
u16_t nr_active_udp;
u16_t nr_active_icmp;
u16_t nr_forced_evictions;
};
#if LWIP_STATS
/** /**
* Get statistics. * Get statistics.
* *
* @param stats struct to receive current stats * @param stats struct to receive current stats
*/ */
void void
ip_napt_get_stats(struct ip_napt_stats *stats); ip_napt_get_stats(struct stats_ip_napt *stats);
#endif
#endif /* IP_NAPT */ #endif /* IP_NAPT */
#endif /* IP_FORWARD */ #endif /* IP_FORWARD */
+9
View File
@@ -2252,6 +2252,14 @@
#define MIB2_STATS 0 #define MIB2_STATS 0
#endif #endif
/**
* IP_NAPT_STATS==1: Stats for IP NAPT.
*/
#if !defined IP_NAPT_STATS || defined __DOXYGEN__
#define IP_NAPT_STATS (IP_NAPT)
#endif
#else #else
#define LINK_STATS 0 #define LINK_STATS 0
@@ -2272,6 +2280,7 @@
#define MLD6_STATS 0 #define MLD6_STATS 0
#define ND6_STATS 0 #define ND6_STATS 0
#define MIB2_STATS 0 #define MIB2_STATS 0
#define IP_NAPT_STATS 0
#endif /* LWIP_STATS */ #endif /* LWIP_STATS */
/** /**
+30
View File
@@ -228,6 +228,18 @@ struct stats_mib2_netif_ctrs {
u32_t ifouterrors; u32_t ifouterrors;
}; };
#if ESP_LWIP && IP_NAPT_STATS
/**
* IP NAPT stats
*/
struct stats_ip_napt {
STAT_COUNTER nr_active_tcp;
STAT_COUNTER nr_active_udp;
STAT_COUNTER nr_active_icmp;
STAT_COUNTER nr_forced_evictions;
};
#endif /* ESP_LWIP && IP_NAPT */
/** lwIP stats container */ /** lwIP stats container */
struct stats_ { struct stats_ {
#if LINK_STATS #if LINK_STATS
@@ -298,6 +310,11 @@ struct stats_ {
/** SNMP MIB2 */ /** SNMP MIB2 */
struct stats_mib2 mib2; struct stats_mib2 mib2;
#endif #endif
#if ESP_LWIP && IP_NAPT_STATS
/** IP NAPT */
struct stats_ip_napt ip_napt;
#endif
}; };
/** Global variable containing lwIP internal statistics. Add this to your debugger's watchlist. */ /** Global variable containing lwIP internal statistics. Add this to your debugger's watchlist. */
@@ -467,6 +484,19 @@ void stats_init(void);
#define MIB2_STATS_INC(x) #define MIB2_STATS_INC(x)
#endif #endif
#if IP_NAPT_STATS
#define IP_NAPT_STATS_INC(x) STATS_INC(x)
#else
#define IP_NAPT_STATS_INC(x)
#endif
#if LWIP_STATS_DISPLAY && IP_NAPT_STATS
void stats_display_ip_napt(struct stats_ip_napt *napt);
#define IP_NAPT_STATS_DISPLAY() stats_display_ip_napt(&lwip_stats.ip_napt)
#else
#define IP_NAPT_STATS_DISPLAY()
#endif
/* Display of statistics */ /* Display of statistics */
#if LWIP_STATS_DISPLAY #if LWIP_STATS_DISPLAY
void stats_display(void); void stats_display(void);