diff --git a/include/nuttx/net/ip.h b/include/nuttx/net/ip.h index 795ce0478b..b3a5e29dd4 100644 --- a/include/nuttx/net/ip.h +++ b/include/nuttx/net/ip.h @@ -174,6 +174,38 @@ struct ipv6_hdr_s }; #endif /* CONFIG_NET_IPv6 */ +#ifdef CONFIG_NET_STATISTICS +#ifdef CONFIG_NET_IPv6 +struct ipv4_stats_s +{ + net_stats_t drop; /* Number of dropped packets at the IP layer */ + net_stats_t recv; /* Number of received packets at the IP layer */ + net_stats_t sent; /* Number of sent packets at the IP layer */ + net_stats_t vhlerr; /* Number of packets dropped due to wrong + IP version or header length */ + net_stats_t fragerr; /* Number of packets dropped since they + were IP fragments */ + net_stats_t chkerr; /* Number of packets dropped due to IP + checksum errors */ + net_stats_t protoerr; /* Number of packets dropped since they + were neither ICMP, UDP nor TCP */ +}; +#endif /* CONFIG_NET_IPv6 */ + +#ifdef CONFIG_NET_IPv6 +struct ipv6_stats_s +{ + net_stats_t drop; /* Number of dropped packets at the IP layer */ + net_stats_t recv; /* Number of received packets at the IP layer */ + net_stats_t sent; /* Number of sent packets at the IP layer */ + net_stats_t vhlerr; /* Number of packets dropped due to wrong + IP version or header length */ + net_stats_t protoerr; /* Number of packets dropped since they + were neither ICMP, UDP nor TCP */ +}; +#endif /* CONFIG_NET_IPv6 */ +#endif /* CONFIG_NET_STATISTICS */ + /**************************************************************************** * Public Data ****************************************************************************/ diff --git a/include/nuttx/net/netstats.h b/include/nuttx/net/netstats.h index 76f428756c..3af439c965 100644 --- a/include/nuttx/net/netstats.h +++ b/include/nuttx/net/netstats.h @@ -50,6 +50,7 @@ #include +#include #ifdef CONFIG_NET_TCP # include #endif @@ -66,6 +67,8 @@ # include #endif +#ifdef CONFIG_NET_STATISTICS + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -74,33 +77,19 @@ * Public Type Definitions ****************************************************************************/ -/* The structure holding the uIP statistics that are gathered if +/* The structure holding the networking statistics that are gathered if * CONFIG_NET_STATISTICS is defined. */ -#ifdef CONFIG_NET_STATISTICS -struct ip_stats_s -{ - net_stats_t drop; /* Number of dropped packets at the IP layer */ - net_stats_t recv; /* Number of received packets at the IP layer */ - net_stats_t sent; /* Number of sent packets at the IP layer */ - net_stats_t vhlerr; /* Number of packets dropped due to wrong - IP version or header length */ - net_stats_t hblenerr; /* Number of packets dropped due to wrong - IP length, high byte */ - net_stats_t lblenerr; /* Number of packets dropped due to wrong - IP length, low byte */ - net_stats_t fragerr; /* Number of packets dropped since they - were IP fragments */ - net_stats_t chkerr; /* Number of packets dropped due to IP - checksum errors */ - net_stats_t protoerr; /* Number of packets dropped since they - were neither ICMP, UDP nor TCP */ -}; - struct net_stats_s { - struct ip_stats_s ip; /* IP statistics */ +#ifdef CONFIG_NET_IPv4 + struct ipv4_stats_s ipv4; /* IPv4 statistics */ +#endif + +#ifdef CONFIG_NET_IPv6 + struct ipv6_stats_s ipv6; /* IPv6 statistics */ +#endif #ifdef CONFIG_NET_ICMP struct icmp_stats_s icmp; /* ICMP statistics */ @@ -122,7 +111,6 @@ struct net_stats_s struct udp_stats_s udp; /* UDP statistics */ #endif }; -#endif /* CONFIG_NET_STATISTICS */ /**************************************************************************** * Public Data @@ -130,12 +118,11 @@ struct net_stats_s /* This is the structure in which the statistics are gathered. */ -#ifdef CONFIG_NET_STATISTICS extern struct net_stats_s g_netstats; -#endif /**************************************************************************** * Public Function Prototypes ****************************************************************************/ +#endif /* CONFIG_NET_STATISTICS */ #endif /* __INCLUDE_NUTTX_NET_NETSTATS_H */ diff --git a/net/devif/ipv4_input.c b/net/devif/ipv4_input.c index fcdf1efd3c..badd165464 100644 --- a/net/devif/ipv4_input.c +++ b/net/devif/ipv4_input.c @@ -321,7 +321,7 @@ int ipv4_input(FAR struct net_driver_s *dev) /* This is where the input processing starts. */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.recv++; + g_netstats.ipv4.recv++; #endif /* Start of IP input header processing code. */ @@ -332,8 +332,8 @@ int ipv4_input(FAR struct net_driver_s *dev) /* IP version and header length. */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.vhlerr++; + g_netstats.ipv4.drop++; + g_netstats.ipv4.vhlerr++; #endif nlldbg("Invalid IP version or header length: %02x\n", pbuf->vhl); goto drop; @@ -369,8 +369,8 @@ int ipv4_input(FAR struct net_driver_s *dev) } #else /* CONFIG_NET_TCP_REASSEMBLY */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.fragerr++; + g_netstats.ipv4.drop++; + g_netstats.ipv4.fragerr++; #endif nlldbg("IP fragment dropped\n"); goto drop; @@ -435,7 +435,7 @@ int ipv4_input(FAR struct net_driver_s *dev) #endif { #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; + g_netstats.ipv4.drop++; #endif goto drop; } @@ -447,8 +447,8 @@ int ipv4_input(FAR struct net_driver_s *dev) /* Compute and check the IP header checksum. */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.chkerr++; + g_netstats.ipv4.drop++; + g_netstats.ipv4.chkerr++; #endif nlldbg("Bad IP checksum\n"); goto drop; @@ -494,8 +494,8 @@ int ipv4_input(FAR struct net_driver_s *dev) default: /* Unrecognized/unsupported protocol */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.protoerr++; + g_netstats.ipv4.drop++; + g_netstats.ipv4.protoerr++; #endif nlldbg("Unrecognized IP protocol\n"); diff --git a/net/devif/ipv6_input.c b/net/devif/ipv6_input.c index a613f1975d..680a54371a 100644 --- a/net/devif/ipv6_input.c +++ b/net/devif/ipv6_input.c @@ -147,7 +147,7 @@ int ipv6_input(FAR struct net_driver_s *dev) /* This is where the input processing starts. */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.recv++; + g_netstats.ipv6.recv++; #endif /* Start of IP input header processing code. */ @@ -158,8 +158,8 @@ int ipv6_input(FAR struct net_driver_s *dev) /* IP version and header length. */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.vhlerr++; + g_netstats.ipv6.drop++; + g_netstats.ipv6.vhlerr++; #endif nlldbg("Invalid IPv6 version: %d\n", ipv6->vtc >> 4); @@ -245,7 +245,7 @@ int ipv6_input(FAR struct net_driver_s *dev) ipv6->destipaddr[0] != HTONS(0xff02)) { #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; + g_netstats.ipv6.drop++; #endif goto drop; } @@ -283,8 +283,8 @@ int ipv6_input(FAR struct net_driver_s *dev) default: /* Unrecognized/unsupported protocol */ #ifdef CONFIG_NET_STATISTICS - g_netstats.ip.drop++; - g_netstats.ip.protoerr++; + g_netstats.ipv6.drop++; + g_netstats.ipv6.protoerr++; #endif nlldbg("Unrecognized IP protocol: %04x\n", ipv6->proto); diff --git a/net/icmp/icmp_input.c b/net/icmp/icmp_input.c index ada65595fd..db39e8356d 100644 --- a/net/icmp/icmp_input.c +++ b/net/icmp/icmp_input.c @@ -173,7 +173,7 @@ void icmp_input(FAR struct net_driver_s *dev) #ifdef CONFIG_NET_STATISTICS g_netstats.icmp.sent++; - g_netstats.ip.sent++; + g_netstats.ipv4.sent++; #endif } diff --git a/net/icmp/icmp_send.c b/net/icmp/icmp_send.c index 520fb90356..e966242740 100644 --- a/net/icmp/icmp_send.c +++ b/net/icmp/icmp_send.c @@ -148,7 +148,7 @@ void icmp_send(FAR struct net_driver_s *dev, FAR in_addr_t *destaddr) #ifdef CONFIG_NET_STATISTICS g_netstats.icmp.sent++; - g_netstats.ip.sent++; + g_netstats.ipv4.sent++; #endif } } diff --git a/net/icmpv6/icmpv6_input.c b/net/icmpv6/icmpv6_input.c index db808a5ceb..99ec167833 100644 --- a/net/icmpv6/icmpv6_input.c +++ b/net/icmpv6/icmpv6_input.c @@ -326,7 +326,7 @@ void icmpv6_input(FAR struct net_driver_s *dev) #ifdef CONFIG_NET_STATISTICS g_netstats.icmpv6.sent++; - g_netstats.ip.sent++; + g_netstats.ipv6.sent++; #endif return; diff --git a/net/icmpv6/icmpv6_ping.c b/net/icmpv6/icmpv6_ping.c index f389bcca13..22dea3b694 100644 --- a/net/icmpv6/icmpv6_ping.c +++ b/net/icmpv6/icmpv6_ping.c @@ -229,7 +229,7 @@ static void icmpv6_echo_request(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_STATISTICS g_netstats.icmpv6.sent++; - g_netstats.ip.sent++; + g_netstats.ipv6.sent++; #endif } diff --git a/net/icmpv6/icmpv6_send.c b/net/icmpv6/icmpv6_send.c index 0464aa2747..1f39e76148 100644 --- a/net/icmpv6/icmpv6_send.c +++ b/net/icmpv6/icmpv6_send.c @@ -137,7 +137,7 @@ void icmpv6_send(FAR struct net_driver_s *dev, FAR net_ipv6addr_t *destaddr) #ifdef CONFIG_NET_STATISTICS g_netstats.icmpv6.sent++; - g_netstats.ip.sent++; + g_netstats.ipv6.sent++; #endif } } diff --git a/net/icmpv6/icmpv6_solicit.c b/net/icmpv6/icmpv6_solicit.c index 6e23119e02..01afa19538 100644 --- a/net/icmpv6/icmpv6_solicit.c +++ b/net/icmpv6/icmpv6_solicit.c @@ -223,7 +223,7 @@ void icmpv6_solicit(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_STATISTICS g_netstats.icmpv6.sent++; - g_netstats.ip.sent++; + g_netstats.ipv6.sent++; #endif } diff --git a/net/igmp/igmp_send.c b/net/igmp/igmp_send.c index 4ec191b5d3..ad1fe8f8e6 100644 --- a/net/igmp/igmp_send.c +++ b/net/igmp/igmp_send.c @@ -1,7 +1,7 @@ /**************************************************************************** * net/igmp/igmp_send.c * - * Copyright (C) 2010 Gregory Nutt. All rights reserved. + * Copyright (C) 2010, 2015 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -175,7 +175,7 @@ void igmp_send(FAR struct net_driver_s *dev, FAR struct igmp_group_s *group, IGMPBUF->chksum = ~igmp_chksum(&IGMPBUF->type, IPIGMP_HDRLEN); IGMP_STATINCR(g_netstats.igmp.poll_send); - IGMP_STATINCR(g_netstats.ip.sent); + IGMP_STATINCR(g_netstats.ipv4.sent); nllvdbg("Outgoing IGMP packet length: %d (%d)\n", dev->d_len, (IGMPBUF->len[0] << 8) | IGMPBUF->len[1]); diff --git a/net/tcp/tcp_send.c b/net/tcp/tcp_send.c index 4d96dc4c0a..536cf2dc44 100644 --- a/net/tcp/tcp_send.c +++ b/net/tcp/tcp_send.c @@ -176,6 +176,10 @@ static inline void tcp_ipv4_sendcomplete(FAR struct net_driver_s *dev, ipv4->ipchksum = ~ipv4_chksum(dev); nllvdbg("IPv4 length: %d\n", ((int)ipv4->len[0] << 8) + ipv4->len[1]); + +#ifdef CONFIG_NET_STATISTICS + g_netstats.ipv4.sent++; +#endif } #endif /* CONFIG_NET_IPv4 */ @@ -235,6 +239,10 @@ static inline void tcp_ipv6_sendcomplete(FAR struct net_driver_s *dev, ipv6->flow = 0x00; nllvdbg("IPv6 length: %d\n", ((int)ipv6->len[0] << 8) + ipv6->len[1]); + +#ifdef CONFIG_NET_STATISTICS + g_netstats.ipv6.sent++; +#endif } #endif /* CONFIG_NET_IPv6 */ @@ -281,7 +289,6 @@ static void tcp_sendcomplete(FAR struct net_driver_s *dev, #ifdef CONFIG_NET_STATISTICS g_netstats.tcp.sent++; - g_netstats.ip.sent++; #endif } diff --git a/net/udp/udp_send.c b/net/udp/udp_send.c index b6ef3bd762..249986bb71 100644 --- a/net/udp/udp_send.c +++ b/net/udp/udp_send.c @@ -156,6 +156,10 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) ipv4->ipchksum = 0; ipv4->ipchksum = ~ipv4_chksum(dev); + +#ifdef CONFIG_NET_STATISTICS + g_netstats.ipv4.sent++; +#endif } #endif /* CONFIG_NET_IPv4 */ @@ -198,6 +202,10 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) */ dev->d_len += IPv6_HDRLEN; + +#ifdef CONFIG_NET_STATISTICS + g_netstats.ipv6.sent++; +#endif } #endif /* CONFIG_NET_IPv6 */ @@ -239,7 +247,6 @@ void udp_send(FAR struct net_driver_s *dev, FAR struct udp_conn_s *conn) #ifdef CONFIG_NET_STATISTICS g_netstats.udp.sent++; - g_netstats.ip.sent++; #endif } }