diff --git a/src/core/ipv4/dhcp.c b/src/core/ipv4/dhcp.c index 1887def7..40286612 100644 --- a/src/core/ipv4/dhcp.c +++ b/src/core/ipv4/dhcp.c @@ -390,7 +390,9 @@ dhcp_check(struct netif *netif) static void dhcp_handle_offer(struct netif *netif, struct dhcp_msg *msg_in) { +#if ESP_DHCP && !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER u8_t n; +#endif /* ESP_DHCP && !ESP_DHCP_DISABLE_VENDOR_CLASS_IDENTIFIER */ struct dhcp *dhcp = netif_dhcp_data(netif); LWIP_DEBUGF(DHCP_DEBUG | LWIP_DBG_TRACE, ("dhcp_handle_offer(netif=%p) %c%c%"U16_F"\n", diff --git a/src/core/ipv4/ip4_napt.c b/src/core/ipv4/ip4_napt.c index a67bfbd9..e05eefe5 100644 --- a/src/core/ipv4/ip4_napt.c +++ b/src/core/ipv4/ip4_napt.c @@ -56,6 +56,7 @@ #include "lwip/lwip_napt.h" #include "lwip/ip4_napt.h" #include "lwip/timeouts.h" +#include "lwip/stats.h" #define NO_IDX ((u16_t)-1) #define NT(x) ((x) == NO_IDX ? NULL : &ip_napt_table[x]) @@ -97,7 +98,7 @@ struct ip_portmap_entry { #endif 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 static uint8_t ip_portmap_max = 0; #endif @@ -107,8 +108,6 @@ static struct ip_napt_entry *ip_napt_table = NULL; static struct ip_portmap_entry *ip_portmap_table = NULL; #endif -static struct ip_napt_stats napt_stats; - static void ip_napt_gc(uint32_t now, bool force); static void ip_napt_tmr(void *arg); @@ -123,10 +122,12 @@ napt_debug_print(void) { int i, next, p; 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", - 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; +#endif DPRINTF(("+-----------------------+-----------------------+-------+---------+----------+\n")); DPRINTF(("| src | dest | mport | flags | age |\n")); @@ -175,7 +176,7 @@ static void ip_napt_deinit(void) { napt_list = NO_IDX; - napt_stats.max_entries = 0; +ip_napt_max = 0; #if IP_NAPT_PORTMAP ip_portmap_max = 0; #endif @@ -218,7 +219,6 @@ ip_napt_init(uint16_t max_nat, uint8_t max_portmap) for (i = 0; i < max_nat - 1; i++) ip_napt_table[i].next = i + 1; ip_napt_table[i].next = NO_IDX; - napt_stats.max_entries = max_nat; 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) napt_list_last = ti; +#if LWIP_STATS #if LWIP_TCP if (t->proto == IP_PROTO_TCP) - napt_stats.nr_active_tcp++; + STATS_INC(ip_napt.nr_active_tcp); #endif #if LWIP_UDP if (t->proto == IP_PROTO_UDP) - napt_stats.nr_active_udp++; + STATS_INC(ip_napt.nr_active_udp); #endif #if LWIP_ICMP if (t->proto == IP_PROTO_ICMP) - napt_stats.nr_active_icmp++; + STATS_INC(ip_napt.nr_active_icmp); #endif 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 @@ -398,18 +400,21 @@ ip_napt_free(struct ip_napt_entry *t) t->next = napt_free; napt_free = ti; +#if LWIP_STATS #if LWIP_TCP if (t->proto == IP_PROTO_TCP) - napt_stats.nr_active_tcp--; + STATS_DEC(ip_napt.nr_active_tcp); #endif #if LWIP_UDP if (t->proto == IP_PROTO_UDP) - napt_stats.nr_active_udp--; + STATS_DEC(ip_napt.nr_active_udp); #endif #if LWIP_ICMP if (t->proto == IP_PROTO_ICMP) - napt_stats.nr_active_icmp--; + STATS_DEC(ip_napt.nr_active_icmp); #endif +#endif /* LWIP_STATS */ + LWIP_DEBUGF(NAPT_DEBUG, ("ip_napt_free\n")); #if NAPT_DEBUG napt_debug_print(); @@ -1007,7 +1012,7 @@ ip_napt_gc(uint32_t now, bool force) ip_napt_free(&ip_napt_table[oldest]); evicted++; 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", force, checked, evicted, forced, oldest_age)); @@ -1042,10 +1047,12 @@ ip_napt_tmr(void *arg) sys_timeout(NAPT_TMR_INTERVAL, ip_napt_tmr, arg); } +#if LWIP_STATS 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 */ diff --git a/src/core/stats.c b/src/core/stats.c index 34e9b270..d8f31e56 100644 --- a/src/core/stats.c +++ b/src/core/stats.c @@ -139,6 +139,17 @@ stats_display_sys(struct stats_sys *sys) } #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 stats_display(void) { @@ -162,6 +173,7 @@ stats_display(void) MEMP_STATS_DISPLAY(i); } SYS_STATS_DISPLAY(); + IP_NAPT_STATS_DISPLAY(); } #endif /* LWIP_STATS_DISPLAY */ diff --git a/src/include/lwip/lwip_napt.h b/src/include/lwip/lwip_napt.h index 073a3d75..a3d27955 100644 --- a/src/include/lwip/lwip_napt.h +++ b/src/include/lwip/lwip_napt.h @@ -141,22 +141,16 @@ u8_t 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. * * @param stats struct to receive current stats */ 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_FORWARD */ diff --git a/src/include/lwip/opt.h b/src/include/lwip/opt.h index 32545029..99eb4979 100644 --- a/src/include/lwip/opt.h +++ b/src/include/lwip/opt.h @@ -2252,6 +2252,14 @@ #define MIB2_STATS 0 #endif +/** + * IP_NAPT_STATS==1: Stats for IP NAPT. + */ +#if !defined IP_NAPT_STATS || defined __DOXYGEN__ +#define IP_NAPT_STATS (IP_NAPT) +#endif + + #else #define LINK_STATS 0 @@ -2272,6 +2280,7 @@ #define MLD6_STATS 0 #define ND6_STATS 0 #define MIB2_STATS 0 +#define IP_NAPT_STATS 0 #endif /* LWIP_STATS */ /** diff --git a/src/include/lwip/stats.h b/src/include/lwip/stats.h index b570dbac..94e16691 100644 --- a/src/include/lwip/stats.h +++ b/src/include/lwip/stats.h @@ -228,6 +228,18 @@ struct stats_mib2_netif_ctrs { 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 */ struct stats_ { #if LINK_STATS @@ -298,6 +310,11 @@ struct stats_ { /** SNMP MIB2 */ struct stats_mib2 mib2; #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. */ @@ -467,6 +484,19 @@ void stats_init(void); #define MIB2_STATS_INC(x) #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 */ #if LWIP_STATS_DISPLAY void stats_display(void);