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 packets dropped for this traffic class */
332 		net_stats_t dropped;
333 		/** Number of bytes sent for this traffic class */
334 		net_stats_t bytes;
335 		/** Priority of this traffic class */
336 		uint8_t priority;
337 	} sent[NET_TC_TX_STATS_COUNT];
338 
339 	/** RX statistics for each traffic class */
340 	struct {
341 		/** Helper for calculating average RX time statistics */
342 		struct net_stats_rx_time rx_time;
343 #if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
344 		/** Detailed RX time statistics inside network stack */
345 		struct net_stats_rx_time
346 				rx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
347 #endif
348 		/** Number of packets received for this traffic class */
349 		net_stats_t pkts;
350 		/** Number of packets dropped for this traffic class */
351 		net_stats_t dropped;
352 		/** Number of bytes received for this traffic class */
353 		net_stats_t bytes;
354 		/** Priority of this traffic class */
355 		uint8_t priority;
356 	} recv[NET_TC_RX_STATS_COUNT];
357 };
358 
359 
360 /**
361  * @brief Power management statistics
362  */
363 struct net_stats_pm {
364 	/** Total suspend time */
365 	uint64_t overall_suspend_time;
366 	/** How many times we were suspended */
367 	net_stats_t suspend_count;
368 	/** How long the last suspend took */
369 	uint32_t last_suspend_time;
370 	/** Network interface last suspend start time */
371 	uint32_t start_time;
372 };
373 
374 
375 /**
376  * @brief All network statistics in one struct.
377  */
378 struct net_stats {
379 	/** Count of malformed packets or packets we do not have handler for */
380 	net_stats_t processing_error;
381 
382 	/**
383 	 * This calculates amount of data transferred through all the
384 	 * network interfaces.
385 	 */
386 	struct net_stats_bytes bytes;
387 
388 	/** IP layer errors */
389 	struct net_stats_ip_errors ip_errors;
390 
391 #if defined(CONFIG_NET_STATISTICS_IPV6)
392 	/** IPv6 statistics */
393 	struct net_stats_ip ipv6;
394 #endif
395 
396 #if defined(CONFIG_NET_STATISTICS_IPV4)
397 	/** IPv4 statistics */
398 	struct net_stats_ip ipv4;
399 #endif
400 
401 #if defined(CONFIG_NET_STATISTICS_ICMP)
402 	/** ICMP statistics */
403 	struct net_stats_icmp icmp;
404 #endif
405 
406 #if defined(CONFIG_NET_STATISTICS_TCP)
407 	/** TCP statistics */
408 	struct net_stats_tcp tcp;
409 #endif
410 
411 #if defined(CONFIG_NET_STATISTICS_UDP)
412 	/** UDP statistics */
413 	struct net_stats_udp udp;
414 #endif
415 
416 #if defined(CONFIG_NET_STATISTICS_IPV6_ND)
417 	/** IPv6 neighbor discovery statistics */
418 	struct net_stats_ipv6_nd ipv6_nd;
419 #endif
420 
421 #if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
422 	/** IPv6 Path MTU Discovery statistics */
423 	struct net_stats_ipv6_pmtu ipv6_pmtu;
424 #endif
425 
426 #if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
427 	/** IPv4 Path MTU Discovery statistics */
428 	struct net_stats_ipv4_pmtu ipv4_pmtu;
429 #endif
430 
431 #if defined(CONFIG_NET_STATISTICS_MLD)
432 	/** IPv6 MLD statistics */
433 	struct net_stats_ipv6_mld ipv6_mld;
434 #endif
435 
436 #if defined(CONFIG_NET_STATISTICS_IGMP)
437 	/** IPv4 IGMP statistics */
438 	struct net_stats_ipv4_igmp ipv4_igmp;
439 #endif
440 
441 #if defined(CONFIG_NET_STATISTICS_DNS)
442 	/** DNS statistics */
443 	struct net_stats_dns dns;
444 #endif
445 
446 #if NET_TC_COUNT > 1
447 	/** Traffic class statistics */
448 	struct net_stats_tc tc;
449 #endif
450 
451 #if defined(CONFIG_NET_PKT_TXTIME_STATS)
452 	/** Network packet TX time statistics */
453 	struct net_stats_tx_time tx_time;
454 #endif
455 
456 #if defined(CONFIG_NET_PKT_RXTIME_STATS)
457 	/** Network packet RX time statistics */
458 	struct net_stats_rx_time rx_time;
459 #endif
460 
461 #if defined(CONFIG_NET_PKT_TXTIME_STATS_DETAIL)
462 	/** Network packet TX time detail statistics */
463 	struct net_stats_tx_time tx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
464 #endif
465 #if defined(CONFIG_NET_PKT_RXTIME_STATS_DETAIL)
466 	/** Network packet RX time detail statistics */
467 	struct net_stats_rx_time rx_time_detail[NET_PKT_DETAIL_STATS_COUNT];
468 #endif
469 
470 #if defined(CONFIG_NET_STATISTICS_POWER_MANAGEMENT)
471 	/** Power management statistics */
472 	struct net_stats_pm pm;
473 #endif
474 };
475 
476 /**
477  * @brief Ethernet error statistics
478  */
479 struct net_stats_eth_errors {
480 	/** Number of RX length errors */
481 	net_stats_t rx_length_errors;
482 
483 	/** Number of RX overrun errors */
484 	net_stats_t rx_over_errors;
485 
486 	/** Number of RX CRC errors */
487 	net_stats_t rx_crc_errors;
488 
489 	/** Number of RX frame errors */
490 	net_stats_t rx_frame_errors;
491 
492 	/** Number of RX net_pkt allocation errors */
493 	net_stats_t rx_no_buffer_count;
494 
495 	/** Number of RX missed errors */
496 	net_stats_t rx_missed_errors;
497 
498 	/** Number of RX long length errors */
499 	net_stats_t rx_long_length_errors;
500 
501 	/** Number of RX short length errors */
502 	net_stats_t rx_short_length_errors;
503 
504 	/** Number of RX buffer align errors */
505 	net_stats_t rx_align_errors;
506 
507 	/** Number of RX DMA failed errors */
508 	net_stats_t rx_dma_failed;
509 
510 	/** Number of RX net_buf allocation errors */
511 	net_stats_t rx_buf_alloc_failed;
512 
513 	/** Number of TX aborted errors */
514 	net_stats_t tx_aborted_errors;
515 
516 	/** Number of TX carrier errors */
517 	net_stats_t tx_carrier_errors;
518 
519 	/** Number of TX FIFO errors */
520 	net_stats_t tx_fifo_errors;
521 
522 	/** Number of TX heartbeat errors */
523 	net_stats_t tx_heartbeat_errors;
524 
525 	/** Number of TX window errors */
526 	net_stats_t tx_window_errors;
527 
528 	/** Number of TX DMA failed errors */
529 	net_stats_t tx_dma_failed;
530 
531 	/** Number of uncorrected ECC errors */
532 	net_stats_t uncorr_ecc_errors;
533 
534 	/** Number of corrected ECC errors */
535 	net_stats_t corr_ecc_errors;
536 };
537 
538 /**
539  * @brief Ethernet flow control statistics
540  */
541 struct net_stats_eth_flow {
542 	/** Number of RX XON flow control */
543 	net_stats_t rx_flow_control_xon;
544 
545 	/** Number of RX XOFF flow control */
546 	net_stats_t rx_flow_control_xoff;
547 
548 	/** Number of TX XON flow control */
549 	net_stats_t tx_flow_control_xon;
550 
551 	/** Number of TX XOFF flow control */
552 	net_stats_t tx_flow_control_xoff;
553 };
554 
555 /**
556  * @brief Ethernet checksum statistics
557  */
558 struct net_stats_eth_csum {
559 	/** Number of good RX checksum offloading */
560 	net_stats_t rx_csum_offload_good;
561 
562 	/** Number of failed RX checksum offloading */
563 	net_stats_t rx_csum_offload_errors;
564 };
565 
566 /**
567  * @brief Ethernet hardware timestamp statistics
568  */
569 struct net_stats_eth_hw_timestamp {
570 	/** Number of RX hardware timestamp cleared */
571 	net_stats_t rx_hwtstamp_cleared;
572 
573 	/** Number of RX hardware timestamp timeout */
574 	net_stats_t tx_hwtstamp_timeouts;
575 
576 	/** Number of RX hardware timestamp skipped */
577 	net_stats_t tx_hwtstamp_skipped;
578 };
579 
580 #ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
581 /**
582  * @brief Ethernet vendor specific statistics
583  */
584 struct net_stats_eth_vendor {
585 	const char * const key; /**< Key name of vendor statistics */
586 	uint32_t value;         /**< Value of the statistics key */
587 };
588 #endif
589 
590 /**
591  * @brief All Ethernet specific statistics
592  */
593 struct net_stats_eth {
594 	/** Total number of bytes received and sent */
595 	struct net_stats_bytes bytes;
596 
597 	/** Total number of packets received and sent */
598 	struct net_stats_pkts pkts;
599 
600 	/** Total number of broadcast packets received and sent */
601 	struct net_stats_pkts broadcast;
602 
603 	/** Total number of multicast packets received and sent */
604 	struct net_stats_pkts multicast;
605 
606 	/** Total number of errors in RX and TX */
607 	struct net_stats_pkts errors;
608 
609 	/** Total number of errors in RX and TX */
610 	struct net_stats_eth_errors error_details;
611 
612 	/** Total number of flow control errors in RX and TX */
613 	struct net_stats_eth_flow flow_control;
614 
615 	/** Total number of checksum errors in RX and TX */
616 	struct net_stats_eth_csum csum;
617 
618 	/** Total number of hardware timestamp errors in RX and TX */
619 	struct net_stats_eth_hw_timestamp hw_timestamp;
620 
621 	/** Total number of collisions */
622 	net_stats_t collisions;
623 
624 	/** Total number of dropped TX packets */
625 	net_stats_t tx_dropped;
626 
627 	/** Total number of TX timeout errors */
628 	net_stats_t tx_timeout_count;
629 
630 	/** Total number of TX queue restarts */
631 	net_stats_t tx_restart_queue;
632 
633 	/** Total number of RX unknown protocol packets */
634 	net_stats_t unknown_protocol;
635 
636 #ifdef CONFIG_NET_STATISTICS_ETHERNET_VENDOR
637 	/** Array is terminated with an entry containing a NULL key */
638 	struct net_stats_eth_vendor *vendor;
639 #endif
640 };
641 
642 /**
643  * @brief All PPP specific statistics
644  */
645 struct net_stats_ppp {
646 	/** Total number of bytes received and sent */
647 	struct net_stats_bytes bytes;
648 
649 	/** Total number of packets received and sent */
650 	struct net_stats_pkts pkts;
651 
652 	/** Number of received and dropped PPP frames. */
653 	net_stats_t drop;
654 
655 	/** Number of received PPP frames with a bad checksum. */
656 	net_stats_t chkerr;
657 };
658 
659 /**
660  * @brief All Wi-Fi management statistics
661  */
662 struct net_stats_sta_mgmt {
663 	/** Number of received beacons */
664 	net_stats_t beacons_rx;
665 
666 	/** Number of missed beacons */
667 	net_stats_t beacons_miss;
668 };
669 
670 /**
671  * @brief All Wi-Fi specific statistics
672  */
673 struct net_stats_wifi {
674 	/** Total number of beacon errors */
675 	struct net_stats_sta_mgmt sta_mgmt;
676 
677 	/** Total number of bytes received and sent */
678 	struct net_stats_bytes bytes;
679 
680 	/** Total number of packets received and sent */
681 	struct net_stats_pkts pkts;
682 
683 	/** Total number of broadcast packets received and sent */
684 	struct net_stats_pkts broadcast;
685 
686 	/** Total number of multicast packets received and sent */
687 	struct net_stats_pkts multicast;
688 
689 	/** Total number of errors in RX and TX */
690 	struct net_stats_pkts errors;
691 
692 	/** Total number of unicast packets received and sent */
693 	struct net_stats_pkts unicast;
694 
695 	/** Total number of dropped packets at received and sent*/
696 	net_stats_t overrun_count;
697 };
698 
699 #if defined(CONFIG_NET_STATISTICS_USER_API)
700 /* Management part definitions */
701 
702 /** @cond INTERNAL_HIDDEN */
703 
704 #define _NET_STATS_LAYER	NET_MGMT_LAYER_L3
705 #define _NET_STATS_CODE		0x101
706 #define _NET_STATS_BASE		(NET_MGMT_LAYER(_NET_STATS_LAYER) |	\
707 				 NET_MGMT_LAYER_CODE(_NET_STATS_CODE))
708 
709 enum net_request_stats_cmd {
710 	NET_REQUEST_STATS_CMD_GET_ALL = 1,
711 	NET_REQUEST_STATS_CMD_GET_PROCESSING_ERROR,
712 	NET_REQUEST_STATS_CMD_GET_BYTES,
713 	NET_REQUEST_STATS_CMD_GET_IP_ERRORS,
714 	NET_REQUEST_STATS_CMD_GET_IPV4,
715 	NET_REQUEST_STATS_CMD_GET_IPV6,
716 	NET_REQUEST_STATS_CMD_GET_IPV6_ND,
717 	NET_REQUEST_STATS_CMD_GET_IPV6_PMTU,
718 	NET_REQUEST_STATS_CMD_GET_IPV4_PMTU,
719 	NET_REQUEST_STATS_CMD_GET_ICMP,
720 	NET_REQUEST_STATS_CMD_GET_UDP,
721 	NET_REQUEST_STATS_CMD_GET_TCP,
722 	NET_REQUEST_STATS_CMD_GET_ETHERNET,
723 	NET_REQUEST_STATS_CMD_GET_PPP,
724 	NET_REQUEST_STATS_CMD_GET_PM,
725 	NET_REQUEST_STATS_CMD_GET_WIFI,
726 	NET_REQUEST_STATS_CMD_RESET_WIFI,
727 };
728 
729 /** @endcond */
730 
731 /** Request all network statistics */
732 #define NET_REQUEST_STATS_GET_ALL				\
733 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_ALL)
734 
735 /** Request all processing error statistics */
736 #define NET_REQUEST_STATS_GET_PROCESSING_ERROR				\
737 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_PROCESSING_ERROR)
738 
739 /** Request number of received and sent bytes */
740 #define NET_REQUEST_STATS_GET_BYTES				\
741 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_BYTES)
742 
743 /** Request IP error statistics */
744 #define NET_REQUEST_STATS_GET_IP_ERRORS				\
745 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IP_ERRORS)
746 
747 /** @cond INTERNAL_HIDDEN */
748 
749 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ALL);
750 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PROCESSING_ERROR);
751 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_BYTES);
752 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IP_ERRORS);
753 
754 /** @endcond */
755 
756 #if defined(CONFIG_NET_STATISTICS_IPV4)
757 /** Request IPv4 statistics */
758 #define NET_REQUEST_STATS_GET_IPV4				\
759 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV4)
760 
761 /** @cond INTERNAL_HIDDEN */
762 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV4);
763 /** @endcond */
764 #endif /* CONFIG_NET_STATISTICS_IPV4 */
765 
766 #if defined(CONFIG_NET_STATISTICS_IPV6)
767 /** Request IPv6 statistics */
768 #define NET_REQUEST_STATS_GET_IPV6				\
769 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV6)
770 
771 /** @cond INTERNAL_HIDDEN */
772 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6);
773 /** @endcond */
774 #endif /* CONFIG_NET_STATISTICS_IPV6 */
775 
776 #if defined(CONFIG_NET_STATISTICS_IPV6_ND)
777 /** Request IPv6 neighbor discovery statistics */
778 #define NET_REQUEST_STATS_GET_IPV6_ND				\
779 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV6_ND)
780 
781 /** @cond INTERNAL_HIDDEN */
782 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6_ND);
783 /** @endcond */
784 #endif /* CONFIG_NET_STATISTICS_IPV6_ND */
785 
786 #if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
787 /** Request IPv6 Path MTU Discovery statistics */
788 #define NET_REQUEST_STATS_GET_IPV6_PMTU				\
789 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV6_PMTU)
790 
791 /** @cond INTERNAL_HIDDEN */
792 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV6_PMTU);
793 /** @endcond */
794 #endif /* CONFIG_NET_STATISTICS_IPV6_PMTU */
795 
796 #if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
797 /** Request IPv4 Path MTU Discovery statistics */
798 #define NET_REQUEST_STATS_GET_IPV4_PMTU				\
799 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_IPV4_PMTU)
800 
801 /** @cond INTERNAL_HIDDEN */
802 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_IPV4_PMTU);
803 /** @endcond */
804 #endif /* CONFIG_NET_STATISTICS_IPV4_PMTU */
805 
806 #if defined(CONFIG_NET_STATISTICS_ICMP)
807 /** Request ICMPv4 and ICMPv6 statistics */
808 #define NET_REQUEST_STATS_GET_ICMP				\
809 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_ICMP)
810 
811 /** @cond INTERNAL_HIDDEN */
812 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ICMP);
813 /** @endcond */
814 #endif /* CONFIG_NET_STATISTICS_ICMP */
815 
816 #if defined(CONFIG_NET_STATISTICS_UDP)
817 /** Request UDP statistics */
818 #define NET_REQUEST_STATS_GET_UDP				\
819 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_UDP)
820 
821 /** @cond INTERNAL_HIDDEN */
822 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_UDP);
823 /** @endcond */
824 #endif /* CONFIG_NET_STATISTICS_UDP */
825 
826 #if defined(CONFIG_NET_STATISTICS_TCP)
827 /** Request TCP statistics */
828 #define NET_REQUEST_STATS_GET_TCP				\
829 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_TCP)
830 
831 /** @cond INTERNAL_HIDDEN */
832 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_TCP);
833 /** @endcond */
834 #endif /* CONFIG_NET_STATISTICS_TCP */
835 
836 #if defined(CONFIG_NET_STATISTICS_ETHERNET)
837 /** Request Ethernet statistics */
838 #define NET_REQUEST_STATS_GET_ETHERNET				\
839 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_ETHERNET)
840 
841 /** @cond INTERNAL_HIDDEN */
842 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_ETHERNET);
843 /** @endcond */
844 #endif /* CONFIG_NET_STATISTICS_ETHERNET */
845 
846 #if defined(CONFIG_NET_STATISTICS_PPP)
847 /** Request PPP statistics */
848 #define NET_REQUEST_STATS_GET_PPP				\
849 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_PPP)
850 
851 /** @cond INTERNAL_HIDDEN */
852 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PPP);
853 /** @endcond */
854 #endif /* CONFIG_NET_STATISTICS_PPP */
855 
856 #endif /* CONFIG_NET_STATISTICS_USER_API */
857 
858 #if defined(CONFIG_NET_STATISTICS_POWER_MANAGEMENT)
859 /** Request network power management statistics */
860 #define NET_REQUEST_STATS_GET_PM				\
861 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_PM)
862 
863 /** @cond INTERNAL_HIDDEN */
864 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_PM);
865 /** @endcond */
866 #endif /* CONFIG_NET_STATISTICS_POWER_MANAGEMENT */
867 
868 #if defined(CONFIG_NET_STATISTICS_WIFI)
869 /** Request Wi-Fi statistics */
870 #define NET_REQUEST_STATS_GET_WIFI				\
871 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_GET_WIFI)
872 
873 /** @cond INTERNAL_HIDDEN */
874 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_GET_WIFI);
875 /** @endcond */
876 
877 /** Reset Wi-Fi statistics*/
878 #define NET_REQUEST_STATS_RESET_WIFI                              \
879 	(_NET_STATS_BASE | NET_REQUEST_STATS_CMD_RESET_WIFI)
880 
881 /** @cond INTERNAL_HIDDEN */
882 NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_STATS_RESET_WIFI);
883 /** @endcond */
884 #endif /* CONFIG_NET_STATISTICS_WIFI */
885 
886 #define NET_STATS_GET_METRIC_NAME(_name) _name
887 #define NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx) net_stats_##dev_id##_##sfx##_collector
888 #define NET_STATS_GET_VAR(dev_id, sfx, var) zephyr_net_##var
889 #define NET_STATS_GET_INSTANCE(dev_id, sfx, _not_used) STRINGIFY(_##dev_id##_##sfx)
890 
891 /* The label value is set to be the network interface name. Note that we skip
892  * the first character (_) when setting the label value. This can be changed
893  * if there is a way to token paste the instance name without the prefix character.
894  * Note also that the below macros have some parameters that are not used atm.
895  */
896 #define NET_STATS_PROMETHEUS_COUNTER_DEFINE(_desc, _labelval, _not_used,	\
897 					    _collector, _name, _stat_var_ptr)	\
898 	static PROMETHEUS_COUNTER_DEFINE(					\
899 		NET_STATS_GET_METRIC_NAME(_name),				\
900 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
901 		&(_collector), _stat_var_ptr)
902 
903 #define NET_STATS_PROMETHEUS_GAUGE_DEFINE(_desc,  _labelval, _not_used,		\
904 					  _collector, _name, _stat_var_ptr)	\
905 	static PROMETHEUS_GAUGE_DEFINE(						\
906 		NET_STATS_GET_METRIC_NAME(_name),				\
907 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
908 		&(_collector), _stat_var_ptr)
909 
910 #define NET_STATS_PROMETHEUS_SUMMARY_DEFINE(_desc,  _labelval, _not_used,	\
911 					    _collector, _name, _stat_var_ptr)	\
912 	static PROMETHEUS_SUMMARY_DEFINE(					\
913 		NET_STATS_GET_METRIC_NAME(_name),				\
914 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
915 		&(_collector), _stat_var_ptr)
916 
917 #define NET_STATS_PROMETHEUS_HISTOGRAM_DEFINE(_desc, _labelval, _not_used,	\
918 					      _collector, _name, _stat_var_ptr)	\
919 	static PROMETHEUS_HISTOGRAM_DEFINE(					\
920 		NET_STATS_GET_METRIC_NAME(_name),				\
921 		_desc, ({ .key = "nic", .value = &_labelval[1] }),		\
922 		&(_collector), _stat_var_ptr)
923 
924 /* IPv6 layer statistics */
925 #if defined(CONFIG_NET_STATISTICS_IPV6)
926 #define NET_STATS_PROMETHEUS_IPV6(iface, dev_id, sfx)			\
927 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
928 		"IPv6 packets sent",					\
929 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_sent),		\
930 		"packet_count",						\
931 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
932 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_sent),		\
933 		&(iface)->stats.ipv6.sent);				\
934 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
935 		"IPv6 packets received",				\
936 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_recv),		\
937 		"packet_count",						\
938 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
939 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_recv),		\
940 		&(iface)->stats.ipv6.recv);				\
941 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
942 		"IPv6 packets dropped",					\
943 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_drop),		\
944 		"packet_count",						\
945 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
946 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_drop),		\
947 		&(iface)->stats.ipv6.drop);				\
948 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
949 		"IPv6 packets forwarded",				\
950 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_forward),	\
951 		"packet_count",						\
952 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
953 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_forwarded),		\
954 		&(iface)->stats.ipv6.forwarded)
955 #else
956 #define NET_STATS_PROMETHEUS_IPV6(iface, dev_id, sfx)
957 #endif
958 
959 /* IPv4 layer statistics */
960 #if defined(CONFIG_NET_STATISTICS_IPV4)
961 #define NET_STATS_PROMETHEUS_IPV4(iface, dev_id, sfx)			\
962 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
963 		"IPv4 packets sent",					\
964 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_sent),		\
965 		"packet_count",						\
966 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
967 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_sent),		\
968 		&(iface)->stats.ipv4.sent);				\
969 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
970 		"IPv4 packets received",				\
971 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_recv),		\
972 		"packet_count",						\
973 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
974 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_recv),		\
975 		&(iface)->stats.ipv4.recv);				\
976 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
977 		"IPv4 packets dropped",					\
978 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_drop),		\
979 		"packet_count",						\
980 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
981 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_drop),		\
982 		&(iface)->stats.ipv4.drop);				\
983 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
984 		"IPv4 packets forwarded",				\
985 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_forwarded),	\
986 		"packet_count",						\
987 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
988 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_forwarded),		\
989 		&(iface)->stats.ipv4.forwarded)
990 #else
991 #define NET_STATS_PROMETHEUS_IPV4(iface, dev_id, sfx)
992 #endif
993 
994 /* ICMP layer statistics */
995 #if defined(CONFIG_NET_STATISTICS_ICMP)
996 #define NET_STATS_PROMETHEUS_ICMP(iface, dev_id, sfx)			\
997 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
998 		"ICMP packets sent",					\
999 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_sent),		\
1000 		"packet_count",						\
1001 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1002 		NET_STATS_GET_VAR(dev_id, sfx, icmp_sent),		\
1003 		&(iface)->stats.icmp.sent);				\
1004 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1005 		"ICMP packets received",				\
1006 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_recv),		\
1007 		"packet_count",						\
1008 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1009 		NET_STATS_GET_VAR(dev_id, sfx, icmp_recv),		\
1010 		&(iface)->stats.icmp.recv);				\
1011 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1012 		"ICMP packets dropped",					\
1013 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_drop),		\
1014 		"packet_count",						\
1015 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1016 		NET_STATS_GET_VAR(dev_id, sfx, icmp_drop),		\
1017 		&(iface)->stats.icmp.drop);				\
1018 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1019 		"ICMP packets checksum error",				\
1020 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_chkerr),	\
1021 		"packet_count",						\
1022 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1023 		NET_STATS_GET_VAR(dev_id, sfx, icmp_chkerr),		\
1024 		&(iface)->stats.icmp.chkerr);				\
1025 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1026 		"ICMP packets type error",				\
1027 		NET_STATS_GET_INSTANCE(dev_id, sfx, icmp_typeerr),	\
1028 		"packet_count",						\
1029 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1030 		NET_STATS_GET_VAR(dev_id, sfx, icmp_typeerr),		\
1031 		&(iface)->stats.icmp.typeerr)
1032 #else
1033 #define NET_STATS_PROMETHEUS_ICMP(iface, dev_id, sfx)
1034 #endif
1035 
1036 /* UDP layer statistics */
1037 #if defined(CONFIG_NET_STATISTICS_UDP)
1038 #define NET_STATS_PROMETHEUS_UDP(iface, dev_id, sfx)			\
1039 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1040 		"UDP packets sent",					\
1041 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_sent),		\
1042 		"packet_count",						\
1043 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1044 		NET_STATS_GET_VAR(dev_id, sfx, udp_sent),		\
1045 		&(iface)->stats.udp.sent);				\
1046 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1047 		"UDP packets received",					\
1048 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_recv),		\
1049 		"packet_count",						\
1050 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1051 		NET_STATS_GET_VAR(dev_id, sfx, udp_recv),		\
1052 		&(iface)->stats.udp.recv);				\
1053 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1054 		"UDP packets dropped",					\
1055 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_drop),		\
1056 		"packet_count",						\
1057 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1058 		NET_STATS_GET_VAR(dev_id, sfx, udp_drop),		\
1059 		&(iface)->stats.udp.drop);				\
1060 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1061 		"UDP packets checksum error",				\
1062 		NET_STATS_GET_INSTANCE(dev_id, sfx, udp_chkerr),	\
1063 		"packet_count",						\
1064 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1065 		NET_STATS_GET_VAR(dev_id, sfx, udp_chkerr),		\
1066 		&(iface)->stats.udp.chkerr)
1067 #else
1068 #define NET_STATS_PROMETHEUS_UDP(iface, dev_id, sfx)
1069 #endif
1070 
1071 /* TCP layer statistics */
1072 #if defined(CONFIG_NET_STATISTICS_TCP)
1073 #define NET_STATS_PROMETHEUS_TCP(iface, dev_id, sfx)			\
1074 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1075 		"TCP bytes sent",					\
1076 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_bytes_sent),	\
1077 		"byte_count",						\
1078 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1079 		NET_STATS_GET_VAR(dev_id, sfx, tcp_bytes_sent),		\
1080 		&(iface)->stats.tcp.bytes.sent);			\
1081 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1082 		"TCP bytes received",					\
1083 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_bytes_recv),	\
1084 		"byte_count",						\
1085 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1086 		NET_STATS_GET_VAR(dev_id, sfx, tcp_bytes_recv),		\
1087 		&(iface)->stats.tcp.bytes.received);			\
1088 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1089 		"TCP bytes resent",					\
1090 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_bytes_resent),	\
1091 		"byte_count",						\
1092 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1093 		NET_STATS_GET_VAR(dev_id, sfx, tcp_bytes_resent),	\
1094 		&(iface)->stats.tcp.resent);				\
1095 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1096 		"TCP packets sent",					\
1097 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_sent),		\
1098 		"packet_count",						\
1099 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1100 		NET_STATS_GET_VAR(dev_id, sfx, tcp_sent),		\
1101 		&(iface)->stats.tcp.sent);				\
1102 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1103 		"TCP packets received",					\
1104 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_recv),		\
1105 		"packet_count",						\
1106 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1107 		NET_STATS_GET_VAR(dev_id, sfx, tcp_recv),		\
1108 		&(iface)->stats.tcp.recv);				\
1109 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1110 		"TCP packets dropped",					\
1111 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_drop),		\
1112 		"packet_count",						\
1113 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1114 		NET_STATS_GET_VAR(dev_id, sfx, tcp_drop),		\
1115 		&(iface)->stats.tcp.drop);				\
1116 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1117 		"TCP packets checksum error",				\
1118 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_chkerr),	\
1119 		"packet_count",						\
1120 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1121 		NET_STATS_GET_VAR(dev_id, sfx, tcp_chkerr),		\
1122 		&(iface)->stats.tcp.chkerr);				\
1123 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1124 		"TCP packets ack error",				\
1125 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_ackerr),	\
1126 		"packet_count",						\
1127 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1128 		NET_STATS_GET_VAR(dev_id, sfx, tcp_ackerr),		\
1129 		&(iface)->stats.tcp.ackerr);				\
1130 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1131 		"TCP packets reset error",				\
1132 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_rsterr),	\
1133 		"packet_count",						\
1134 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1135 		NET_STATS_GET_VAR(dev_id, sfx, tcp_rsterr),		\
1136 		&(iface)->stats.tcp.rsterr);				\
1137 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1138 		"TCP packets retransmitted",				\
1139 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_rexmit),	\
1140 		"packet_count",						\
1141 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1142 		NET_STATS_GET_VAR(dev_id, sfx, tcp_rexmit),		\
1143 		&(iface)->stats.tcp.rexmit);				\
1144 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1145 		"TCP reset received",					\
1146 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_rst_recv),	\
1147 		"packet_count",						\
1148 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1149 		NET_STATS_GET_VAR(dev_id, sfx, tcp_rst),		\
1150 		&(iface)->stats.tcp.rst);				\
1151 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1152 		"TCP connection drop",					\
1153 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_conndrop),	\
1154 		"packet_count",						\
1155 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1156 		NET_STATS_GET_VAR(dev_id, sfx, tcp_conndrop),		\
1157 		&(iface)->stats.tcp.conndrop);				\
1158 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1159 		"TCP connection reset",					\
1160 		NET_STATS_GET_INSTANCE(dev_id, sfx, tcp_connrst),	\
1161 		"packet_count",						\
1162 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1163 		NET_STATS_GET_VAR(dev_id, sfx, tcp_connrst),		\
1164 		&(iface)->stats.tcp.connrst)
1165 #else
1166 #define NET_STATS_PROMETHEUS_TCP(iface, dev_id, sfx)
1167 #endif
1168 
1169 /* IPv6 Neighbor Discovery statistics */
1170 #if defined(CONFIG_NET_STATISTICS_IPV6_ND)
1171 #define NET_STATS_PROMETHEUS_IPV6_ND(iface, dev_id, sfx)		\
1172 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1173 		"IPv6 ND packets sent",					\
1174 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_nd_sent),	\
1175 		"packet_count",						\
1176 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1177 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_nd_sent),		\
1178 		&(iface)->stats.ipv6_nd.sent);				\
1179 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1180 		"IPv6 ND packets received",				\
1181 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_nd_recv),	\
1182 		"packet_count",						\
1183 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1184 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_nd_recv),		\
1185 		&(iface)->stats.ipv6_nd.recv);				\
1186 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1187 		"IPv6 ND packets dropped",				\
1188 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_nd_drop),	\
1189 		"packet_count",						\
1190 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1191 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_nd_drop),		\
1192 		&(iface)->stats.ipv6_nd.drop)
1193 #else
1194 #define NET_STATS_PROMETHEUS_IPV6_ND(iface, dev_id, sfx)
1195 #endif
1196 
1197 /* IPv6 Path MTU Discovery statistics */
1198 #if defined(CONFIG_NET_STATISTICS_IPV6_PMTU)
1199 #define NET_STATS_PROMETHEUS_IPV6_PMTU(iface, dev_id, sfx)		\
1200 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1201 		"IPv6 PMTU packets sent",				\
1202 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_pmtu_sent),	\
1203 		"packet_count",						\
1204 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1205 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_pmtu_sent),		\
1206 		&(iface)->stats.ipv6_pmtu.sent);			\
1207 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1208 		"IPv6 PMTU packets received",				\
1209 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_pmtu_recv),	\
1210 		"packet_count",						\
1211 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1212 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_pmtu_recv),		\
1213 		&(iface)->stats.ipv6_pmtu.recv);			\
1214 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1215 		"IPv6 PMTU packets dropped",				\
1216 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_pmtu_drop),	\
1217 		"packet_count",						\
1218 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1219 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_pmtu_drop),		\
1220 		&(iface)->stats.ipv6_pmtu.drop)
1221 #else
1222 #define NET_STATS_PROMETHEUS_IPV6_PMTU(iface, dev_id, sfx)
1223 #endif
1224 
1225 /* IPv4 Path MTU Discovery statistics */
1226 #if defined(CONFIG_NET_STATISTICS_IPV4_PMTU)
1227 #define NET_STATS_PROMETHEUS_IPV4_PMTU(iface, dev_id, sfx)		\
1228 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1229 		"IPv4 PMTU packets sent",				\
1230 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_pmtu_sent),	\
1231 		"packet_count",						\
1232 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1233 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_pmtu_sent),		\
1234 		&(iface)->stats.ipv4_pmtu.sent);			\
1235 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1236 		"IPv4 PMTU packets received",				\
1237 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_pmtu_recv),	\
1238 		"packet_count",						\
1239 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1240 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_pmtu_recv),		\
1241 		&(iface)->stats.ipv4_pmtu.recv);			\
1242 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1243 		"IPv4 PMTU packets dropped",				\
1244 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_pmtu_drop),	\
1245 		"packet_count",						\
1246 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1247 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_pmtu_drop),		\
1248 		&(iface)->stats.ipv4_pmtu.drop)
1249 #else
1250 #define NET_STATS_PROMETHEUS_IPV4_PMTU(iface, dev_id, sfx)
1251 #endif
1252 
1253 /* IPv6 Multicast Listener Discovery statistics */
1254 #if defined(CONFIG_NET_STATISTICS_MLD)
1255 #define NET_STATS_PROMETHEUS_MLD(iface, dev_id, sfx)			\
1256 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1257 		"IPv6 MLD packets sent",				\
1258 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_mld_sent),	\
1259 		"packet_count",						\
1260 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1261 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_mld_sent),		\
1262 		&(iface)->stats.ipv6_mld.sent);				\
1263 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1264 		"IPv6 MLD packets received",				\
1265 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_mld_recv),	\
1266 		"packet_count",						\
1267 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1268 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_mld_recv),		\
1269 		&(iface)->stats.ipv6_mld.recv);				\
1270 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1271 		"IPv6 MLD packets dropped",				\
1272 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv6_mld_drop),	\
1273 		"packet_count",						\
1274 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1275 		NET_STATS_GET_VAR(dev_id, sfx, ipv6_mld_drop),		\
1276 		&(iface)->stats.ipv6_mld.drop)
1277 #else
1278 #define NET_STATS_PROMETHEUS_MLD(iface, dev_id, sfx)
1279 #endif
1280 
1281 /* IPv4 IGMP statistics */
1282 #if defined(CONFIG_NET_STATISTICS_IGMP)
1283 #define NET_STATS_PROMETHEUS_IGMP(iface, dev_id, sfx)			\
1284 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1285 		"IPv4 IGMP packets sent",				\
1286 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_igmp_sent),	\
1287 		"packet_count",						\
1288 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1289 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_igmp_sent),		\
1290 		&(iface)->stats.ipv4_igmp.sent);			\
1291 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1292 		"IPv4 IGMP packets received",				\
1293 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_igmp_recv),	\
1294 		"packet_count",						\
1295 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1296 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_igmp_recv),		\
1297 		&(iface)->stats.ipv4_igmp.recv);			\
1298 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1299 		"IPv4 IGMP packets dropped",				\
1300 		NET_STATS_GET_INSTANCE(dev_id, sfx, ipv4_igmp_drop),	\
1301 		"packet_count",						\
1302 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1303 		NET_STATS_GET_VAR(dev_id, sfx, ipv4_igmp_drop),		\
1304 		&(iface)->stats.ipv4_igmp.drop)
1305 #else
1306 #define NET_STATS_PROMETHEUS_IGMP(iface, dev_id, sfx)
1307 #endif
1308 
1309 /* DNS statistics */
1310 #if defined(CONFIG_NET_STATISTICS_DNS)
1311 #define NET_STATS_PROMETHEUS_DNS(iface, dev_id, sfx)			\
1312 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1313 		"DNS packets sent",					\
1314 		NET_STATS_GET_INSTANCE(dev_id, sfx, dns_sent),		\
1315 		"packet_count",						\
1316 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1317 		NET_STATS_GET_VAR(dev_id, sfx, dns_sent),		\
1318 		&(iface)->stats.dns.sent);				\
1319 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1320 		"DNS packets received",					\
1321 		NET_STATS_GET_INSTANCE(dev_id, sfx, dns_recv),		\
1322 		"packet_count",						\
1323 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1324 		NET_STATS_GET_VAR(dev_id, sfx, dns_recv),		\
1325 		&(iface)->stats.dns.recv);				\
1326 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1327 		"DNS packets dropped",					\
1328 		NET_STATS_GET_INSTANCE(dev_id, sfx, dns_drop),		\
1329 		"packet_count",						\
1330 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1331 		NET_STATS_GET_VAR(dev_id, sfx, dns_drop),		\
1332 		&(iface)->stats.dns.drop)
1333 #else
1334 #define NET_STATS_PROMETHEUS_DNS(iface, dev_id, sfx)
1335 #endif
1336 
1337 /* TX time statistics */
1338 #if defined(CONFIG_NET_PKT_TXTIME_STATS)
1339 #define NET_STATS_PROMETHEUS_TX_TIME(iface, dev_id, sfx)		\
1340 	NET_STATS_PROMETHEUS_SUMMARY_DEFINE(				\
1341 		"TX time in microseconds",				\
1342 		NET_STATS_GET_INSTANCE(dev_id, sfx, tx_time),		\
1343 		"time",							\
1344 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1345 		NET_STATS_GET_VAR(dev_id, sfx, tx_time),		\
1346 		&(iface)->stats.tx_time)
1347 #else
1348 #define NET_STATS_PROMETHEUS_TX_TIME(iface, dev_id, sfx)
1349 #endif
1350 
1351 /* RX time statistics */
1352 #if defined(CONFIG_NET_PKT_RXTIME_STATS)
1353 #define NET_STATS_PROMETHEUS_RX_TIME(iface, dev_id, sfx)		\
1354 	NET_STATS_PROMETHEUS_SUMMARY_DEFINE(				\
1355 		"RX time in microseconds",				\
1356 		NET_STATS_GET_INSTANCE(dev_id, sfx, rx_time),		\
1357 		"time",							\
1358 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1359 		NET_STATS_GET_VAR(dev_id, sfx, rx_time),		\
1360 		&(iface)->stats.rx_time)
1361 #else
1362 #define NET_STATS_PROMETHEUS_RX_TIME(iface, dev_id, sfx)
1363 #endif
1364 
1365 /* Per network interface statistics via Prometheus */
1366 #define NET_STATS_PROMETHEUS(iface, dev_id, sfx)			\
1367 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1368 		"Processing error",					\
1369 		NET_STATS_GET_INSTANCE(dev_id, sfx, process_error),	\
1370 		"error_count",						\
1371 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1372 		NET_STATS_GET_VAR(dev_id, sfx, processing_error),	\
1373 		&(iface)->stats.processing_error);			\
1374 	/* IP layer error statistics */					\
1375 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1376 		"IP proto error",					\
1377 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_proto_error),	\
1378 		"error_count",						\
1379 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1380 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_protoerr),	\
1381 		&(iface)->stats.ip_errors.protoerr);			\
1382 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1383 		"IP version/header len error",				\
1384 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_vhl_error),	\
1385 		"error_count",						\
1386 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1387 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_vhlerr),	\
1388 		&(iface)->stats.ip_errors.vhlerr);			\
1389 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1390 		"IP header len error (high byte)",			\
1391 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_hblen_error),	\
1392 		"error_count",						\
1393 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1394 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_hblenerr),	\
1395 		&(iface)->stats.ip_errors.hblenerr);			\
1396 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1397 		"IP header len error (low byte)",			\
1398 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_lblen_error),	\
1399 		"error_count",						\
1400 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1401 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_lblenerr),	\
1402 		&(iface)->stats.ip_errors.lblenerr);			\
1403 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1404 		"IP fragment error",					\
1405 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_frag_error),	\
1406 		"error_count",						\
1407 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1408 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_fragerr),	\
1409 		&(iface)->stats.ip_errors.fragerr);			\
1410 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1411 		"IP checksum error",					\
1412 		NET_STATS_GET_INSTANCE(dev_id, sfx, ip_chk_error),	\
1413 		"error_count",						\
1414 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1415 		NET_STATS_GET_VAR(dev_id, sfx, ip_errors_chkerr),	\
1416 		&(iface)->stats.ip_errors.chkerr);			\
1417 	/* General network statistics */				\
1418 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1419 		"Bytes received",					\
1420 		NET_STATS_GET_INSTANCE(dev_id, sfx, bytes_recv),	\
1421 		"byte_count",						\
1422 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1423 		NET_STATS_GET_VAR(dev_id, sfx, bytes_recv),		\
1424 		&(iface)->stats.bytes.received);			\
1425 	NET_STATS_PROMETHEUS_COUNTER_DEFINE(				\
1426 		"Bytes sent",						\
1427 		NET_STATS_GET_INSTANCE(dev_id, sfx, bytes_sent),	\
1428 		"byte_count",						\
1429 		NET_STATS_GET_COLLECTOR_NAME(dev_id, sfx),		\
1430 		NET_STATS_GET_VAR(dev_id, sfx, bytes_sent),		\
1431 		&(iface)->stats.bytes.sent);				\
1432 	NET_STATS_PROMETHEUS_IPV6(iface, dev_id, sfx);			\
1433 	NET_STATS_PROMETHEUS_IPV4(iface, dev_id, sfx);			\
1434 	NET_STATS_PROMETHEUS_ICMP(iface, dev_id, sfx);			\
1435 	NET_STATS_PROMETHEUS_UDP(iface, dev_id, sfx);			\
1436 	NET_STATS_PROMETHEUS_TCP(iface, dev_id, sfx);			\
1437 	NET_STATS_PROMETHEUS_IPV6_ND(iface, dev_id, sfx);		\
1438 	NET_STATS_PROMETHEUS_IPV6_PMTU(iface, dev_id, sfx);		\
1439 	NET_STATS_PROMETHEUS_IPV4_PMTU(iface, dev_id, sfx);		\
1440 	NET_STATS_PROMETHEUS_MLD(iface, dev_id, sfx);			\
1441 	NET_STATS_PROMETHEUS_IGMP(iface, dev_id, sfx);			\
1442 	NET_STATS_PROMETHEUS_DNS(iface, dev_id, sfx);			\
1443 	NET_STATS_PROMETHEUS_TX_TIME(iface, dev_id, sfx);		\
1444 	NET_STATS_PROMETHEUS_RX_TIME(iface, dev_id, sfx)
1445 
1446 /**
1447  * @}
1448  */
1449 
1450 #ifdef __cplusplus
1451 }
1452 #endif
1453 
1454 #endif /* ZEPHYR_INCLUDE_NET_NET_STATS_H_ */
1455