net: stats: ipv4: pmtu: Add Path MTU Discovery statistics

Add information about PMTU related packets received/sent/dropped
for IPv4.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
This commit is contained in:
Jukka Rissanen 2024-11-05 16:53:24 +02:00 committed by Anas Nashif
parent ab0ddc0bbe
commit d178eb2908
6 changed files with 92 additions and 0 deletions

View file

@ -212,6 +212,20 @@ struct net_stats_ipv6_pmtu {
net_stats_t sent; net_stats_t sent;
}; };
/**
* @brief IPv4 Path MTU Discovery statistics
*/
struct net_stats_ipv4_pmtu {
/** Number of dropped IPv4 PMTU packets. */
net_stats_t drop;
/** Number of received IPv4 PMTU packets. */
net_stats_t recv;
/** Number of sent IPv4 PMTU packets. */
net_stats_t sent;
};
/** /**
* @brief IPv6 multicast listener daemon statistics * @brief IPv6 multicast listener daemon statistics
*/ */
@ -398,6 +412,11 @@ struct net_stats {
struct net_stats_ipv6_pmtu ipv6_pmtu; struct net_stats_ipv6_pmtu ipv6_pmtu;
#endif #endif
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
/** IPv4 Path MTU Discovery statistics */
struct net_stats_ipv4_pmtu ipv4_pmtu;
#endif
#if defined(CONFIG_NET_STATISTICS_MLD) #if defined(CONFIG_NET_STATISTICS_MLD)
/** IPv6 MLD statistics */ /** IPv6 MLD statistics */
struct net_stats_ipv6_mld ipv6_mld; struct net_stats_ipv6_mld ipv6_mld;
@ -685,6 +704,7 @@ enum net_request_stats_cmd {
NET_REQUEST_STATS_CMD_GET_IPV6, NET_REQUEST_STATS_CMD_GET_IPV6,
NET_REQUEST_STATS_CMD_GET_IPV6_ND, NET_REQUEST_STATS_CMD_GET_IPV6_ND,
NET_REQUEST_STATS_CMD_GET_IPV6_PMTU, NET_REQUEST_STATS_CMD_GET_IPV6_PMTU,
NET_REQUEST_STATS_CMD_GET_IPV4_PMTU,
NET_REQUEST_STATS_CMD_GET_ICMP, NET_REQUEST_STATS_CMD_GET_ICMP,
NET_REQUEST_STATS_CMD_GET_UDP, NET_REQUEST_STATS_CMD_GET_UDP,
NET_REQUEST_STATS_CMD_GET_TCP, NET_REQUEST_STATS_CMD_GET_TCP,
@ -762,6 +782,16 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6_PMTU);
/** @endcond */ /** @endcond */
#endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */ #endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
/** Request IPv4 Path MTU Discovery statistics */
#define NET_REQUEST_STATS_GET_IPV4_PMTU \
(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV4_PMTU)
/** @cond INTERNAL_HIDDEN */
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV4_PMTU);
/** @endcond */
#endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
#if defined(CONFIG_NET_STATISTICS_ICMP) #if defined(CONFIG_NET_STATISTICS_ICMP)
/** Request ICMPv4 and ICMPv6 statistics */ /** Request ICMPv4 and ICMPv6 statistics */
#define NET_REQUEST_STATS_GET_ICMP \ #define NET_REQUEST_STATS_GET_ICMP \

View file

