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
176 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_TXPKTS
= 81
177 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_RXMTPKTS
= 82
178 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_RXPKTS
= 83
179 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_OOPKTS
= 84
180 ,NSTAT_SYSINFO_ECN_IFNET_ON_DROP_RST
= 85
181 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_TXPKTS
= 86
182 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_RXMTPKTS
= 87
183 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_RXPKTS
= 88
184 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_OOPKTS
= 89
185 ,NSTAT_SYSINFO_ECN_IFNET_OFF_DROP_RST
= 90
186 ,NSTAT_SYSINFO_ECN_IFNET_TOTAL_CONN
= 91
187 // NSTAT_SYSINFO_ENUM_VERSION must be updated any time a value is added
188 #define NSTAT_SYSINFO_ENUM_VERSION 20151208
191 #pragma mark -- Network Statistics Providers --
194 // Interface properties
196 #define NSTAT_IFNET_IS_UNKNOWN_TYPE 0x01
197 #define NSTAT_IFNET_IS_LOOPBACK 0x02
198 #define NSTAT_IFNET_IS_CELLULAR 0x04
199 #define NSTAT_IFNET_IS_WIFI 0x08
200 #define NSTAT_IFNET_IS_WIRED 0x10
201 #define NSTAT_IFNET_IS_AWDL 0x20
202 #define NSTAT_IFNET_IS_EXPENSIVE 0x40
203 #define NSTAT_IFNET_IS_VPN 0x80
204 #define NSTAT_IFNET_VIA_CELLFALLBACK 0x100
209 NSTAT_PROVIDER_NONE
= 0
210 ,NSTAT_PROVIDER_ROUTE
= 1
211 ,NSTAT_PROVIDER_TCP
= 2
212 ,NSTAT_PROVIDER_UDP
= 3
213 ,NSTAT_PROVIDER_IFNET
= 4
214 ,NSTAT_PROVIDER_SYSINFO
= 5
216 #define NSTAT_PROVIDER_LAST NSTAT_PROVIDER_SYSINFO
217 #define NSTAT_PROVIDER_COUNT (NSTAT_PROVIDER_LAST+1)
219 typedef struct nstat_route_add_param
223 struct sockaddr_in v4
;
224 struct sockaddr_in6 v6
;
228 struct sockaddr_in v4
;
229 struct sockaddr_in6 v6
;
232 } nstat_route_add_param
;
234 typedef struct nstat_tcp_add_param
238 struct sockaddr_in v4
;
239 struct sockaddr_in6 v6
;
243 struct sockaddr_in v4
;
244 struct sockaddr_in6 v6
;
246 } nstat_tcp_add_param
;
248 typedef struct nstat_tcp_descriptor
252 struct sockaddr_in v4
;
253 struct sockaddr_in6 v6
;
258 struct sockaddr_in v4
;
259 struct sockaddr_in6 v6
;
266 u_int32_t sndbufsize
;
267 u_int32_t sndbufused
;
268 u_int32_t rcvbufsize
;
269 u_int32_t rcvbufused
;
273 u_int32_t traffic_class
;
274 u_int32_t traffic_mgt_flags
;
286 struct tcp_conn_status connstatus
;
287 uint16_t ifnet_properties
__attribute__((aligned(4)));
288 } nstat_tcp_descriptor
;
290 typedef struct nstat_tcp_add_param nstat_udp_add_param
;
292 typedef struct nstat_udp_descriptor
296 struct sockaddr_in v4
;
297 struct sockaddr_in6 v6
;
302 struct sockaddr_in v4
;
303 struct sockaddr_in6 v6
;
308 u_int32_t rcvbufsize
;
309 u_int32_t rcvbufused
;
310 u_int32_t traffic_class
;
321 uint16_t ifnet_properties
;
322 } nstat_udp_descriptor
;
324 typedef struct nstat_route_descriptor
328 u_int64_t gateway_id
;
332 struct sockaddr_in v4
;
333 struct sockaddr_in6 v6
;
339 struct sockaddr_in v4
;
340 struct sockaddr_in6 v6
;
346 struct sockaddr_in v4
;
347 struct sockaddr_in6 v6
;
354 } nstat_route_descriptor
;
356 typedef struct nstat_ifnet_add_param
360 } nstat_ifnet_add_param
;
362 typedef struct nstat_ifnet_desc_cellular_status
364 u_int32_t valid_bitmask
; /* indicates which fields are valid */
365 #define NSTAT_IFNET_DESC_CELL_LINK_QUALITY_METRIC_VALID 0x1
366 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
367 #define NSTAT_IFNET_DESC_CELL_UL_MAX_BANDWIDTH_VALID 0x4
368 #define NSTAT_IFNET_DESC_CELL_UL_MIN_LATENCY_VALID 0x8
369 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
370 #define NSTAT_IFNET_DESC_CELL_UL_MAX_LATENCY_VALID 0x20
371 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_VALID 0x40
372 #define NSTAT_IFNET_DESC_CELL_UL_BYTES_LOST_VALID 0x80
373 #define NSTAT_IFNET_DESC_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
374 #define NSTAT_IFNET_DESC_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
375 #define NSTAT_IFNET_DESC_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
376 #define NSTAT_IFNET_DESC_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
377 #define NSTAT_IFNET_DESC_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
378 #define NSTAT_IFNET_DESC_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
379 #define NSTAT_IFNET_DESC_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
380 u_int32_t link_quality_metric
;
381 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on
382 current activity (bps) */
383 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth
385 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop
387 u_int32_t ul_effective_latency
; /* current expected uplink latency for
389 u_int32_t ul_max_latency
; /* max expected uplink latency first hop
391 u_int32_t ul_retxt_level
; /* Retransmission metric */
392 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_NONE 1
393 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_LOW 2
394 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_MEDIUM 3
395 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_HIGH 4
397 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10
399 u_int32_t ul_min_queue_size
; /* minimum bytes in queue */
400 u_int32_t ul_avg_queue_size
; /* average bytes in queue */
401 u_int32_t ul_max_queue_size
; /* maximum bytes in queue */
402 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based
403 on current activity (bps) */
404 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth
406 u_int32_t config_inactivity_time
; /* ms */
407 u_int32_t config_backoff_time
; /* new connections backoff time in ms */
408 } nstat_ifnet_desc_cellular_status
;
410 typedef struct nstat_ifnet_desc_wifi_status
{
411 u_int32_t valid_bitmask
;
412 #define NSTAT_IFNET_DESC_WIFI_LINK_QUALITY_METRIC_VALID 0x1
413 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
414 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
415 #define NSTAT_IFNET_DESC_WIFI_UL_MIN_LATENCY_VALID 0x8
416 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
417 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_LATENCY_VALID 0x20
418 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_VALID 0x40
419 #define NSTAT_IFNET_DESC_WIFI_UL_ERROR_RATE_VALID 0x80
420 #define NSTAT_IFNET_DESC_WIFI_UL_BYTES_LOST_VALID 0x100
421 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
422 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
423 #define NSTAT_IFNET_DESC_WIFI_DL_MIN_LATENCY_VALID 0x800
424 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
425 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_LATENCY_VALID 0x2000
426 #define NSTAT_IFNET_DESC_WIFI_DL_ERROR_RATE_VALID 0x4000
427 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_VALID 0x8000
428 #define NSTAT_IFNET_DESC_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
429 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
430 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
431 u_int32_t link_quality_metric
; /* link quality metric */
432 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on
433 current activity (bps) */
434 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth
436 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop
438 u_int32_t ul_effective_latency
; /* current expected uplink latency for
440 u_int32_t ul_max_latency
; /* max expected uplink latency for first hop
442 u_int32_t ul_retxt_level
; /* Retransmission metric */
443 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_NONE 1
444 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_LOW 2
445 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_MEDIUM 3
446 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_HIGH 4
448 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10
450 u_int32_t ul_error_rate
; /* % of bytes dropped on uplink after many
451 retransmissions in Q10 format */
452 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based
453 on current activity (bps) */
454 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth
457 * The download latency values indicate the time AP may have to wait
458 * for the driver to receive the packet. These values give the range
459 * of expected latency mainly due to co-existence events and channel
460 * hopping where the interface becomes unavailable.
462 u_int32_t dl_min_latency
; /* min expected latency for first hop in ms */
463 u_int32_t dl_effective_latency
; /* current expected latency for first
465 u_int32_t dl_max_latency
; /* max expected latency for first hop in ms */
466 u_int32_t dl_error_rate
; /* % of CRC or other errors in Q10 format */
467 u_int32_t config_frequency
; /* 2.4 or 5 GHz */
468 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
469 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
470 u_int32_t config_multicast_rate
; /* bps */
471 u_int32_t scan_count
; /* scan count during the previous period */
472 u_int32_t scan_duration
; /* scan duration in ms */
473 } nstat_ifnet_desc_wifi_status
;
477 NSTAT_IFNET_DESC_LINK_STATUS_TYPE_NONE
= 0
478 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_CELLULAR
= 1
479 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_WIFI
= 2
482 typedef struct nstat_ifnet_desc_link_status
484 u_int32_t link_status_type
;
486 nstat_ifnet_desc_cellular_status cellular
;
487 nstat_ifnet_desc_wifi_status wifi
;
489 } nstat_ifnet_desc_link_status
;
492 #define IF_DESCSIZE 128
494 typedef struct nstat_ifnet_descriptor
496 char name
[IFNAMSIZ
+1];
500 char description
[IF_DESCSIZE
];
501 nstat_ifnet_desc_link_status link_status
;
502 } nstat_ifnet_descriptor
;
504 typedef struct nstat_sysinfo_descriptor
507 } nstat_sysinfo_descriptor
;
509 typedef struct nstat_sysinfo_add_param
511 /* To indicate which system level information should be collected */
513 } nstat_sysinfo_add_param
;
515 #define NSTAT_SYSINFO_MBUF_STATS 0x0001
516 #define NSTAT_SYSINFO_TCP_STATS 0x0002
517 #define NSTAT_SYSINFO_IFNET_ECN_STATS 0x0003
519 #pragma mark -- Network Statistics User Client --
521 #define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
525 // generic response messages
526 NSTAT_MSG_TYPE_SUCCESS
= 0
527 ,NSTAT_MSG_TYPE_ERROR
= 1
530 ,NSTAT_MSG_TYPE_ADD_SRC
= 1001
531 ,NSTAT_MSG_TYPE_ADD_ALL_SRCS
= 1002
532 ,NSTAT_MSG_TYPE_REM_SRC
= 1003
533 ,NSTAT_MSG_TYPE_QUERY_SRC
= 1004
534 ,NSTAT_MSG_TYPE_GET_SRC_DESC
= 1005
535 ,NSTAT_MSG_TYPE_SET_FILTER
= 1006
536 ,NSTAT_MSG_TYPE_GET_UPDATE
= 1007
537 ,NSTAT_MSG_TYPE_SUBSCRIBE_SYSINFO
= 1008
539 // Responses/Notfications
540 ,NSTAT_MSG_TYPE_SRC_ADDED
= 10001
541 ,NSTAT_MSG_TYPE_SRC_REMOVED
= 10002
542 ,NSTAT_MSG_TYPE_SRC_DESC
= 10003
543 ,NSTAT_MSG_TYPE_SRC_COUNTS
= 10004
544 ,NSTAT_MSG_TYPE_SYSINFO_COUNTS
= 10005
545 ,NSTAT_MSG_TYPE_SRC_UPDATE
= 10006
550 NSTAT_SRC_REF_ALL
= 0xffffffff
551 ,NSTAT_SRC_REF_INVALID
= 0
554 /* Source-level filters */
557 NSTAT_FILTER_NOZEROBYTES
= 0x00000001
560 /* Provider-level filters */
563 NSTAT_FILTER_ACCEPT_UNKNOWN
= 0x00000001
564 ,NSTAT_FILTER_ACCEPT_LOOPBACK
= 0x00000002
565 ,NSTAT_FILTER_ACCEPT_CELLULAR
= 0x00000004
566 ,NSTAT_FILTER_ACCEPT_WIFI
= 0x00000008
567 ,NSTAT_FILTER_ACCEPT_WIRED
= 0x00000010
568 ,NSTAT_FILTER_ACCEPT_ALL
= 0x0000001F
569 ,NSTAT_FILTER_IFNET_FLAGS
= 0x000000FF
571 ,NSTAT_FILTER_PROVIDER_NOZEROBYTES
= 0x00000100
573 ,NSTAT_FILTER_TCP_NO_LISTENER
= 0x00001000
574 ,NSTAT_FILTER_TCP_ONLY_LISTENER
= 0x00002000
575 ,NSTAT_FILTER_TCP_INTERFACE_ATTACH
= 0x00004000
576 ,NSTAT_FILTER_TCP_FLAGS
= 0x0000F000
578 ,NSTAT_FILTER_UDP_INTERFACE_ATTACH
= 0x00010000
579 ,NSTAT_FILTER_UDP_FLAGS
= 0x000F0000
581 ,NSTAT_FILTER_SUPPRESS_SRC_ADDED
= 0x00100000
582 ,NSTAT_FILTER_REQUIRE_SRC_ADDED
= 0x00200000
587 NSTAT_MSG_HDR_FLAG_SUPPORTS_AGGREGATE
= 1 << 0,
588 NSTAT_MSG_HDR_FLAG_CONTINUATION
= 1 << 1,
589 NSTAT_MSG_HDR_FLAG_CLOSING
= 1 << 2,
592 typedef struct nstat_msg_hdr
600 typedef struct nstat_msg_error
603 u_int32_t error
; // errno error
606 typedef struct nstat_msg_add_src
609 nstat_provider_id_t provider
;
611 } nstat_msg_add_src_req
;
613 typedef struct nstat_msg_add_all_srcs
616 nstat_provider_id_t provider
;
618 } nstat_msg_add_all_srcs
;
620 typedef struct nstat_msg_src_added
623 nstat_provider_id_t provider
;
624 nstat_src_ref_t srcref
;
625 } nstat_msg_src_added
;
627 typedef struct nstat_msg_rem_src
630 nstat_src_ref_t srcref
;
631 } nstat_msg_rem_src_req
;
633 typedef struct nstat_msg_get_src_description
636 nstat_src_ref_t srcref
;
637 } nstat_msg_get_src_description
;
639 typedef struct nstat_msg_set_filter
642 nstat_src_ref_t srcref
;
644 } nstat_msg_set_filter
;
646 typedef struct nstat_msg_src_description
649 nstat_src_ref_t srcref
;
650 nstat_provider_id_t provider
;
652 } nstat_msg_src_description
;
654 typedef struct nstat_msg_query_src
657 nstat_src_ref_t srcref
;
658 } nstat_msg_query_src_req
;
660 typedef struct nstat_msg_src_counts
663 nstat_src_ref_t srcref
;
665 } nstat_msg_src_counts
;
667 typedef struct nstat_msg_src_update
670 nstat_src_ref_t srcref
;
672 nstat_provider_id_t provider
;
674 } nstat_msg_src_update
;
676 typedef struct nstat_msg_src_removed
679 nstat_src_ref_t srcref
;
680 } nstat_msg_src_removed
;
682 typedef struct nstat_msg_sysinfo_counts
685 nstat_src_ref_t srcref
;
686 nstat_sysinfo_counts counts
;
687 } __attribute__((packed
)) nstat_msg_sysinfo_counts
;
691 #pragma mark -- Statitiscs about Network Statistics --
694 u_int32_t nstat_successmsgfailures
;
695 u_int32_t nstat_sendcountfailures
;
696 u_int32_t nstat_sysinfofailures
;
697 u_int32_t nstat_srcupatefailures
;
698 u_int32_t nstat_descriptionfailures
;
699 u_int32_t nstat_msgremovedfailures
;
700 u_int32_t nstat_srcaddedfailures
;
701 u_int32_t nstat_msgerrorfailures
;
702 u_int32_t nstat_copy_descriptor_failures
;
703 u_int32_t nstat_provider_counts_failures
;
704 u_int32_t nstat_control_send_description_failures
;
705 u_int32_t nstat_control_send_goodbye_failures
;
706 u_int32_t nstat_flush_accumulated_msgs_failures
;
707 u_int32_t nstat_accumulate_msg_failures
;
708 u_int32_t nstat_control_cleanup_source_failures
;
709 u_int32_t nstat_handle_msg_failures
;
714 #ifdef XNU_KERNEL_PRIVATE
715 #include <sys/mcache.h>
717 #pragma mark -- System Information Internal Support --
719 typedef struct nstat_sysinfo_mbuf_stats
721 u_int32_t total_256b
; /* Peak usage, 256B pool */
722 u_int32_t total_2kb
; /* Peak usage, 2KB pool */
723 u_int32_t total_4kb
; /* Peak usage, 4KB pool */
724 u_int32_t total_16kb
; /* Peak usage, 16KB pool */
725 u_int32_t sbmb_total
; /* Total mbufs in sock buffer pool */
726 u_int32_t sb_atmbuflimit
; /* Memory limit reached for socket buffer autoscaling */
727 u_int32_t draincnt
; /* Number of times mbuf pool has been drained under memory pressure */
728 u_int32_t memreleased
; /* Memory (bytes) released from mbuf pool to VM */
729 } nstat_sysinfo_mbuf_stats
;
731 typedef struct nstat_sysinfo_tcp_stats
733 u_int32_t ipv4_avgrtt
; /* Average RTT for IPv4 */
734 u_int32_t ipv6_avgrtt
; /* Average RTT for IPv6 */
735 u_int32_t send_plr
; /* Average uplink packet loss rate */
736 u_int32_t recv_plr
; /* Average downlink packet loss rate */
737 u_int32_t send_tlrto_rate
; /* Average rxt timeout after tail loss */
738 u_int32_t send_reorder_rate
; /* Average packet reordering rate */
739 u_int32_t connection_attempts
; /* TCP client connection attempts */
740 u_int32_t connection_accepts
; /* TCP server connection accepts */
741 u_int32_t ecn_client_enabled
; /* Global setting for ECN client side */
742 u_int32_t ecn_server_enabled
; /* Global setting for ECN server side */
743 u_int32_t ecn_client_setup
; /* Attempts to setup TCP client connection with ECN */
744 u_int32_t ecn_server_setup
; /* Attempts to setup TCP server connection with ECN */
745 u_int32_t ecn_client_success
; /* Number of successful negotiations of ECN for a client connection */
746 u_int32_t ecn_server_success
; /* Number of successful negotiations of ECN for a server connection */
747 u_int32_t ecn_not_supported
; /* Number of falbacks to Non-ECN, no support from peer */
748 u_int32_t ecn_lost_syn
; /* Number of SYNs lost with ECN bits */
749 u_int32_t ecn_lost_synack
; /* Number of SYN-ACKs lost with ECN bits */
750 u_int32_t ecn_recv_ce
; /* Number of CEs received from network */
751 u_int32_t ecn_recv_ece
; /* Number of ECEs received from receiver */
752 u_int32_t ecn_sent_ece
; /* Number of ECEs sent in response to CE */
753 u_int32_t ecn_conn_recv_ce
; /* Number of connections using ECN received CE at least once */
754 u_int32_t ecn_conn_recv_ece
; /* Number of connections using ECN received ECE at least once */
755 u_int32_t ecn_conn_plnoce
; /* Number of connections using ECN seen packet loss but never received CE */
756 u_int32_t ecn_conn_pl_ce
; /* Number of connections using ECN seen packet loss and CE */
757 u_int32_t ecn_conn_nopl_ce
; /* Number of connections using ECN with no packet loss but received CE */
758 u_int32_t ecn_fallback_synloss
; /* Number of times we did fall back due to SYN-Loss */
759 u_int32_t ecn_fallback_reorder
; /* Number of times we fallback because we detected the PAWS-issue */
760 u_int32_t ecn_fallback_ce
; /* Number of times we fallback because we received too many CEs */
761 u_int32_t tfo_syn_data_rcv
; /* Number of SYN+data received with valid cookie */
762 u_int32_t tfo_cookie_req_rcv
;/* Number of TFO cookie-requests received */
763 u_int32_t tfo_cookie_sent
; /* Number of TFO-cookies offered to the client */
764 u_int32_t tfo_cookie_invalid
;/* Number of invalid TFO-cookies received */
765 u_int32_t tfo_cookie_req
; /* Number of SYNs with cookie request received*/
766 u_int32_t tfo_cookie_rcv
; /* Number of SYN/ACKs with Cookie received */
767 u_int32_t tfo_syn_data_sent
; /* Number of SYNs+data+cookie sent */
768 u_int32_t tfo_syn_data_acked
;/* Number of times our SYN+data has been acknowledged */
769 u_int32_t tfo_syn_loss
; /* Number of times SYN+TFO has been lost and we fallback */
770 u_int32_t tfo_blackhole
; /* Number of times SYN+TFO has been lost and we fallback */
771 } nstat_sysinfo_tcp_stats
;
774 NSTAT_IFNET_ECN_PROTO_IPV4
= 1
775 ,NSTAT_IFNET_ECN_PROTO_IPV6
779 NSTAT_IFNET_ECN_TYPE_CELLULAR
= 1
780 ,NSTAT_IFNET_ECN_TYPE_WIFI
781 ,NSTAT_IFNET_ECN_TYPE_ETHERNET
784 typedef struct nstat_sysinfo_ifnet_ecn_stats
{
785 u_int32_t ifnet_proto
;
786 u_int32_t ifnet_type
;
787 struct if_tcp_ecn_stat ecn_stat
;
788 } nstat_sysinfo_ifnet_ecn_stats
;
790 typedef struct nstat_sysinfo_data
794 nstat_sysinfo_mbuf_stats mb_stats
;
795 nstat_sysinfo_tcp_stats tcp_stats
;
796 nstat_sysinfo_ifnet_ecn_stats ifnet_ecn_stats
;
798 } nstat_sysinfo_data
;
800 #pragma mark -- Generic Network Statistics Provider --
802 typedef void * nstat_provider_cookie_t
;
804 #pragma mark -- Route Statistics Gathering Functions --
809 NSTAT_TX_FLAG_RETRANSMIT
= 1
814 NSTAT_RX_FLAG_DUPLICATE
= 1,
815 NSTAT_RX_FLAG_OUT_OF_ORDER
= 2
818 // indicates whether or not collection of statistics is enabled
819 extern int nstat_collect
;
821 void nstat_init(void);
823 // Route collection routines
824 void nstat_route_connect_attempt(struct rtentry
*rte
);
825 void nstat_route_connect_success(struct rtentry
*rte
);
826 void nstat_route_tx(struct rtentry
*rte
, u_int32_t packets
, u_int32_t bytes
, u_int32_t flags
);
827 void nstat_route_rx(struct rtentry
*rte
, u_int32_t packets
, u_int32_t bytes
, u_int32_t flags
);
828 void nstat_route_rtt(struct rtentry
*rte
, u_int32_t rtt
, u_int32_t rtt_var
);
829 void nstat_route_detach(struct rtentry
*rte
);
833 void nstat_tcp_new_pcb(struct inpcb
*inp
);
834 void nstat_udp_new_pcb(struct inpcb
*inp
);
835 void nstat_route_new_entry(struct rtentry
*rt
);
836 void nstat_pcb_detach(struct inpcb
*inp
);
837 void nstat_pcb_cache(struct inpcb
*inp
);
838 void nstat_pcb_invalidate_cache(struct inpcb
*inp
);
841 void nstat_ifnet_threshold_reached(unsigned int ifindex
);
843 void nstat_sysinfo_send_data(struct nstat_sysinfo_data
*);
845 // locked_add_64 uses atomic operations on 32bit so the 64bit
846 // value can be properly read. The values are only ever incremented
847 // while under the socket lock, so on 64bit we don't actually need
848 // atomic operations to increment.
849 #if defined(__LP64__)
850 #define locked_add_64(__addr, __count) do { \
851 *(__addr) += (__count); \
854 #define locked_add_64(__addr, __count) do { \
855 atomic_add_64((__addr), (__count)); \
859 #endif /* XNU_KERNEL_PRIVATE */
861 #endif /* __NTSTAT_H__ */