2 * Copyright (c) 2010-2015 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
30 #include <netinet/in.h>
32 #include <net/if_var.h>
33 #include <netinet/tcp.h>
37 #pragma mark -- Common Data Structures --
39 #define __NSTAT_REVISION__ 7
41 typedef u_int32_t nstat_provider_id_t
;
42 typedef u_int32_t nstat_src_ref_t
;
44 typedef struct nstat_counts
47 u_int64_t nstat_rxpackets
__attribute__((aligned(8)));
48 u_int64_t nstat_rxbytes
__attribute__((aligned(8)));
49 u_int64_t nstat_txpackets
__attribute__((aligned(8)));
50 u_int64_t nstat_txbytes
__attribute__((aligned(8)));
52 u_int32_t nstat_rxduplicatebytes
;
53 u_int32_t nstat_rxoutoforderbytes
;
54 u_int32_t nstat_txretransmit
;
56 u_int32_t nstat_connectattempts
;
57 u_int32_t nstat_connectsuccesses
;
59 u_int32_t nstat_min_rtt
;
60 u_int32_t nstat_avg_rtt
;
61 u_int32_t nstat_var_rtt
;
63 u_int64_t nstat_cell_rxbytes
__attribute__((aligned(8)));
64 u_int64_t nstat_cell_txbytes
__attribute__((aligned(8)));
65 u_int64_t nstat_wifi_rxbytes
__attribute__((aligned(8)));
66 u_int64_t nstat_wifi_txbytes
__attribute__((aligned(8)));
67 u_int64_t nstat_wired_rxbytes
__attribute__((aligned(8)));
68 u_int64_t nstat_wired_txbytes
__attribute__((aligned(8)));
71 typedef struct nstat_sysinfo_keyval
73 u_int32_t nstat_sysinfo_key
;
74 u_int32_t nstat_sysinfo_flags
;
76 int64_t nstat_sysinfo_scalar
;
77 double nstat_sysinfo_distribution
;
79 } __attribute__((packed
)) nstat_sysinfo_keyval
;
81 #define NSTAT_SYSINFO_FLAG_SCALAR 0x0001
82 #define NSTAT_SYSINFO_FLAG_DISTRIBUTION 0x0002
84 #define NSTAT_MAX_MSG_SIZE 4096
86 typedef struct nstat_sysinfo_counts
89 u_int32_t nstat_sysinfo_len
;
91 u_int8_t nstat_sysinfo_keyvals
[];
92 } __attribute__((packed
)) nstat_sysinfo_counts
;
96 NSTAT_SYSINFO_KEY_MBUF_256B_TOTAL
= 1
97 ,NSTAT_SYSINFO_KEY_MBUF_2KB_TOTAL
= 2
98 ,NSTAT_SYSINFO_KEY_MBUF_4KB_TOTAL
= 3
99 ,NSTAT_SYSINFO_KEY_SOCK_MBCNT
= 4
100 ,NSTAT_SYSINFO_KEY_SOCK_ATMBLIMIT
= 5
101 ,NSTAT_SYSINFO_KEY_IPV4_AVGRTT
= 6
102 ,NSTAT_SYSINFO_KEY_IPV6_AVGRTT
= 7
103 ,NSTAT_SYSINFO_KEY_SEND_PLR
= 8
104 ,NSTAT_SYSINFO_KEY_RECV_PLR
= 9
105 ,NSTAT_SYSINFO_KEY_SEND_TLRTO
= 10
106 ,NSTAT_SYSINFO_KEY_SEND_REORDERRATE
= 11
107 ,NSTAT_SYSINFO_CONNECTION_ATTEMPTS
= 12
108 ,NSTAT_SYSINFO_CONNECTION_ACCEPTS
= 13
109 ,NSTAT_SYSINFO_ECN_CLIENT_SETUP
= 14
110 ,NSTAT_SYSINFO_ECN_SERVER_SETUP
= 15
111 ,NSTAT_SYSINFO_ECN_CLIENT_SUCCESS
= 16
112 ,NSTAT_SYSINFO_ECN_SERVER_SUCCESS
= 17
113 ,NSTAT_SYSINFO_ECN_NOT_SUPPORTED
= 18
114 ,NSTAT_SYSINFO_ECN_LOST_SYN
= 19
115 ,NSTAT_SYSINFO_ECN_LOST_SYNACK
= 20
116 ,NSTAT_SYSINFO_ECN_RECV_CE
= 21
117 ,NSTAT_SYSINFO_ECN_RECV_ECE
= 22
118 ,NSTAT_SYSINFO_ECN_SENT_ECE
= 23
119 ,NSTAT_SYSINFO_ECN_CONN_RECV_CE
= 24
120 ,NSTAT_SYSINFO_ECN_CONN_PLNOCE
= 25
121 ,NSTAT_SYSINFO_ECN_CONN_PL_CE
= 26
122 ,NSTAT_SYSINFO_ECN_CONN_NOPL_CE
= 27
123 ,NSTAT_SYSINFO_MBUF_16KB_TOTAL
= 28
124 ,NSTAT_SYSINFO_ECN_CLIENT_ENABLED
= 29
125 ,NSTAT_SYSINFO_ECN_SERVER_ENABLED
= 30
126 ,NSTAT_SYSINFO_ECN_CONN_RECV_ECE
= 31
127 ,NSTAT_SYSINFO_MBUF_MEM_RELEASED
= 32
128 ,NSTAT_SYSINFO_MBUF_DRAIN_CNT
= 33
129 ,NSTAT_SYSINFO_TFO_SYN_DATA_RCV
= 34
130 ,NSTAT_SYSINFO_TFO_COOKIE_REQ_RCV
= 35
131 ,NSTAT_SYSINFO_TFO_COOKIE_SENT
= 36
132 ,NSTAT_SYSINFO_TFO_COOKIE_INVALID
= 37
133 ,NSTAT_SYSINFO_TFO_COOKIE_REQ
= 38
134 ,NSTAT_SYSINFO_TFO_COOKIE_RCV
= 39
135 ,NSTAT_SYSINFO_TFO_SYN_DATA_SENT
= 40
136 ,NSTAT_SYSINFO_TFO_SYN_DATA_ACKED
= 41
137 ,NSTAT_SYSINFO_TFO_SYN_LOSS
= 42
138 ,NSTAT_SYSINFO_TFO_BLACKHOLE
= 43
139 ,NSTAT_SYSINFO_ECN_FALLBACK_SYNLOSS
= 44
140 ,NSTAT_SYSINFO_ECN_FALLBACK_REORDER
= 45
141 ,NSTAT_SYSINFO_ECN_FALLBACK_CE
= 46
142 ,NSTAT_SYSINFO_ECN_IFNET_TYPE
= 47
143 ,NSTAT_SYSINFO_ECN_IFNET_PROTO
= 48
144 ,NSTAT_SYSINFO_ECN_IFNET_CLIENT_SETUP
= 49
145 ,NSTAT_SYSINFO_ECN_IFNET_SERVER_SETUP
= 50
146 ,NSTAT_SYSINFO_ECN_IFNET_CLIENT_SUCCESS
= 51
147 ,NSTAT_SYSINFO_ECN_IFNET_SERVER_SUCCESS
= 52
148 ,NSTAT_SYSINFO_ECN_IFNET_PEER_NOSUPPORT
= 53
149 ,NSTAT_SYSINFO_ECN_IFNET_SYN_LOST
= 54
150 ,NSTAT_SYSINFO_ECN_IFNET_SYNACK_LOST
= 55
151 ,NSTAT_SYSINFO_ECN_IFNET_RECV_CE
= 56
152 ,NSTAT_SYSINFO_ECN_IFNET_RECV_ECE
= 57
153 ,NSTAT_SYSINFO_ECN_IFNET_SENT_ECE
= 58
154 ,NSTAT_SYSINFO_ECN_IFNET_CONN_RECV_CE
= 59
155 ,NSTAT_SYSINFO_ECN_IFNET_CONN_RECV_ECE
= 60
156 ,NSTAT_SYSINFO_ECN_IFNET_CONN_PLNOCE
= 61
157 ,NSTAT_SYSINFO_ECN_IFNET_CONN_PLCE
= 62
158 ,NSTAT_SYSINFO_ECN_IFNET_CONN_NOPLCE
= 63
159 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_SYNLOSS
= 64
160 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_REORDER
= 65
161 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_CE
= 66
162 ,NSTAT_SYSINFO_ECN_IFNET_ON_RTT_AVG
= 67
163 ,NSTAT_SYSINFO_ECN_IFNET_ON_RTT_VAR
= 68
164 ,NSTAT_SYSINFO_ECN_IFNET_ON_OOPERCENT
= 69
165 ,NSTAT_SYSINFO_ECN_IFNET_ON_SACK_EPISODE
= 70
166 ,NSTAT_SYSINFO_ECN_IFNET_ON_REORDER_PERCENT
= 71
167 ,NSTAT_SYSINFO_ECN_IFNET_ON_RXMIT_PERCENT
= 72
168 ,NSTAT_SYSINFO_ECN_IFNET_ON_RXMIT_DROP
= 73
169 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RTT_AVG
= 74
170 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RTT_VAR
= 75
171 ,NSTAT_SYSINFO_ECN_IFNET_OFF_OOPERCENT
= 76
172 ,NSTAT_SYSINFO_ECN_IFNET_OFF_SACK_EPISODE
= 77
173 ,NSTAT_SYSINFO_ECN_IFNET_OFF_REORDER_PERCENT
= 78
174 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RXMIT_PERCENT
= 79
175 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RXMIT_DROP
= 80
178 #pragma mark -- Network Statistics Providers --
181 // Interface properties
183 #define NSTAT_IFNET_IS_UNKNOWN_TYPE 0x01
184 #define NSTAT_IFNET_IS_LOOPBACK 0x02
185 #define NSTAT_IFNET_IS_CELLULAR 0x04
186 #define NSTAT_IFNET_IS_WIFI 0x08
187 #define NSTAT_IFNET_IS_WIRED 0x10
188 #define NSTAT_IFNET_IS_AWDL 0x20
189 #define NSTAT_IFNET_IS_EXPENSIVE 0x40
190 #define NSTAT_IFNET_IS_VPN 0x80
195 NSTAT_PROVIDER_NONE
= 0
196 ,NSTAT_PROVIDER_ROUTE
= 1
197 ,NSTAT_PROVIDER_TCP
= 2
198 ,NSTAT_PROVIDER_UDP
= 3
199 ,NSTAT_PROVIDER_IFNET
= 4
200 ,NSTAT_PROVIDER_SYSINFO
= 5
202 #define NSTAT_PROVIDER_LAST NSTAT_PROVIDER_SYSINFO
203 #define NSTAT_PROVIDER_COUNT (NSTAT_PROVIDER_LAST+1)
205 typedef struct nstat_route_add_param
209 struct sockaddr_in v4
;
210 struct sockaddr_in6 v6
;
214 struct sockaddr_in v4
;
215 struct sockaddr_in6 v6
;
218 } nstat_route_add_param
;
220 typedef struct nstat_tcp_add_param
224 struct sockaddr_in v4
;
225 struct sockaddr_in6 v6
;
229 struct sockaddr_in v4
;
230 struct sockaddr_in6 v6
;
232 } nstat_tcp_add_param
;
234 typedef struct nstat_tcp_descriptor
238 struct sockaddr_in v4
;
239 struct sockaddr_in6 v6
;
244 struct sockaddr_in v4
;
245 struct sockaddr_in6 v6
;
252 u_int32_t sndbufsize
;
253 u_int32_t sndbufused
;
254 u_int32_t rcvbufsize
;
255 u_int32_t rcvbufused
;
259 u_int32_t traffic_class
;
260 u_int32_t traffic_mgt_flags
;
272 struct tcp_conn_status connstatus
;
273 uint16_t ifnet_properties
__attribute__((aligned(4)));
274 } nstat_tcp_descriptor
;
276 typedef struct nstat_tcp_add_param nstat_udp_add_param
;
278 typedef struct nstat_udp_descriptor
282 struct sockaddr_in v4
;
283 struct sockaddr_in6 v6
;
288 struct sockaddr_in v4
;
289 struct sockaddr_in6 v6
;
294 u_int32_t rcvbufsize
;
295 u_int32_t rcvbufused
;
296 u_int32_t traffic_class
;
307 uint16_t ifnet_properties
;
308 } nstat_udp_descriptor
;
310 typedef struct nstat_route_descriptor
314 u_int64_t gateway_id
;
318 struct sockaddr_in v4
;
319 struct sockaddr_in6 v6
;
325 struct sockaddr_in v4
;
326 struct sockaddr_in6 v6
;
332 struct sockaddr_in v4
;
333 struct sockaddr_in6 v6
;
340 } nstat_route_descriptor
;
342 typedef struct nstat_ifnet_add_param
346 } nstat_ifnet_add_param
;
348 typedef struct nstat_ifnet_desc_cellular_status
350 u_int32_t valid_bitmask
; /* indicates which fields are valid */
351 #define NSTAT_IFNET_DESC_CELL_LINK_QUALITY_METRIC_VALID 0x1
352 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
353 #define NSTAT_IFNET_DESC_CELL_UL_MAX_BANDWIDTH_VALID 0x4
354 #define NSTAT_IFNET_DESC_CELL_UL_MIN_LATENCY_VALID 0x8
355 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
356 #define NSTAT_IFNET_DESC_CELL_UL_MAX_LATENCY_VALID 0x20
357 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_VALID 0x40
358 #define NSTAT_IFNET_DESC_CELL_UL_BYTES_LOST_VALID 0x80
359 #define NSTAT_IFNET_DESC_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
360 #define NSTAT_IFNET_DESC_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
361 #define NSTAT_IFNET_DESC_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
362 #define NSTAT_IFNET_DESC_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
363 #define NSTAT_IFNET_DESC_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
364 #define NSTAT_IFNET_DESC_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
365 #define NSTAT_IFNET_DESC_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
366 u_int32_t link_quality_metric
;
367 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on
368 current activity (bps) */
369 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth
371 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop
373 u_int32_t ul_effective_latency
; /* current expected uplink latency for
375 u_int32_t ul_max_latency
; /* max expected uplink latency first hop
377 u_int32_t ul_retxt_level
; /* Retransmission metric */
378 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_NONE 1
379 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_LOW 2
380 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_MEDIUM 3
381 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_HIGH 4
383 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10
385 u_int32_t ul_min_queue_size
; /* minimum bytes in queue */
386 u_int32_t ul_avg_queue_size
; /* average bytes in queue */
387 u_int32_t ul_max_queue_size
; /* maximum bytes in queue */
388 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based
389 on current activity (bps) */
390 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth
392 u_int32_t config_inactivity_time
; /* ms */
393 u_int32_t config_backoff_time
; /* new connections backoff time in ms */
394 } nstat_ifnet_desc_cellular_status
;
396 typedef struct nstat_ifnet_desc_wifi_status
{
397 u_int32_t valid_bitmask
;
398 #define NSTAT_IFNET_DESC_WIFI_LINK_QUALITY_METRIC_VALID 0x1
399 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
400 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
401 #define NSTAT_IFNET_DESC_WIFI_UL_MIN_LATENCY_VALID 0x8
402 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
403 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_LATENCY_VALID 0x20
404 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_VALID 0x40
405 #define NSTAT_IFNET_DESC_WIFI_UL_ERROR_RATE_VALID 0x80
406 #define NSTAT_IFNET_DESC_WIFI_UL_BYTES_LOST_VALID 0x100
407 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
408 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
409 #define NSTAT_IFNET_DESC_WIFI_DL_MIN_LATENCY_VALID 0x800
410 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
411 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_LATENCY_VALID 0x2000
412 #define NSTAT_IFNET_DESC_WIFI_DL_ERROR_RATE_VALID 0x4000
413 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_VALID 0x8000
414 #define NSTAT_IFNET_DESC_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
415 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
416 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
417 u_int32_t link_quality_metric
; /* link quality metric */
418 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on
419 current activity (bps) */
420 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth
422 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop
424 u_int32_t ul_effective_latency
; /* current expected uplink latency for
426 u_int32_t ul_max_latency
; /* max expected uplink latency for first hop
428 u_int32_t ul_retxt_level
; /* Retransmission metric */
429 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_NONE 1
430 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_LOW 2
431 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_MEDIUM 3
432 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_HIGH 4
434 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10
436 u_int32_t ul_error_rate
; /* % of bytes dropped on uplink after many
437 retransmissions in Q10 format */
438 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based
439 on current activity (bps) */
440 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth
443 * The download latency values indicate the time AP may have to wait
444 * for the driver to receive the packet. These values give the range
445 * of expected latency mainly due to co-existence events and channel
446 * hopping where the interface becomes unavailable.
448 u_int32_t dl_min_latency
; /* min expected latency for first hop in ms */
449 u_int32_t dl_effective_latency
; /* current expected latency for first
451 u_int32_t dl_max_latency
; /* max expected latency for first hop in ms */
452 u_int32_t dl_error_rate
; /* % of CRC or other errors in Q10 format */
453 u_int32_t config_frequency
; /* 2.4 or 5 GHz */
454 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
455 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
456 u_int32_t config_multicast_rate
; /* bps */
457 u_int32_t scan_count
; /* scan count during the previous period */
458 u_int32_t scan_duration
; /* scan duration in ms */
459 } nstat_ifnet_desc_wifi_status
;
463 NSTAT_IFNET_DESC_LINK_STATUS_TYPE_NONE
= 0
464 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_CELLULAR
= 1
465 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_WIFI
= 2
468 typedef struct nstat_ifnet_desc_link_status
470 u_int32_t link_status_type
;
472 nstat_ifnet_desc_cellular_status cellular
;
473 nstat_ifnet_desc_wifi_status wifi
;
475 } nstat_ifnet_desc_link_status
;
478 #define IF_DESCSIZE 128
480 typedef struct nstat_ifnet_descriptor
482 char name
[IFNAMSIZ
+1];
486 char description
[IF_DESCSIZE
];
487 nstat_ifnet_desc_link_status link_status
;
488 } nstat_ifnet_descriptor
;
490 typedef struct nstat_sysinfo_descriptor
493 } nstat_sysinfo_descriptor
;
495 typedef struct nstat_sysinfo_add_param
497 /* To indicate which system level information should be collected */
499 } nstat_sysinfo_add_param
;
501 #define NSTAT_SYSINFO_MBUF_STATS 0x0001
502 #define NSTAT_SYSINFO_TCP_STATS 0x0002
503 #define NSTAT_SYSINFO_IFNET_ECN_STATS 0x0003
505 #pragma mark -- Network Statistics User Client --
507 #define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
511 // generic response messages
512 NSTAT_MSG_TYPE_SUCCESS
= 0
513 ,NSTAT_MSG_TYPE_ERROR
= 1
516 ,NSTAT_MSG_TYPE_ADD_SRC
= 1001
517 ,NSTAT_MSG_TYPE_ADD_ALL_SRCS
= 1002
518 ,NSTAT_MSG_TYPE_REM_SRC
= 1003
519 ,NSTAT_MSG_TYPE_QUERY_SRC
= 1004
520 ,NSTAT_MSG_TYPE_GET_SRC_DESC
= 1005
521 ,NSTAT_MSG_TYPE_SET_FILTER
= 1006
522 ,NSTAT_MSG_TYPE_GET_UPDATE
= 1007
523 ,NSTAT_MSG_TYPE_SUBSCRIBE_SYSINFO
= 1008
525 // Responses/Notfications
526 ,NSTAT_MSG_TYPE_SRC_ADDED
= 10001
527 ,NSTAT_MSG_TYPE_SRC_REMOVED
= 10002
528 ,NSTAT_MSG_TYPE_SRC_DESC
= 10003
529 ,NSTAT_MSG_TYPE_SRC_COUNTS
= 10004
530 ,NSTAT_MSG_TYPE_SYSINFO_COUNTS
= 10005
531 ,NSTAT_MSG_TYPE_SRC_UPDATE
= 10006
536 NSTAT_SRC_REF_ALL
= 0xffffffff
537 ,NSTAT_SRC_REF_INVALID
= 0
540 /* Source-level filters */
543 NSTAT_FILTER_NOZEROBYTES
= 0x00000001
546 /* Provider-level filters */
549 NSTAT_FILTER_ACCEPT_UNKNOWN
= 0x00000001
550 ,NSTAT_FILTER_ACCEPT_LOOPBACK
= 0x00000002
551 ,NSTAT_FILTER_ACCEPT_CELLULAR
= 0x00000004
552 ,NSTAT_FILTER_ACCEPT_WIFI
= 0x00000008
553 ,NSTAT_FILTER_ACCEPT_WIRED
= 0x00000010
554 ,NSTAT_FILTER_ACCEPT_ALL
= 0x0000001F
555 ,NSTAT_FILTER_IFNET_FLAGS
= 0x000000FF
557 ,NSTAT_FILTER_PROVIDER_NOZEROBYTES
= 0x00000100
559 ,NSTAT_FILTER_TCP_NO_LISTENER
= 0x00001000
560 ,NSTAT_FILTER_TCP_ONLY_LISTENER
= 0x00002000
561 ,NSTAT_FILTER_TCP_INTERFACE_ATTACH
= 0x00004000
562 ,NSTAT_FILTER_TCP_FLAGS
= 0x0000F000
564 ,NSTAT_FILTER_UDP_INTERFACE_ATTACH
= 0x00010000
565 ,NSTAT_FILTER_UDP_FLAGS
= 0x000F0000
567 ,NSTAT_FILTER_SUPPRESS_SRC_ADDED
= 0x00100000
568 ,NSTAT_FILTER_REQUIRE_SRC_ADDED
= 0x00200000
573 NSTAT_MSG_HDR_FLAG_SUPPORTS_AGGREGATE
= 1 << 0,
574 NSTAT_MSG_HDR_FLAG_CONTINUATION
= 1 << 1,
575 NSTAT_MSG_HDR_FLAG_CLOSING
= 1 << 2,
578 typedef struct nstat_msg_hdr
586 typedef struct nstat_msg_error
589 u_int32_t error
; // errno error
592 typedef struct nstat_msg_add_src
595 nstat_provider_id_t provider
;
597 } nstat_msg_add_src_req
;
599 typedef struct nstat_msg_add_all_srcs
602 nstat_provider_id_t provider
;
604 } nstat_msg_add_all_srcs
;
606 typedef struct nstat_msg_src_added
609 nstat_provider_id_t provider
;
610 nstat_src_ref_t srcref
;
611 } nstat_msg_src_added
;
613 typedef struct nstat_msg_rem_src
616 nstat_src_ref_t srcref
;
617 } nstat_msg_rem_src_req
;
619 typedef struct nstat_msg_get_src_description
622 nstat_src_ref_t srcref
;
623 } nstat_msg_get_src_description
;
625 typedef struct nstat_msg_set_filter
628 nstat_src_ref_t srcref
;
630 } nstat_msg_set_filter
;
632 typedef struct nstat_msg_src_description
635 nstat_src_ref_t srcref
;
636 nstat_provider_id_t provider
;
638 } nstat_msg_src_description
;
640 typedef struct nstat_msg_query_src
643 nstat_src_ref_t srcref
;
644 } nstat_msg_query_src_req
;
646 typedef struct nstat_msg_src_counts
649 nstat_src_ref_t srcref
;
651 } nstat_msg_src_counts
;
653 typedef struct nstat_msg_src_update
656 nstat_src_ref_t srcref
;
658 nstat_provider_id_t provider
;
660 } nstat_msg_src_update
;
662 typedef struct nstat_msg_src_removed
665 nstat_src_ref_t srcref
;
666 } nstat_msg_src_removed
;
668 typedef struct nstat_msg_sysinfo_counts
671 nstat_src_ref_t srcref
;
672 nstat_sysinfo_counts counts
;
673 } __attribute__((packed
)) nstat_msg_sysinfo_counts
;
677 #pragma mark -- Statitiscs about Network Statistics --
680 u_int32_t nstat_successmsgfailures
;
681 u_int32_t nstat_sendcountfailures
;
682 u_int32_t nstat_sysinfofailures
;
683 u_int32_t nstat_srcupatefailures
;
684 u_int32_t nstat_descriptionfailures
;
685 u_int32_t nstat_msgremovedfailures
;
686 u_int32_t nstat_srcaddedfailures
;
687 u_int32_t nstat_msgerrorfailures
;
688 u_int32_t nstat_copy_descriptor_failures
;
689 u_int32_t nstat_provider_counts_failures
;
690 u_int32_t nstat_control_send_description_failures
;
691 u_int32_t nstat_control_send_goodbye_failures
;
692 u_int32_t nstat_flush_accumulated_msgs_failures
;
693 u_int32_t nstat_accumulate_msg_failures
;
694 u_int32_t nstat_control_cleanup_source_failures
;
695 u_int32_t nstat_handle_msg_failures
;
700 #ifdef XNU_KERNEL_PRIVATE
701 #include <sys/mcache.h>
703 #pragma mark -- System Information Internal Support --
705 typedef struct nstat_sysinfo_mbuf_stats
707 u_int32_t total_256b
; /* Peak usage, 256B pool */
708 u_int32_t total_2kb
; /* Peak usage, 2KB pool */
709 u_int32_t total_4kb
; /* Peak usage, 4KB pool */
710 u_int32_t total_16kb
; /* Peak usage, 16KB pool */
711 u_int32_t sbmb_total
; /* Total mbufs in sock buffer pool */
712 u_int32_t sb_atmbuflimit
; /* Memory limit reached for socket buffer autoscaling */
713 u_int32_t draincnt
; /* Number of times mbuf pool has been drained under memory pressure */
714 u_int32_t memreleased
; /* Memory (bytes) released from mbuf pool to VM */
715 } nstat_sysinfo_mbuf_stats
;
717 typedef struct nstat_sysinfo_tcp_stats
719 u_int32_t ipv4_avgrtt
; /* Average RTT for IPv4 */
720 u_int32_t ipv6_avgrtt
; /* Average RTT for IPv6 */
721 u_int32_t send_plr
; /* Average uplink packet loss rate */
722 u_int32_t recv_plr
; /* Average downlink packet loss rate */
723 u_int32_t send_tlrto_rate
; /* Average rxt timeout after tail loss */
724 u_int32_t send_reorder_rate
; /* Average packet reordering rate */
725 u_int32_t connection_attempts
; /* TCP client connection attempts */
726 u_int32_t connection_accepts
; /* TCP server connection accepts */
727 u_int32_t ecn_client_enabled
; /* Global setting for ECN client side */
728 u_int32_t ecn_server_enabled
; /* Global setting for ECN server side */
729 u_int32_t ecn_client_setup
; /* Attempts to setup TCP client connection with ECN */
730 u_int32_t ecn_server_setup
; /* Attempts to setup TCP server connection with ECN */
731 u_int32_t ecn_client_success
; /* Number of successful negotiations of ECN for a client connection */
732 u_int32_t ecn_server_success
; /* Number of successful negotiations of ECN for a server connection */
733 u_int32_t ecn_not_supported
; /* Number of falbacks to Non-ECN, no support from peer */
734 u_int32_t ecn_lost_syn
; /* Number of SYNs lost with ECN bits */
735 u_int32_t ecn_lost_synack
; /* Number of SYN-ACKs lost with ECN bits */
736 u_int32_t ecn_recv_ce
; /* Number of CEs received from network */
737 u_int32_t ecn_recv_ece
; /* Number of ECEs received from receiver */
738 u_int32_t ecn_sent_ece
; /* Number of ECEs sent in response to CE */
739 u_int32_t ecn_conn_recv_ce
; /* Number of connections using ECN received CE at least once */
740 u_int32_t ecn_conn_recv_ece
; /* Number of connections using ECN received ECE at least once */
741 u_int32_t ecn_conn_plnoce
; /* Number of connections using ECN seen packet loss but never received CE */
742 u_int32_t ecn_conn_pl_ce
; /* Number of connections using ECN seen packet loss and CE */
743 u_int32_t ecn_conn_nopl_ce
; /* Number of connections using ECN with no packet loss but received CE */
744 u_int32_t ecn_fallback_synloss
; /* Number of times we did fall back due to SYN-Loss */
745 u_int32_t ecn_fallback_reorder
; /* Number of times we fallback because we detected the PAWS-issue */
746 u_int32_t ecn_fallback_ce
; /* Number of times we fallback because we received too many CEs */
747 u_int32_t tfo_syn_data_rcv
; /* Number of SYN+data received with valid cookie */
748 u_int32_t tfo_cookie_req_rcv
;/* Number of TFO cookie-requests received */
749 u_int32_t tfo_cookie_sent
; /* Number of TFO-cookies offered to the client */
750 u_int32_t tfo_cookie_invalid
;/* Number of invalid TFO-cookies received */
751 u_int32_t tfo_cookie_req
; /* Number of SYNs with cookie request received*/
752 u_int32_t tfo_cookie_rcv
; /* Number of SYN/ACKs with Cookie received */
753 u_int32_t tfo_syn_data_sent
; /* Number of SYNs+data+cookie sent */
754 u_int32_t tfo_syn_data_acked
;/* Number of times our SYN+data has been acknowledged */
755 u_int32_t tfo_syn_loss
; /* Number of times SYN+TFO has been lost and we fallback */
756 u_int32_t tfo_blackhole
; /* Number of times SYN+TFO has been lost and we fallback */
757 } nstat_sysinfo_tcp_stats
;
760 NSTAT_IFNET_ECN_PROTO_IPV4
= 1
761 ,NSTAT_IFNET_ECN_PROTO_IPV6
765 NSTAT_IFNET_ECN_TYPE_CELLULAR
= 1
766 ,NSTAT_IFNET_ECN_TYPE_WIFI
767 ,NSTAT_IFNET_ECN_TYPE_ETHERNET
770 typedef struct nstat_sysinfo_ifnet_ecn_stats
{
771 u_int32_t ifnet_proto
;
772 u_int32_t ifnet_type
;
773 struct if_tcp_ecn_stat ecn_stat
;
774 } nstat_sysinfo_ifnet_ecn_stats
;
776 typedef struct nstat_sysinfo_data
780 nstat_sysinfo_mbuf_stats mb_stats
;
781 nstat_sysinfo_tcp_stats tcp_stats
;
782 nstat_sysinfo_ifnet_ecn_stats ifnet_ecn_stats
;
784 } nstat_sysinfo_data
;
786 #pragma mark -- Generic Network Statistics Provider --
788 typedef void * nstat_provider_cookie_t
;
790 #pragma mark -- Route Statistics Gathering Functions --
795 NSTAT_TX_FLAG_RETRANSMIT
= 1
800 NSTAT_RX_FLAG_DUPLICATE
= 1,
801 NSTAT_RX_FLAG_OUT_OF_ORDER
= 2
804 // indicates whether or not collection of statistics is enabled
805 extern int nstat_collect
;
807 void nstat_init(void);
809 // Route collection routines
810 void nstat_route_connect_attempt(struct rtentry
*rte
);
811 void nstat_route_connect_success(struct rtentry
*rte
);
812 void nstat_route_tx(struct rtentry
*rte
, u_int32_t packets
, u_int32_t bytes
, u_int32_t flags
);
813 void nstat_route_rx(struct rtentry
*rte
, u_int32_t packets
, u_int32_t bytes
, u_int32_t flags
);
814 void nstat_route_rtt(struct rtentry
*rte
, u_int32_t rtt
, u_int32_t rtt_var
);
815 void nstat_route_detach(struct rtentry
*rte
);
819 void nstat_tcp_new_pcb(struct inpcb
*inp
);
820 void nstat_udp_new_pcb(struct inpcb
*inp
);
821 void nstat_route_new_entry(struct rtentry
*rt
);
822 void nstat_pcb_detach(struct inpcb
*inp
);
823 void nstat_pcb_cache(struct inpcb
*inp
);
824 void nstat_pcb_invalidate_cache(struct inpcb
*inp
);
827 void nstat_ifnet_threshold_reached(unsigned int ifindex
);
829 void nstat_sysinfo_send_data(struct nstat_sysinfo_data
*);
831 // locked_add_64 uses atomic operations on 32bit so the 64bit
832 // value can be properly read. The values are only ever incremented
833 // while under the socket lock, so on 64bit we don't actually need
834 // atomic operations to increment.
835 #if defined(__LP64__)
836 #define locked_add_64(__addr, __count) do { \
837 *(__addr) += (__count); \
840 #define locked_add_64(__addr, __count) do { \
841 atomic_add_64((__addr), (__count)); \
845 #endif /* XNU_KERNEL_PRIVATE */
847 #endif /* __NTSTAT_H__ */