@ -74,6 +74,13 @@ static void print_stats(struct net_if *iface, struct net_stats *data)
GET_STAT(iface, ip_errors.chkerr), GET_STAT(iface, ip_errors.chkerr),
GET_STAT(iface, ip_errors.protoerr)); GET_STAT(iface, ip_errors.protoerr));
#if defined(CONFIG_NET_IPV4_PMTU)
printk("IPv4 PMTU recv %d\tsent\t%d\tdrop\t%d\n",
GET_STAT(iface, ipv4_pmtu.recv),
GET_STAT(iface, ipv4_pmtu.sent),
GET_STAT(iface, ipv4_pmtu.drop));
#endif /* CONFIG_NET_IPV4_PMTU */
printk("ICMP recv %d\tsent\t%d\tdrop\t%d\n", printk("ICMP recv %d\tsent\t%d\tdrop\t%d\n",
GET_STAT(iface, icmp.recv), GET_STAT(iface, icmp.recv),
GET_STAT(iface, icmp.sent), GET_STAT(iface, icmp.sent),

View file

@ -64,6 +64,13 @@ config NET_STATISTICS_IPV6_PMTU
help help
Keep track of IPv6 Path MTU Discovery related statistics Keep track of IPv6 Path MTU Discovery related statistics
config NET_STATISTICS_IPV4_PMTU
bool "IPv4 PMTU statistics"
depends on NET_IPV4_PMTU
default y
help
Keep track of IPv4 Path MTU Discovery related statistics
config NET_STATISTICS_ICMP config NET_STATISTICS_ICMP
bool "ICMP statistics" bool "ICMP statistics"
depends on NET_IPV6 || NET_IPV4 depends on NET_IPV6 || NET_IPV4

View file

@ -122,6 +122,13 @@ static inline void stats(struct net_if *iface)
GET_STAT(iface, ip_errors.chkerr), GET_STAT(iface, ip_errors.chkerr),
GET_STAT(iface, ip_errors.protoerr)); GET_STAT(iface, ip_errors.protoerr));
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
NET_INFO("IPv4 PMTU recv %d\tsent\t%d\tdrop\t%d",
GET_STAT(iface, ipv4_pmtu.recv),
GET_STAT(iface, ipv4_pmtu.sent),
GET_STAT(iface, ipv4_pmtu.drop));
#endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
NET_INFO("ICMP recv %d\tsent\t%d\tdrop\t%d", NET_INFO("ICMP recv %d\tsent\t%d\tdrop\t%d",
GET_STAT(iface, icmp.recv), GET_STAT(iface, icmp.recv),
GET_STAT(iface, icmp.sent), GET_STAT(iface, icmp.sent),
@ -291,6 +298,12 @@ static int net_stats_get(uint32_t mgmt_request, struct net_if *iface,
src = GET_STAT_ADDR(iface, ipv6_pmtu); src = GET_STAT_ADDR(iface, ipv6_pmtu);
break; break;
#endif #endif
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
case NET_REQUEST_STATS_CMD_GET_IPV4_PMTU:
len_chk = sizeof(struct net_stats_ipv4_pmtu);
src = GET_STAT_ADDR(iface, ipv4_pmtu);
break;
#endif
#if defined(CONFIG_NET_STATISTICS_ICMP) #if defined(CONFIG_NET_STATISTICS_ICMP)
case NET_REQUEST_STATS_CMD_GET_ICMP: case NET_REQUEST_STATS_CMD_GET_ICMP:
len_chk = sizeof(struct net_stats_icmp); len_chk = sizeof(struct net_stats_icmp);
@ -358,6 +371,11 @@ NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6_PMTU,
net_stats_get); net_stats_get);
#endif #endif
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV4_PMTU,
net_stats_get);
#endif
#if defined(CONFIG_NET_STATISTICS_ICMP) #if defined(CONFIG_NET_STATISTICS_ICMP)
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ICMP, NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ICMP,
net_stats_get); net_stats_get);

View file

@ -136,6 +136,29 @@ static inline void net_stats_update_ipv6_pmtu_drop(struct net_if *iface)
#define net_stats_update_ipv6_pmtu_drop(iface) #define net_stats_update_ipv6_pmtu_drop(iface)
#endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */ #endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU) && defined(CONFIG_NET_NATIVE_IPV4)
/* IPv4 Path MTU Discovery stats */
static inline void net_stats_update_ipv4_pmtu_sent(struct net_if *iface)
{
UPDATE_STAT(iface, stats.ipv4_pmtu.sent++);
}
static inline void net_stats_update_ipv4_pmtu_recv(struct net_if *iface)
{
UPDATE_STAT(iface, stats.ipv4_pmtu.recv++);
}
static inline void net_stats_update_ipv4_pmtu_drop(struct net_if *iface)
{
UPDATE_STAT(iface, stats.ipv4_pmtu.drop++);
}
#else
#define net_stats_update_ipv4_pmtu_sent(iface)
#define net_stats_update_ipv4_pmtu_recv(iface)
#define net_stats_update_ipv4_pmtu_drop(iface)
#endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
#if defined(CONFIG_NET_STATISTICS_IPV4) && defined(CONFIG_NET_NATIVE_IPV4) #if defined(CONFIG_NET_STATISTICS_IPV4) && defined(CONFIG_NET_NATIVE_IPV4)
/* IPv4 stats */ /* IPv4 stats */

View file

@ -498,6 +498,13 @@ static void net_shell_print_statistics(struct net_if *iface, void *user_data)
GET_STAT(iface, ip_errors.chkerr), GET_STAT(iface, ip_errors.chkerr),
GET_STAT(iface, ip_errors.protoerr)); GET_STAT(iface, ip_errors.protoerr));
#if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
PR("IPv4 PMTU recv %d\tsent\t%d\tdrop\t%d\n",
GET_STAT(iface, ipv4_pmtu.recv),
GET_STAT(iface, ipv4_pmtu.sent),
GET_STAT(iface, ipv4_pmtu.drop));
#endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
#if defined(CONFIG_NET_STATISTICS_ICMP) && defined(CONFIG_NET_NATIVE_IPV4) #if defined(CONFIG_NET_STATISTICS_ICMP) && defined(CONFIG_NET_NATIVE_IPV4)
PR("ICMP recv %d\tsent\t%d\tdrop\t%d\n", PR("ICMP recv %d\tsent\t%d\tdrop\t%d\n",
GET_STAT(iface, icmp.recv), GET_STAT(iface, icmp.recv),