1 /** @file
2  * @brief Network statistics
3  *
4  * Network statistics data. This should only be enabled when
5  * debugging as it consumes memory.
6  */
7 
8 /*
9  * Copyright (c) 2016 Intel Corporation
10  *
11  * SPDX-License-Identifier: Apache-2.0
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_NET_NET_STATS_H_
15 #define ZEPHYR_INCLUDE_NET_NET_STATS_H_
16 
17 #include <zephyr/types.h>
18 #include <zephyr/net/net_core.h>
19 #include <zephyr/net/net_mgmt.h>
20 
21 #include <zephyr/net/prometheus/collector.h>
22 #include <zephyr/net/prometheus/counter.h>
23 #include <zephyr/net/prometheus/metric.h>
24 #include <zephyr/net/prometheus/gauge.h>
25 #include <zephyr/net/prometheus/histogram.h>
26 #include <zephyr/net/prometheus/summary.h>
27 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 /**
33  * @brief Network statistics library
34  * @defgroup net_stats Network Statistics Library
35  * @since 1.5
36  * @version 0.8.0
37  * @ingroup networking
38  * @{
39  */
40 
41 /**
42  * @typedef net_stats_t
43  * @brief Network statistics counter
44  */
45 typedef uint32_t net_stats_t;
46 
47 /**
48  * @brief Number of bytes sent and received.
49  */
50 struct net_stats_bytes {
51 	/** Number of bytes sent */
52 	net_stats_t sent;
53 	/** Number of bytes received */
54 	net_stats_t received;
55 };
56 
57 /**
58  * @brief Number of network packets sent and received.
59  */
60 struct net_stats_pkts {
61 	/** Number of packets sent */
62 	net_stats_t tx;
63 	/** Number of packets received */
64 	net_stats_t rx;
65 };
66 
67 /**
68  * @brief IP layer statistics
69  */
70 struct net_stats_ip {
71 	/** Number of received packets at the IP layer. */
72 	net_stats_t recv;
73 
74 	/** Number of sent packets at the IP layer. */
75 	net_stats_t sent;
76 
77 	/** Number of forwarded packets at the IP layer. */
78 	net_stats_t forwarded;
79 
80 	/** Number of dropped packets at the IP layer. */
81 	net_stats_t drop;
82 };
83 
84 /**
85  * @brief IP layer error statistics
86  */
87 struct net_stats_ip_errors {
88 	/** Number of packets dropped due to wrong IP version
89 	 * or header length.
90 	 */
91 	net_stats_t vhlerr;
92 
93 	 /** Number of packets dropped due to wrong IP length, high byte. */
94 	net_stats_t hblenerr;
95 
96 	/** Number of packets dropped due to wrong IP length, low byte. */
97 	net_stats_t lblenerr;
98 
99 	/** Number of packets dropped because they were IP fragments. */
100 	net_stats_t fragerr;
101 
102 	/** Number of packets dropped due to IP checksum errors. */
103 	net_stats_t chkerr;
104 
105 	/** Number of packets dropped because they were neither ICMP,
106 	 * UDP nor TCP.
107 	 */
108 	net_stats_t protoerr;
109 };
110 
111 /**
112  * @brief ICMP statistics
113  */
114 struct net_stats_icmp {
115 	/** Number of received ICMP packets. */
116 	net_stats_t recv;
117 
118 	/** Number of sent ICMP packets. */
119 	net_stats_t sent;
120 
121 	/** Number of dropped ICMP packets. */
122 	net_stats_t drop;
123 
124 	/** Number of ICMP packets with a wrong type. */
125 	net_stats_t typeerr;
126 
127 	/** Number of ICMP packets with a bad checksum. */
128 	net_stats_t chkerr;
129 };
130 
131 /**
132  * @brief TCP statistics
133  */
134 struct net_stats_tcp {
135 	/** Amount of received and sent TCP application data. */
136 	struct net_stats_bytes bytes;
137 
138 	/** Amount of retransmitted data. */
139 	net_stats_t resent;
140 
141 	/** Number of dropped packets at the TCP layer. */
142 	net_stats_t drop;
143 
144 	/** Number of received TCP segments. */
145 	net_stats_t recv;
146 
147 	/** Number of sent TCP segments. */
148 	net_stats_t sent;
149 
150 	/** Number of dropped TCP segments. */
151 	net_stats_t seg_drop;
152 
153 	/** Number of TCP segments with a bad checksum. */
154 	net_stats_t chkerr;
155 
156 	/** Number of received TCP segments with a bad ACK number. */
157 	net_stats_t ackerr;
158 
159 	/** Number of received bad TCP RST (reset) segments. */
160 	net_stats_t rsterr;
161 
162 	/** Number of received TCP RST (reset) segments. */
163 	net_stats_t rst;
164 
165 	/** Number of retransmitted TCP segments. */
166 	net_stats_t rexmit;
167 
168 	/** Number of dropped connection attempts because too few connections
169 	 * were available.
170 	 */
171 	net_stats_t conndrop;
172 
173 	/** Number of connection attempts for closed ports, triggering a RST. */
174 	net_stats_t connrst;
175 };
176 
177 /**
178  * @brief UDP statistics
179  */
180 struct net_stats_udp {
181 	/** Number of dropped UDP segments. */
182 	net_stats_t drop;
183 
184 	/** Number of received UDP segments. */
185 	net_stats_t recv;
186 
187 	/** Number of sent UDP segments. */
188 	net_stats_t sent;
189 
190 	/** Number of UDP segments with a bad checksum. */
191 	net_stats_t chkerr;
192 };
193 
194 /**
195  * @brief IPv6 neighbor discovery statistics
196  */
197 struct net_stats_ipv6_nd {
198 	/** Number of dropped IPv6 neighbor discovery packets. */
199 	net_stats_t drop;
200 
201 	/** Number of received IPv6 neighbor discovery packets. */
202 	net_stats_t recv;
203 
204 	/** Number of sent IPv6 neighbor discovery packets. */
205 	net_stats_t sent;
206 };
207 
208 /**
209  * @brief IPv6 Path MTU Discovery statistics
210  */
211 struct net_stats_ipv6_pmtu {
212 	/** Number of dropped IPv6 PMTU packets. */
213 	net_stats_t drop;
214 
215 	/** Number of received IPv6 PMTU packets. */
216 	net_stats_t recv;
217 
218 	/** Number of sent IPv6 PMTU packets. */
219 	net_stats_t sent;
220 };
221 
222 /**
223  * @brief IPv4 Path MTU Discovery statistics
224  */
225 struct net_stats_ipv4_pmtu {
226 	/** Number of dropped IPv4 PMTU packets. */
227 	net_stats_t drop;
228 
229 	/** Number of received IPv4 PMTU packets. */
230 	net_stats_t recv;
231 
232 	/** Number of sent IPv4 PMTU packets. */
233 	net_stats_t sent;
234 };
235 
236 /**
237  * @brief IPv6 multicast listener daemon statistics
238  */
239 struct net_stats_ipv6_mld {
240 	/** Number of received IPv6 MLD queries. */
241 	net_stats_t recv;
242 
243 	/** Number of sent IPv6 MLD reports. */
244 	net_stats_t sent;
245 
246 	/** Number of dropped IPv6 MLD packets. */
247 	net_stats_t drop;
248 };
249 
250 /**
251  * @brief IPv4 IGMP daemon statistics
252  */
253 struct net_stats_ipv4_igmp {
254 	/** Number of received IPv4 IGMP queries */
255 	net_stats_t recv;
256 
257 	/** Number of sent IPv4 IGMP reports */
258 	net_stats_t sent;
259 
260 	/** Number of dropped IPv4 IGMP packets */
261 	net_stats_t drop;
262 };
263 
264 /**
265  * @brief DNS statistics
266  */
267 struct net_stats_dns {
268 	/** Number of received DNS queries */
269 	net_stats_t recv;
270 
271 	/** Number of sent DNS responses */
272 	net_stats_t sent;
273 
274 	/** Number of dropped DNS packets */
275 	net_stats_t drop;
276 };
277 
278 /**
279  * @brief Network packet transfer times for calculating average TX time
280  */
281 struct net_stats_tx_time {
282 	/** Sum of network packet transfer times. */
283 	uint64_t sum;
284 
285 	/** Number of network packets transferred. */
286 	net_stats_t count;
287 };
288 
289 /**
290  * @brief Network packet receive times for calculating average RX time
291  */
292 struct net_stats_rx_time {
293 	/** Sum of network packet receive times. */
294 	uint64_t sum;
295 
296 	/** Number of network packets received. */
297 	net_stats_t count;
298 };
299 
300 /** @cond INTERNAL_HIDDEN */
301 
302 #if NET_TC_TX_COUNT == 0
303 #define NET_TC_TX_STATS_COUNT 1
304 #else
305 #define NET_TC_TX_STATS_COUNT NET_TC_TX_COUNT
306 #endif
307 
308 #if NET_TC_RX_COUNT == 0
309 #define NET_TC_RX_STATS_COUNT 1
310 #else
311 #define NET_TC_RX_STATS_COUNT NET_TC_RX_COUNT
312 #endif
313 
314 /** @endcond */
315 
316 /**
317  * @brief Traffic class statistics
318  */
319 struct net_stats_tc {
320 	/** TX statistics for each traffic class */
321 	struct {
322 		/** Helper for calculating average TX time statistics */
323 		struct net_stats_tx_time tx_time;
324 #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL)
325 		/** Detailed TX time statistics inside network stack */
326 		struct net_stats_tx_time
327 				tx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
328 #endif
329 		/** Number of packets sent for this traffic class */
330 		net_stats_t pkts;
331 		/** Number of bytes sent for this traffic class */
332 		net_stats_t bytes;
333 		/** Priority of this traffic class */
334 		uint8_t priority;
335 	} sent[NET_TC_TX_STATS_COUNT];
336 
337 	/** RX statistics for each traffic class */
338 	struct {
339 		/** Helper for calculating average RX time statistics */
340 		struct net_stats_rx_time rx_time;
341 #if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
342 		/** Detailed RX time statistics inside network stack */
343 		struct net_stats_rx_time
344 				rx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
345 #endif
346 		/** Number of packets received for this traffic class */
347 		net_stats_t pkts;
348 		/** Number of bytes received for this traffic class */
349 		net_stats_t bytes;
350 		/** Priority of this traffic class */
351 		uint8_t priority;
352 	} recv[NET_TC_RX_STATS_COUNT];
353 };
354 
355 
356 /**
357  * @brief Power management statistics
358  */
359 struct net_stats_pm {
360 	/** Total suspend time */
361 	uint64_t overall_suspend_time;
362 	/** How many times we were suspended */
363 	net_stats_t suspend_count;
364 	/** How long the last suspend took */
365 	uint32_t last_suspend_time;
366 	/** Network interface last suspend start time */
367 	uint32_t start_time;
368 };
369 
370 
371 /**
372  * @brief All network statistics in one struct.
373  */
374 struct net_stats {
375 	/** Count of malformed packets or packets we do not have handler for */
376 	net_stats_t processing_error;
377 
378 	/**
379 	 * This calculates amount of data transferred through all the
380 	 * network interfaces.
381 	 */
382 	struct net_stats_bytes bytes;
383 
384 	/** IP layer errors */
385 	struct net_stats_ip_errors ip_errors;
386 
387 #if defined(CONFIG_NET_STATISTICS_IPV6)
388 	/** IPv6 statistics */
389 	struct net_stats_ip ipv6;
390 #endif
391 
392 #if defined(CONFIG_NET_STATISTICS_IPV4)
393 	/** IPv4 statistics */
394 	struct net_stats_ip ipv4;
395 #endif
396 
397 #if defined(CONFIG_NET_STATISTICS_ICMP)
398 	/** ICMP statistics */
399 	struct net_stats_icmp icmp;
400 #endif
401 
402 #if defined(CONFIG_NET_STATISTICS_TCP)
403 	/** TCP statistics */
404 	struct net_stats_tcp tcp;
405 #endif
406 
407 #if defined(CONFIG_NET_STATISTICS_UDP)
408 	/** UDP statistics */
409 	struct net_stats_udp udp;
410 #endif
411 
412 #if defined(CONFIG_NET_STATISTICS_IPV6_ND)
413 	/** IPv6 neighbor discovery statistics */
414 	struct net_stats_ipv6_nd ipv6_nd;
415 #endif
416 
417 #if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
418 	/** IPv6 Path MTU Discovery statistics */
419 	struct net_stats_ipv6_pmtu ipv6_pmtu;
420 #endif
421 
422 #if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
423 	/** IPv4 Path MTU Discovery statistics */
424 	struct net_stats_ipv4_pmtu ipv4_pmtu;
425 #endif
426 
427 #if defined(CONFIG_NET_STATISTICS_MLD)
428 	/** IPv6 MLD statistics */
429 	struct net_stats_ipv6_mld ipv6_mld;
430 #endif
431 
432 #if defined(CONFIG_NET_STATISTICS_IGMP)
433 	/** IPv4 IGMP statistics */
434 	struct net_stats_ipv4_igmp ipv4_igmp;
435 #endif
436 
437 #if defined(CONFIG_NET_STATISTICS_DNS)
438 	/** DNS statistics */
439 	struct net_stats_dns dns;
440 #endif
441 
442 #if NET_TC_COUNT > 1
443 	/** Traffic class statistics */
444 	struct net_stats_tc tc;
445 #endif
446 
447 #if defined(CONFIG_NET_PKT_TXTIME_STATS)
448 	/** Network packet TX time statistics */
449 	struct net_stats_tx_time tx_time;
450 #endif
451 
452 #if defined(CONFIG_NET_PKT_RXTIME_STATS)
453 	/** Network packet RX time statistics */
454 	struct net_stats_rx_time rx_time;
455 #endif
456 
457 #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL)
458 	/** Network packet TX time detail statistics */
459 	struct net_stats_tx_time tx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
460 #endif
461 #if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
462 	/** Network packet RX time detail statistics */
463 	struct net_stats_rx_time rx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
464 #endif
465 
466 #if defined(CONFIG_NET_STATISTICS_POWER_MANAGEMENT)
467 	/** Power management statistics */
468 	struct net_stats_pm pm;
469 #endif
470 };
471 
472 /**
473  * @brief Ethernet error statistics
474  */
475 struct net_stats_eth_errors {
476 	/** Number of RX length errors */
477 	net_stats_t rx_length_errors;
478 
479 	/** Number of RX overrun errors */
480 	net_stats_t rx_over_errors;
481 
482 	/** Number of RX CRC errors */
483 	net_stats_t rx_crc_errors;
484 
485 	/** Number of RX frame errors */
486 	net_stats_t rx_frame_errors;
487 
488 	/** Number of RX net_pkt allocation errors */
489 	net_stats_t rx_no_buffer_count;
490 
491 	/** Number of RX missed errors */
492 	net_stats_t rx_missed_errors;
493 
494 	/** Number of RX long length errors */
495 	net_stats_t rx_long_length_errors;
496 
497 	/** Number of RX short length errors */
498 	net_stats_t rx_short_length_errors;
499 
500 	/** Number of RX buffer align errors */
501 	net_stats_t rx_align_errors;
502 
503 	/** Number of RX DMA failed errors */
504 	net_stats_t rx_dma_failed;
505 
506 	/** Number of RX net_buf allocation errors */
507 	net_stats_t rx_buf_alloc_failed;
508 
509 	/** Number of TX aborted errors */
510 	net_stats_t tx_aborted_errors;
511 
512 	/** Number of TX carrier errors */
513 	net_stats_t tx_carrier_errors;
514 
515 	/** Number of TX FIFO errors */
516 	net_stats_t tx_fifo_errors;
517 
518 	/** Number of TX heartbeat errors */
519 	net_stats_t tx_heartbeat_errors;
520 
521 	/** Number of TX window errors */
522 	net_stats_t tx_window_errors;
523 
524 	/** Number of TX DMA failed errors */
525 	net_stats_t tx_dma_failed;
526 
527 	/** Number of uncorrected ECC errors */
528 	net_stats_t uncorr_ecc_errors;
529 
530 	/** Number of corrected ECC errors */
531 	net_stats_t corr_ecc_errors;
532 };
533 
534 /**
535  * @brief Ethernet flow control statistics
536  */
537 struct net_stats_eth_flow {
538 	/** Number of RX XON flow control */
539 	net_stats_t rx_flow_control_xon;
540 
541 	/** Number of RX XOFF flow control */
542 	net_stats_t rx_flow_control_xoff;
543 
544 	/** Number of TX XON flow control */
545 	net_stats_t tx_flow_control_xon;
546 
547 	/** Number of TX XOFF flow control */
548 	net_stats_t tx_flow_control_xoff;
549 };
550 
551 /**
552  * @brief Ethernet checksum statistics
553  */
554 struct net_stats_eth_csum {
555 	/** Number of good RX checksum offloading */
556 	net_stats_t rx_csum_offload_good;
557 
558 	/** Number of failed RX checksum offloading */
559 	net_stats_t rx_csum_offload_errors;
560 };
561 
562 /**
563  * @brief Ethernet hardware timestamp statistics
564  */
565 struct net_stats_eth_hw_timestamp {
566 	/** Number of RX hardware timestamp cleared */
567 	net_stats_t rx_hwtstamp_cleared;
568 
569 	/** Number of RX hardware timestamp timeout */
570 	net_stats_t tx_hwtstamp_timeouts;
571 
572 	/** Number of RX hardware timestamp skipped */
573 	net_stats_t tx_hwtstamp_skipped;
574 };
575 
576 #ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
577 /**
578  * @brief Ethernet vendor specific statistics
579  */
580 struct net_stats_eth_vendor {
581 	const char * const key; /**< Key name of vendor statistics */
582 	uint32_t value;         /**< Value of the statistics key */
583 };
584 #endif
585 
586 /**
587  * @brief All Ethernet specific statistics
588  */
589 struct net_stats_eth {
590 	/** Total number of bytes received and sent */
591 	struct net_stats_bytes bytes;
592 
593 	/** Total number of packets received and sent */
594 	struct net_stats_pkts pkts;
595 
596 	/** Total number of broadcast packets received and sent */
597 	struct net_stats_pkts broadcast;
598 
599 	/** Total number of multicast packets received and sent */
600 	struct net_stats_pkts multicast;
601 
602 	/** Total number of errors in RX and TX */
603 	struct net_stats_pkts errors;
604 
605 	/** Total number of errors in RX and TX */
606 	struct net_stats_eth_errors error_details;
607 
608 	/** Total number of flow control errors in RX and TX */
609 	struct net_stats_eth_flow flow_control;
610 
611 	/** Total number of checksum errors in RX and TX */
612 	struct net_stats_eth_csum csum;
613 
614 	/** Total number of hardware timestamp errors in RX and TX */
615 	struct net_stats_eth_hw_timestamp hw_timestamp;
616 
617 	/** Total number of collisions */
618 	net_stats_t collisions;
619 
620 	/** Total number of dropped TX packets */
621 	net_stats_t tx_dropped;
622 
623 	/** Total number of TX timeout errors */
624 	net_stats_t tx_timeout_count;
625 
626 	/** Total number of TX queue restarts */
627 	net_stats_t tx_restart_queue;
628 
629 	/** Total number of RX unknown protocol packets */
630 	net_stats_t unknown_protocol;
631 
632 #ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
633 	/** Array is terminated with an entry containing a NULL key */
634 	struct net_stats_eth_vendor *vendor;
635 #endif
636 };
637 
638 /**
639  * @brief All PPP specific statistics
640  */
641 struct net_stats_ppp {
642 	/** Total number of bytes received and sent */
643 	struct net_stats_bytes bytes;
644 
645 	/** Total number of packets received and sent */
646 	struct net_stats_pkts pkts;
647 
648 	/** Number of received and dropped PPP frames. */
649 	net_stats_t drop;
650 
651 	/** Number of received PPP frames with a bad checksum. */
652 	net_stats_t chkerr;
653 };
654 
655 /**
656  * @brief All Wi-Fi management statistics
657  */
658 struct net_stats_sta_mgmt {
659 	/** Number of received beacons */
660 	net_stats_t beacons_rx;
661 
662 	/** Number of missed beacons */
663 	net_stats_t beacons_miss;
664 };
665 
666 /**
667  * @brief All Wi-Fi specific statistics
668  */
669 struct net_stats_wifi {
670 	/** Total number of beacon errors */
671 	struct net_stats_sta_mgmt sta_mgmt;
672 
673 	/** Total number of bytes received and sent */
674 	struct net_stats_bytes bytes;
675 
676 	/** Total number of packets received and sent */
677 	struct net_stats_pkts pkts;
678 
679 	/** Total number of broadcast packets received and sent */
680 	struct net_stats_pkts broadcast;
681 
682 	/** Total number of multicast packets received and sent */
683 	struct net_stats_pkts multicast;
684 
685 	/** Total number of errors in RX and TX */
686 	struct net_stats_pkts errors;
687 
688 	/** Total number of unicast packets received and sent */
689 	struct net_stats_pkts unicast;
690 
691 	/** Total number of dropped packets at received and sent*/
692 	net_stats_t overrun_count;
693 };
694 
695 #if defined(CONFIG_NET_STATISTICS_USER_API)
696 /* Management part definitions */
697 
698 /** @cond INTERNAL_HIDDEN */
699 
700 #define _NET_STATS_LAYER	NET_MGMT_LAYER_L3
701 #define _NET_STATS_CODE		0x101
702 #define _NET_STATS_BASE		(NET_MGMT_LAYER(_NET_STATS_LAYER) |	\
703 				 NET_MGMT_LAYER_CODE(_NET_STATS_CODE))
704 
705 enum net_request_stats_cmd {
706 	NET_REQUEST_STATS_CMD_GET_ALL = 1,
707 	NET_REQUEST_STATS_CMD_GET_PROCESSING_ERROR,
708 	NET_REQUEST_STATS_CMD_GET_BYTES,
709 	NET_REQUEST_STATS_CMD_GET_IP_ERRORS,
710 	NET_REQUEST_STATS_CMD_GET_IPV4,
711 	NET_REQUEST_STATS_CMD_GET_IPV6,
712 	NET_REQUEST_STATS_CMD_GET_IPV6_ND,
713 	NET_REQUEST_STATS_CMD_GET_IPV6_PMTU,
714 	NET_REQUEST_STATS_CMD_GET_IPV4_PMTU,
715 	NET_REQUEST_STATS_CMD_GET_ICMP,
716 	NET_REQUEST_STATS_CMD_GET_UDP,
717 	NET_REQUEST_STATS_CMD_GET_TCP,
718 	NET_REQUEST_STATS_CMD_GET_ETHERNET,
719 	NET_REQUEST_STATS_CMD_GET_PPP,
720 	NET_REQUEST_STATS_CMD_GET_PM,
721 	NET_REQUEST_STATS_CMD_GET_WIFI,
722 	NET_REQUEST_STATS_CMD_RESET_WIFI,
723 };
724 
725 /** @endcond */
726 
727 /** Request all network statistics */
728 #define NET_REQUEST_STATS_GET_ALL				\
729 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_ALL)
730 
731 /** Request all processing error statistics */
732 #define NET_REQUEST_STATS_GET_PROCESSING_ERROR				\
733 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_PROCESSING_ERROR)
734 
735 /** Request number of received and sent bytes */
736 #define NET_REQUEST_STATS_GET_BYTES				\
737 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_BYTES)
738 
739 /** Request IP error statistics */
740 #define NET_REQUEST_STATS_GET_IP_ERRORS				\
741 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IP_ERRORS)
742 
743 /** @cond INTERNAL_HIDDEN */
744 
745 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ALL);
746 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PROCESSING_ERROR);
747 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_BYTES);
748 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IP_ERRORS);
749 
750 /** @endcond */
751 
752 #if defined(CONFIG_NET_STATISTICS_IPV4)
753 /** Request IPv4 statistics */
754 #define NET_REQUEST_STATS_GET_IPV4				\
755 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV4)
756 
757 /** @cond INTERNAL_HIDDEN */
758 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV4);
759 /** @endcond */
760 #endif /* CONFIG_NET_STATISTICS_IPV4 */
761 
762 #if defined(CONFIG_NET_STATISTICS_IPV6)
763 /** Request IPv6 statistics */
764 #define NET_REQUEST_STATS_GET_IPV6				\
765 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV6)
766 
767 /** @cond INTERNAL_HIDDEN */
768 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6);
769 /** @endcond */
770 #endif /* CONFIG_NET_STATISTICS_IPV6 */
771 
772 #if defined(CONFIG_NET_STATISTICS_IPV6_ND)
773 /** Request IPv6 neighbor discovery statistics */
774 #define NET_REQUEST_STATS_GET_IPV6_ND				\
775 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV6_ND)
776 
777 /** @cond INTERNAL_HIDDEN */
778 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6_ND);
779 /** @endcond */
780 #endif /* CONFIG_NET_STATISTICS_IPV6_ND */
781 
782 #if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
783 /** Request IPv6 Path MTU Discovery statistics */
784 #define NET_REQUEST_STATS_GET_IPV6_PMTU				\
785 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV6_PMTU)
786 
787 /** @cond INTERNAL_HIDDEN */
788 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6_PMTU);
789 /** @endcond */
790 #endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */
791 
792 #if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
793 /** Request IPv4 Path MTU Discovery statistics */
794 #define NET_REQUEST_STATS_GET_IPV4_PMTU				\
795 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV4_PMTU)
796 
797 /** @cond INTERNAL_HIDDEN */
798 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV4_PMTU);
799 /** @endcond */
800 #endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
801 
802 #if defined(CONFIG_NET_STATISTICS_ICMP)
803 /** Request ICMPv4 and ICMPv6 statistics */
804 #define NET_REQUEST_STATS_GET_ICMP				\
805 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_ICMP)
806 
807 /** @cond INTERNAL_HIDDEN */
808 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ICMP);
809 /** @endcond */
810 #endif /* CONFIG_NET_STATISTICS_ICMP */
811 
812 #if defined(CONFIG_NET_STATISTICS_UDP)
813 /** Request UDP statistics */
814 #define NET_REQUEST_STATS_GET_UDP				\
815 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_UDP)
816 
817 /** @cond INTERNAL_HIDDEN */
818 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_UDP);
819 /** @endcond */
820 #endif /* CONFIG_NET_STATISTICS_UDP */
821 
822 #if defined(CONFIG_NET_STATISTICS_TCP)
823 /** Request TCP statistics */
824 #define NET_REQUEST_STATS_GET_TCP				\
825 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_TCP)
826 
827 /** @cond INTERNAL_HIDDEN */
828 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_TCP);
829 /** @endcond */
830 #endif /* CONFIG_NET_STATISTICS_TCP */
831 
832 #if defined(CONFIG_NET_STATISTICS_ETHERNET)
833 /** Request Ethernet statistics */
834 #define NET_REQUEST_STATS_GET_ETHERNET				\
835 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_ETHERNET)
836 
837 /** @cond INTERNAL_HIDDEN */
838 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ETHERNET);
839 /** @endcond */
840 #endif /* CONFIG_NET_STATISTICS_ETHERNET */
841 
842 #if defined(CONFIG_NET_STATISTICS_PPP)
843 /** Request PPP statistics */
844 #define NET_REQUEST_STATS_GET_PPP				\
845 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_PPP)
846 
847 /** @cond INTERNAL_HIDDEN */
848 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PPP);
849 /** @endcond */
850 #endif /* CONFIG_NET_STATISTICS_PPP */
851 
852 #endif /* CONFIG_NET_STATISTICS_USER_API */
853 
854 #if defined(CONFIG_NET_STATISTICS_POWER_MANAGEMENT)
855 /** Request network power management statistics */
856 #define NET_REQUEST_STATS_GET_PM				\
857 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_PM)
858 
859 /** @cond INTERNAL_HIDDEN */
860 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PM);
861 /** @endcond */
862 #endif /* CONFIG_NET_STATISTICS_POWER_MANAGEMENT */
863 
864 #if defined(CONFIG_NET_STATISTICS_WIFI)
865 /** Request Wi-Fi statistics */
866 #define NET_REQUEST_STATS_GET_WIFI				\
867 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_WIFI)
868 
869 /** @cond INTERNAL_HIDDEN */
870 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI);
871 /** @endcond */
872 
873 /** Reset Wi-Fi statistics*/
874 #define NET_REQUEST_STATS_RESET_WIFI                              \
875 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_RESET_WIFI)
876 
877 /** @cond INTERNAL_HIDDEN */
878 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_RESET_WIFI);
879 /** @endcond */
880 #endif /* CONFIG_NET_STATISTICS_WIFI */
881 
882 #define NET_STATS_GET_METRIC_NAME(_name) _name
883 #define NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx) net_stats_##dev_id##_##sfx##_collector
884 #define NET_STATS_GET_VAR(dev_id, sfx, var) zephyr_net_##var
885 #define NET_STATS_GET_INSTANCE(dev_id, sfx, _not_used) STRINGIFY(_##dev_id##_##sfx)
886 
887 /* The label value is set to be the network interface name. Note that we skip
888  * the first character (_) when setting the label value. This can be changed
889  * if there is a way to token paste the instance name without the prefix character.
890  * Note also that the below macros have some parameters that are not used atm.
891  */
892 #define NET_STATS_PROMETHEUS_COUNTER_DEFINE(_desc, _labelval, _not_used,	\
893 					    _collector, _name, _stat_var_ptr)	\
894 	static PROMETHEUS_COUNTER_DEFINE(					\
895 		NET_STATS_GET_METRIC_NAME(_name),				\
896 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
897 		&(_collector), _stat_var_ptr)
898 
899 #define NET_STATS_PROMETHEUS_GAUGE_DEFINE(_desc,  _labelval, _not_used,		\
900 					  _collector, _name, _stat_var_ptr)	\
901 	static PROMETHEUS_GAUGE_DEFINE(						\
902 		NET_STATS_GET_METRIC_NAME(_name),				\
903 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
904 		&(_collector), _stat_var_ptr)
905 
906 #define NET_STATS_PROMETHEUS_SUMMARY_DEFINE(_desc,  _labelval, _not_used,	\
907 					    _collector, _name, _stat_var_ptr)	\
908 	static PROMETHEUS_SUMMARY_DEFINE(					\
909 		NET_STATS_GET_METRIC_NAME(_name),				\
910 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
911 		&(_collector), _stat_var_ptr)
912 
913 #define NET_STATS_PROMETHEUS_HISTOGRAM_DEFINE(_desc, _labelval, _not_used,	\
914 					      _collector, _name, _stat_var_ptr)	\
915 	static PROMETHEUS_HISTOGRAM_DEFINE(					\
916 		NET_STATS_GET_METRIC_NAME(_name),				\
917 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
918 		&(_collector), _stat_var_ptr)
919 
920 /* IPv6 layer statistics */
921 #if defined(CONFIG_NET_STATISTICS_IPV6)
922 #define NET_STATS_PROMETHEUS_IPV6(iface, dev_id, sfx)			\
923 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
924 		"IPv6 packets sent",					\
925 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_sent),		\
926 		"packet_count",						\
927 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
928 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_sent),		\
929 		&(iface)->stats.ipv6.sent);				\
930 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
931 		"IPv6 packets received",				\
932 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_recv),		\
933 		"packet_count",						\
934 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
935 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_recv),		\
936 		&(iface)->stats.ipv6.recv);				\
937 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
938 		"IPv6 packets dropped",					\
939 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_drop),		\
940 		"packet_count",						\
941 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
942 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_drop),		\
943 		&(iface)->stats.ipv6.drop);				\
944 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
945 		"IPv6 packets forwarded",				\
946 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_forward),	\
947 		"packet_count",						\
948 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
949 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_forwarded),		\
950 		&(iface)->stats.ipv6.forwarded)
951 #else
952 #define NET_STATS_PROMETHEUS_IPV6(iface, dev_id, sfx)
953 #endif
954 
955 /* IPv4 layer statistics */
956 #if defined(CONFIG_NET_STATISTICS_IPV4)
957 #define NET_STATS_PROMETHEUS_IPV4(iface, dev_id, sfx)			\
958 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
959 		"IPv4 packets sent",					\
960 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_sent),		\
961 		"packet_count",						\
962 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
963 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_sent),		\
964 		&(iface)->stats.ipv4.sent);				\
965 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
966 		"IPv4 packets received",				\
967 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_recv),		\
968 		"packet_count",						\
969 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
970 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_recv),		\
971 		&(iface)->stats.ipv4.recv);				\
972 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
973 		"IPv4 packets dropped",					\
974 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_drop),		\
975 		"packet_count",						\
976 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
977 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_drop),		\
978 		&(iface)->stats.ipv4.drop);				\
979 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
980 		"IPv4 packets forwarded",				\
981 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_forwarded),	\
982 		"packet_count",						\
983 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
984 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_forwarded),		\
985 		&(iface)->stats.ipv4.forwarded)
986 #else
987 #define NET_STATS_PROMETHEUS_IPV4(iface, dev_id, sfx)
988 #endif
989 
990 /* ICMP layer statistics */
991 #if defined(CONFIG_NET_STATISTICS_ICMP)
992 #define NET_STATS_PROMETHEUS_ICMP(iface, dev_id, sfx)			\
993 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
994 		"ICMP packets sent",					\
995 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_sent),		\
996 		"packet_count",						\
997 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
998 		NET_STATS_GET_VAR(dev_id, sfx, icmp_sent),		\
999 		&(iface)->stats.icmp.sent);				\
1000 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1001 		"ICMP packets received",				\
1002 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_recv),		\
1003 		"packet_count",						\
1004 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1005 		NET_STATS_GET_VAR(dev_id, sfx, icmp_recv),		\
1006 		&(iface)->stats.icmp.recv);				\
1007 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1008 		"ICMP packets dropped",					\
1009 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_drop),		\
1010 		"packet_count",						\
1011 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1012 		NET_STATS_GET_VAR(dev_id, sfx, icmp_drop),		\
1013 		&(iface)->stats.icmp.drop);				\
1014 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1015 		"ICMP packets checksum error",				\
1016 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_chkerr),	\
1017 		"packet_count",						\
1018 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1019 		NET_STATS_GET_VAR(dev_id, sfx, icmp_chkerr),		\
1020 		&(iface)->stats.icmp.chkerr);				\
1021 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1022 		"ICMP packets type error",				\
1023 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_typeerr),	\
1024 		"packet_count",						\
1025 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1026 		NET_STATS_GET_VAR(dev_id, sfx, icmp_typeerr),		\
1027 		&(iface)->stats.icmp.typeerr)
1028 #else
1029 #define NET_STATS_PROMETHEUS_ICMP(iface, dev_id, sfx)
1030 #endif
1031 
1032 /* UDP layer statistics */
1033 #if defined(CONFIG_NET_STATISTICS_UDP)
1034 #define NET_STATS_PROMETHEUS_UDP(iface, dev_id, sfx)			\
1035 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1036 		"UDP packets sent",					\
1037 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_sent),		\
1038 		"packet_count",						\
1039 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1040 		NET_STATS_GET_VAR(dev_id, sfx, udp_sent),		\
1041 		&(iface)->stats.udp.sent);				\
1042 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1043 		"UDP packets received",					\
1044 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_recv),		\
1045 		"packet_count",						\
1046 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1047 		NET_STATS_GET_VAR(dev_id, sfx, udp_recv),		\
1048 		&(iface)->stats.udp.recv);				\
1049 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1050 		"UDP packets dropped",					\
1051 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_drop),		\
1052 		"packet_count",						\
1053 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1054 		NET_STATS_GET_VAR(dev_id, sfx, udp_drop),		\
1055 		&(iface)->stats.udp.drop);				\
1056 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1057 		"UDP packets checksum error",				\
1058 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_chkerr),	\
1059 		"packet_count",						\
1060 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1061 		NET_STATS_GET_VAR(dev_id, sfx, udp_chkerr),		\
1062 		&(iface)->stats.udp.chkerr)
1063 #else
1064 #define NET_STATS_PROMETHEUS_UDP(iface, dev_id, sfx)
1065 #endif
1066 
1067 /* TCP layer statistics */
1068 #if defined(CONFIG_NET_STATISTICS_TCP)
1069 #define NET_STATS_PROMETHEUS_TCP(iface, dev_id, sfx)			\
1070 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1071 		"TCP bytes sent",					\
1072 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_bytes_sent),	\
1073 		"byte_count",						\
1074 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1075 		NET_STATS_GET_VAR(dev_id, sfx, tcp_bytes_sent),		\
1076 		&(iface)->stats.tcp.bytes.sent);			\
1077 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1078 		"TCP bytes received",					\
1079 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_bytes_recv),	\
1080 		"byte_count",						\
1081 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1082 		NET_STATS_GET_VAR(dev_id, sfx, tcp_bytes_recv),		\
1083 		&(iface)->stats.tcp.bytes.received);			\
1084 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1085 		"TCP bytes resent",					\
1086 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_bytes_resent),	\
1087 		"byte_count",						\
1088 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1089 		NET_STATS_GET_VAR(dev_id, sfx, tcp_bytes_resent),	\
1090 		&(iface)->stats.tcp.resent);				\
1091 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1092 		"TCP packets sent",					\
1093 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_sent),		\
1094 		"packet_count",						\
1095 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1096 		NET_STATS_GET_VAR(dev_id, sfx, tcp_sent),		\
1097 		&(iface)->stats.tcp.sent);				\
1098 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1099 		"TCP packets received",					\
1100 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_recv),		\
1101 		"packet_count",						\
1102 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1103 		NET_STATS_GET_VAR(dev_id, sfx, tcp_recv),		\
1104 		&(iface)->stats.tcp.recv);				\
1105 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1106 		"TCP packets dropped",					\
1107 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_drop),		\
1108 		"packet_count",						\
1109 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1110 		NET_STATS_GET_VAR(dev_id, sfx, tcp_drop),		\
1111 		&(iface)->stats.tcp.drop);				\
1112 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1113 		"TCP packets checksum error",				\
1114 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_chkerr),	\
1115 		"packet_count",						\
1116 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1117 		NET_STATS_GET_VAR(dev_id, sfx, tcp_chkerr),		\
1118 		&(iface)->stats.tcp.chkerr);				\
1119 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1120 		"TCP packets ack error",				\
1121 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_ackerr),	\
1122 		"packet_count",						\
1123 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1124 		NET_STATS_GET_VAR(dev_id, sfx, tcp_ackerr),		\
1125 		&(iface)->stats.tcp.ackerr);				\
1126 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1127 		"TCP packets reset error",				\
1128 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_rsterr),	\
1129 		"packet_count",						\
1130 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1131 		NET_STATS_GET_VAR(dev_id, sfx, tcp_rsterr),		\
1132 		&(iface)->stats.tcp.rsterr);				\
1133 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1134 		"TCP packets retransmitted",				\
1135 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_rexmit),	\
1136 		"packet_count",						\
1137 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1138 		NET_STATS_GET_VAR(dev_id, sfx, tcp_rexmit),		\
1139 		&(iface)->stats.tcp.rexmit);				\
1140 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1141 		"TCP reset received",					\
1142 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_rst_recv),	\
1143 		"packet_count",						\
1144 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1145 		NET_STATS_GET_VAR(dev_id, sfx, tcp_rst),		\
1146 		&(iface)->stats.tcp.rst);				\
1147 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1148 		"TCP connection drop",					\
1149 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_conndrop),	\
1150 		"packet_count",						\
1151 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1152 		NET_STATS_GET_VAR(dev_id, sfx, tcp_conndrop),		\
1153 		&(iface)->stats.tcp.conndrop);				\
1154 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1155 		"TCP connection reset",					\
1156 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_connrst),	\
1157 		"packet_count",						\
1158 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1159 		NET_STATS_GET_VAR(dev_id, sfx, tcp_connrst),		\
1160 		&(iface)->stats.tcp.connrst)
1161 #else
1162 #define NET_STATS_PROMETHEUS_TCP(iface, dev_id, sfx)
1163 #endif
1164 
1165 /* IPv6 Neighbor Discovery statistics */
1166 #if defined(CONFIG_NET_STATISTICS_IPV6_ND)
1167 #define NET_STATS_PROMETHEUS_IPV6_ND(iface, dev_id, sfx)		\
1168 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1169 		"IPv6 ND packets sent",					\
1170 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_nd_sent),	\
1171 		"packet_count",						\
1172 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1173 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_nd_sent),		\
1174 		&(iface)->stats.ipv6_nd.sent);				\
1175 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1176 		"IPv6 ND packets received",				\
1177 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_nd_recv),	\
1178 		"packet_count",						\
1179 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1180 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_nd_recv),		\
1181 		&(iface)->stats.ipv6_nd.recv);				\
1182 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1183 		"IPv6 ND packets dropped",				\
1184 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_nd_drop),	\
1185 		"packet_count",						\
1186 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1187 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_nd_drop),		\
1188 		&(iface)->stats.ipv6_nd.drop)
1189 #else
1190 #define NET_STATS_PROMETHEUS_IPV6_ND(iface, dev_id, sfx)
1191 #endif
1192 
1193 /* IPv6 Path MTU Discovery statistics */
1194 #if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
1195 #define NET_STATS_PROMETHEUS_IPV6_PMTU(iface, dev_id, sfx)		\
1196 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1197 		"IPv6 PMTU packets sent",				\
1198 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_pmtu_sent),	\
1199 		"packet_count",						\
1200 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1201 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_pmtu_sent),		\
1202 		&(iface)->stats.ipv6_pmtu.sent);			\
1203 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1204 		"IPv6 PMTU packets received",				\
1205 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_pmtu_recv),	\
1206 		"packet_count",						\
1207 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1208 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_pmtu_recv),		\
1209 		&(iface)->stats.ipv6_pmtu.recv);			\
1210 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1211 		"IPv6 PMTU packets dropped",				\
1212 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_pmtu_drop),	\
1213 		"packet_count",						\
1214 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1215 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_pmtu_drop),		\
1216 		&(iface)->stats.ipv6_pmtu.drop)
1217 #else
1218 #define NET_STATS_PROMETHEUS_IPV6_PMTU(iface, dev_id, sfx)
1219 #endif
1220 
1221 /* IPv4 Path MTU Discovery statistics */
1222 #if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
1223 #define NET_STATS_PROMETHEUS_IPV4_PMTU(iface, dev_id, sfx)		\
1224 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1225 		"IPv4 PMTU packets sent",				\
1226 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_pmtu_sent),	\
1227 		"packet_count",						\
1228 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1229 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_pmtu_sent),		\
1230 		&(iface)->stats.ipv4_pmtu.sent);			\
1231 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1232 		"IPv4 PMTU packets received",				\
1233 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_pmtu_recv),	\
1234 		"packet_count",						\
1235 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1236 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_pmtu_recv),		\
1237 		&(iface)->stats.ipv4_pmtu.recv);			\
1238 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1239 		"IPv4 PMTU packets dropped",				\
1240 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_pmtu_drop),	\
1241 		"packet_count",						\
1242 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1243 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_pmtu_drop),		\
1244 		&(iface)->stats.ipv4_pmtu.drop)
1245 #else
1246 #define NET_STATS_PROMETHEUS_IPV4_PMTU(iface, dev_id, sfx)
1247 #endif
1248 
1249 /* IPv6 Multicast Listener Discovery statistics */
1250 #if defined(CONFIG_NET_STATISTICS_MLD)
1251 #define NET_STATS_PROMETHEUS_MLD(iface, dev_id, sfx)			\
1252 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1253 		"IPv6 MLD packets sent",				\
1254 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_mld_sent),	\
1255 		"packet_count",						\
1256 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1257 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_mld_sent),		\
1258 		&(iface)->stats.ipv6_mld.sent);				\
1259 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1260 		"IPv6 MLD packets received",				\
1261 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_mld_recv),	\
1262 		"packet_count",						\
1263 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1264 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_mld_recv),		\
1265 		&(iface)->stats.ipv6_mld.recv);				\
1266 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1267 		"IPv6 MLD packets dropped",				\
1268 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_mld_drop),	\
1269 		"packet_count",						\
1270 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1271 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_mld_drop),		\
1272 		&(iface)->stats.ipv6_mld.drop)
1273 #else
1274 #define NET_STATS_PROMETHEUS_MLD(iface, dev_id, sfx)
1275 #endif
1276 
1277 /* IPv4 IGMP statistics */
1278 #if defined(CONFIG_NET_STATISTICS_IGMP)
1279 #define NET_STATS_PROMETHEUS_IGMP(iface, dev_id, sfx)			\
1280 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1281 		"IPv4 IGMP packets sent",				\
1282 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_igmp_sent),	\
1283 		"packet_count",						\
1284 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1285 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_igmp_sent),		\
1286 		&(iface)->stats.ipv4_igmp.sent);			\
1287 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1288 		"IPv4 IGMP packets received",				\
1289 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_igmp_recv),	\
1290 		"packet_count",						\
1291 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1292 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_igmp_recv),		\
1293 		&(iface)->stats.ipv4_igmp.recv);			\
1294 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1295 		"IPv4 IGMP packets dropped",				\
1296 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_igmp_drop),	\
1297 		"packet_count",						\
1298 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1299 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_igmp_drop),		\
1300 		&(iface)->stats.ipv4_igmp.drop)
1301 #else
1302 #define NET_STATS_PROMETHEUS_IGMP(iface, dev_id, sfx)
1303 #endif
1304 
1305 /* DNS statistics */
1306 #if defined(CONFIG_NET_STATISTICS_DNS)
1307 #define NET_STATS_PROMETHEUS_DNS(iface, dev_id, sfx)			\
1308 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1309 		"DNS packets sent",					\
1310 		NET_STATS_GET_INSTANCE(dev_id, sfx, dns_sent),		\
1311 		"packet_count",						\
1312 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1313 		NET_STATS_GET_VAR(dev_id, sfx, dns_sent),		\
1314 		&(iface)->stats.dns.sent);				\
1315 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1316 		"DNS packets received",					\
1317 		NET_STATS_GET_INSTANCE(dev_id, sfx, dns_recv),		\
1318 		"packet_count",						\
1319 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1320 		NET_STATS_GET_VAR(dev_id, sfx, dns_recv),		\
1321 		&(iface)->stats.dns.recv);				\
1322 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1323 		"DNS packets dropped",					\
1324 		NET_STATS_GET_INSTANCE(dev_id, sfx, dns_drop),		\
1325 		"packet_count",						\
1326 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1327 		NET_STATS_GET_VAR(dev_id, sfx, dns_drop),		\
1328 		&(iface)->stats.dns.drop)
1329 #else
1330 #define NET_STATS_PROMETHEUS_DNS(iface, dev_id, sfx)
1331 #endif
1332 
1333 /* TX time statistics */
1334 #if defined(CONFIG_NET_PKT_TXTIME_STATS)
1335 #define NET_STATS_PROMETHEUS_TX_TIME(iface, dev_id, sfx)		\
1336 	NET_STATS_PROMETHEUS_SUMMARY_DEFINE(				\
1337 		"TX time in microseconds",				\
1338 		NET_STATS_GET_INSTANCE(dev_id, sfx, tx_time),		\
1339 		"time",							\
1340 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1341 		NET_STATS_GET_VAR(dev_id, sfx, tx_time),		\
1342 		&(iface)->stats.tx_time)
1343 #else
1344 #define NET_STATS_PROMETHEUS_TX_TIME(iface, dev_id, sfx)
1345 #endif
1346 
1347 /* RX time statistics */
1348 #if defined(CONFIG_NET_PKT_RXTIME_STATS)
1349 #define NET_STATS_PROMETHEUS_RX_TIME(iface, dev_id, sfx)		\
1350 	NET_STATS_PROMETHEUS_SUMMARY_DEFINE(				\
1351 		"RX time in microseconds",				\
1352 		NET_STATS_GET_INSTANCE(dev_id, sfx, rx_time),		\
1353 		"time",							\
1354 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1355 		NET_STATS_GET_VAR(dev_id, sfx, rx_time),		\
1356 		&(iface)->stats.rx_time)
1357 #else
1358 #define NET_STATS_PROMETHEUS_RX_TIME(iface, dev_id, sfx)
1359 #endif
1360 
1361 /* Per network interface statistics via Prometheus */
1362 #define NET_STATS_PROMETHEUS(iface, dev_id, sfx)			\
1363 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1364 		"Processing error",					\
1365 		NET_STATS_GET_INSTANCE(dev_id, sfx, process_error),	\
1366 		"error_count",						\
1367 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1368 		NET_STATS_GET_VAR(dev_id, sfx, processing_error),	\
1369 		&(iface)->stats.processing_error);			\
1370 	/* IP layer error statistics */					\
1371 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1372 		"IP proto error",					\
1373 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_proto_error),	\
1374 		"error_count",						\
1375 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1376 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_protoerr),	\
1377 		&(iface)->stats.ip_errors.protoerr);			\
1378 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1379 		"IP version/header len error",				\
1380 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_vhl_error),	\
1381 		"error_count",						\
1382 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1383 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_vhlerr),	\
1384 		&(iface)->stats.ip_errors.vhlerr);			\
1385 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1386 		"IP header len error (high byte)",			\
1387 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_hblen_error),	\
1388 		"error_count",						\
1389 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1390 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_hblenerr),	\
1391 		&(iface)->stats.ip_errors.hblenerr);			\
1392 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1393 		"IP header len error (low byte)",			\
1394 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_lblen_error),	\
1395 		"error_count",						\
1396 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1397 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_lblenerr),	\
1398 		&(iface)->stats.ip_errors.lblenerr);			\
1399 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1400 		"IP fragment error",					\
1401 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_frag_error),	\
1402 		"error_count",						\
1403 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1404 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_fragerr),	\
1405 		&(iface)->stats.ip_errors.fragerr);			\
1406 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1407 		"IP checksum error",					\
1408 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_chk_error),	\
1409 		"error_count",						\
1410 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1411 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_chkerr),	\
1412 		&(iface)->stats.ip_errors.chkerr);			\
1413 	/* General network statistics */				\
1414 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1415 		"Bytes received",					\
1416 		NET_STATS_GET_INSTANCE(dev_id, sfx, bytes_recv),	\
1417 		"byte_count",						\
1418 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1419 		NET_STATS_GET_VAR(dev_id, sfx, bytes_recv),		\
1420 		&(iface)->stats.bytes.received);			\
1421 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1422 		"Bytes sent",						\
1423 		NET_STATS_GET_INSTANCE(dev_id, sfx, bytes_sent),	\
1424 		"byte_count",						\
1425 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1426 		NET_STATS_GET_VAR(dev_id, sfx, bytes_sent),		\
1427 		&(iface)->stats.bytes.sent);				\
1428 	NET_STATS_PROMETHEUS_IPV6(iface, dev_id, sfx);			\
1429 	NET_STATS_PROMETHEUS_IPV4(iface, dev_id, sfx);			\
1430 	NET_STATS_PROMETHEUS_ICMP(iface, dev_id, sfx);			\
1431 	NET_STATS_PROMETHEUS_UDP(iface, dev_id, sfx);			\
1432 	NET_STATS_PROMETHEUS_TCP(iface, dev_id, sfx);			\
1433 	NET_STATS_PROMETHEUS_IPV6_ND(iface, dev_id, sfx);		\
1434 	NET_STATS_PROMETHEUS_IPV6_PMTU(iface, dev_id, sfx);		\
1435 	NET_STATS_PROMETHEUS_IPV4_PMTU(iface, dev_id, sfx);		\
1436 	NET_STATS_PROMETHEUS_MLD(iface, dev_id, sfx);			\
1437 	NET_STATS_PROMETHEUS_IGMP(iface, dev_id, sfx);			\
1438 	NET_STATS_PROMETHEUS_DNS(iface, dev_id, sfx);			\
1439 	NET_STATS_PROMETHEUS_TX_TIME(iface, dev_id, sfx);		\
1440 	NET_STATS_PROMETHEUS_RX_TIME(iface, dev_id, sfx)
1441 
1442 /**
1443  * @}
1444  */
1445 
1446 #ifdef __cplusplus
1447 }
1448 #endif
1449 
1450 #endif /* ZEPHYR_INCLUDE_NET_NET_STATS_H_ */
1451