@@ -14,6 +14,8 @@ LOG_MODULE_REGISTER(net_test, CONFIG_NET_SOCKETS_LOG_LEVEL);
1414
1515#include <zephyr/net/socket.h>
1616#include <zephyr/net/ethernet.h>
17+ #include <zephyr/net/net_mgmt.h>
18+ #include <zephyr/net/net_event.h>
1719
1820#include "ipv6.h"
1921#include "net_private.h"
@@ -1924,6 +1926,10 @@ static void test_check_ttl(int sock_c, int sock_s, int sock_p,
19241926 .tv_sec = 0 ,
19251927 .tv_usec = 100000 ,
19261928 };
1929+ #if defined(CONFIG_NET_STATISTICS )
1930+ struct net_stats_ip ipv4_stats_before , ipv4_stats_after ;
1931+ struct net_stats_ip ipv6_stats_before , ipv6_stats_after ;
1932+ #endif
19271933
19281934 Z_TEST_SKIP_IFNDEF (CONFIG_NET_INTERFACE_NAME );
19291935
@@ -2025,10 +2031,27 @@ static void test_check_ttl(int sock_c, int sock_s, int sock_p,
20252031 option == IP_TTL ? "unicast" : "multicast" ,
20262032 - errno );
20272033
2034+ #if defined(CONFIG_NET_STATISTICS )
2035+ /* Get IPv4 stats and verify they are updated for dropped
2036+ * packets.
2037+ */
2038+ net_mgmt (NET_REQUEST_STATS_GET_IPV4 , lo0 ,
2039+ & ipv4_stats_before , sizeof (ipv4_stats_before ));
2040+ #endif
20282041 ret = sendto (sock_c , & tx_buf , sizeof (tx_buf ), 0 ,
20292042 addr_sendto , addrlen_sendto );
20302043 zassert_equal (ret , sizeof (tx_buf ), "send failed (%d)" , - errno );
20312044
2045+ #if defined(CONFIG_NET_STATISTICS )
2046+ net_mgmt (NET_REQUEST_STATS_GET_IPV4 , lo0 ,
2047+ & ipv4_stats_after , sizeof (ipv4_stats_after ));
2048+
2049+ zassert_equal (ipv4_stats_before .drop + 1 ,
2050+ ipv4_stats_after .drop ,
2051+ "Dropped statistics not updated (%d vs %d)" ,
2052+ ipv4_stats_before .drop + 1 ,
2053+ ipv4_stats_after .drop );
2054+ #endif
20322055 ret = recv (sock_s , & rx_buf , sizeof (rx_buf ), 0 );
20332056 zassert_true (ret < 0 && errno == EAGAIN , "recv succeed (%d)" , - errno );
20342057 }
@@ -2052,12 +2075,30 @@ static void test_check_ttl(int sock_c, int sock_s, int sock_p,
20522075 option == IPV6_UNICAST_HOPS ? "unicast" : "multicast" ,
20532076 - errno );
20542077
2078+ #if defined(CONFIG_NET_STATISTICS )
2079+ /* Get IPv6 stats and verify they are updated for dropped
2080+ * packets.
2081+ */
2082+ net_mgmt (NET_REQUEST_STATS_GET_IPV6 , lo0 ,
2083+ & ipv6_stats_before , sizeof (ipv6_stats_before ));
2084+ #endif
20552085 ret = sendto (sock_c , & tx_buf , sizeof (tx_buf ), 0 ,
20562086 addr_sendto , addrlen_sendto );
20572087 zassert_equal (ret , sizeof (tx_buf ), "send failed (%d)" , - errno );
20582088
2089+ #if defined(CONFIG_NET_STATISTICS )
2090+ net_mgmt (NET_REQUEST_STATS_GET_IPV6 , lo0 ,
2091+ & ipv6_stats_after , sizeof (ipv6_stats_after ));
2092+
2093+ zassert_equal (ipv6_stats_before .drop + 1 ,
2094+ ipv6_stats_after .drop ,
2095+ "Dropped statistics not updated (%d vs %d)" ,
2096+ ipv6_stats_before .drop + 1 ,
2097+ ipv6_stats_after .drop );
2098+ #endif
20592099 ret = recv (sock_s , & rx_buf , sizeof (rx_buf ), 0 );
20602100 zassert_true (ret < 0 && errno == EAGAIN , "recv succeed (%d)" , - errno );
2101+
20612102 }
20622103
20632104 ret = close (sock_c );
0 commit comments