2 * Copyright (c) 2010-2017 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 <net/net_api_stats.h>
34 #include <netinet/in_stat.h>
35 #include <netinet/tcp.h>
38 #pragma mark -- Common Data Structures --
40 #define __NSTAT_REVISION__ 9
42 typedef u_int32_t nstat_provider_id_t
;
43 typedef u_int64_t nstat_src_ref_t
;
44 typedef u_int64_t nstat_event_flags_t
;
46 // The following event definitions are very provisional..
49 NSTAT_EVENT_SRC_ADDED
= 0x00000001
50 ,NSTAT_EVENT_SRC_REMOVED
= 0x00000002
51 ,NSTAT_EVENT_SRC_QUERIED
= 0x00000004
52 ,NSTAT_EVENT_SRC_QUERIED_ALL
= 0x00000008
53 ,NSTAT_EVENT_SRC_WILL_CHANGE_STATE
= 0x00000010
54 ,NSTAT_EVENT_SRC_DID_CHANGE_STATE
= 0x00000020
55 ,NSTAT_EVENT_SRC_WILL_CHANGE_OWNER
= 0x00000040
56 ,NSTAT_EVENT_SRC_DID_CHANGE_OWNER
= 0x00000080
57 ,NSTAT_EVENT_SRC_WILL_CHANGE_PROPERTY
= 0x00000100
58 ,NSTAT_EVENT_SRC_DID_CHANGE_PROPERTY
= 0x00000200
61 typedef struct nstat_counts
64 u_int64_t nstat_rxpackets
__attribute__((aligned(sizeof(u_int64_t
))));
65 u_int64_t nstat_rxbytes
__attribute__((aligned(sizeof(u_int64_t
))));
66 u_int64_t nstat_txpackets
__attribute__((aligned(sizeof(u_int64_t
))));
67 u_int64_t nstat_txbytes
__attribute__((aligned(sizeof(u_int64_t
))));
69 u_int64_t nstat_cell_rxbytes
__attribute__((aligned(sizeof(u_int64_t
))));
70 u_int64_t nstat_cell_txbytes
__attribute__((aligned(sizeof(u_int64_t
))));
71 u_int64_t nstat_wifi_rxbytes
__attribute__((aligned(sizeof(u_int64_t
))));
72 u_int64_t nstat_wifi_txbytes
__attribute__((aligned(sizeof(u_int64_t
))));
73 u_int64_t nstat_wired_rxbytes
__attribute__((aligned(sizeof(u_int64_t
))));
74 u_int64_t nstat_wired_txbytes
__attribute__((aligned(sizeof(u_int64_t
))));
76 u_int32_t nstat_rxduplicatebytes
;
77 u_int32_t nstat_rxoutoforderbytes
;
78 u_int32_t nstat_txretransmit
;
80 u_int32_t nstat_connectattempts
;
81 u_int32_t nstat_connectsuccesses
;
83 u_int32_t nstat_min_rtt
;
84 u_int32_t nstat_avg_rtt
;
85 u_int32_t nstat_var_rtt
;
88 #define NSTAT_SYSINFO_KEYVAL_STRING_MAXSIZE 24
89 typedef struct nstat_sysinfo_keyval
91 u_int32_t nstat_sysinfo_key
;
92 u_int32_t nstat_sysinfo_flags
;
94 int64_t nstat_sysinfo_scalar
;
95 double nstat_sysinfo_distribution
;
96 u_int8_t nstat_sysinfo_string
[NSTAT_SYSINFO_KEYVAL_STRING_MAXSIZE
];
98 u_int32_t nstat_sysinfo_valsize
;
100 } nstat_sysinfo_keyval
;
102 #define NSTAT_SYSINFO_FLAG_SCALAR 0x0001
103 #define NSTAT_SYSINFO_FLAG_DISTRIBUTION 0x0002
104 #define NSTAT_SYSINFO_FLAG_STRING 0x0004
106 #define NSTAT_MAX_MSG_SIZE 4096
108 typedef struct nstat_sysinfo_counts
111 u_int32_t nstat_sysinfo_len
;
113 u_int8_t nstat_sysinfo_keyvals
[];
114 } nstat_sysinfo_counts
;
118 NSTAT_SYSINFO_KEY_MBUF_256B_TOTAL
= 1
119 ,NSTAT_SYSINFO_KEY_MBUF_2KB_TOTAL
= 2
120 ,NSTAT_SYSINFO_KEY_MBUF_4KB_TOTAL
= 3
121 ,NSTAT_SYSINFO_KEY_SOCK_MBCNT
= 4
122 ,NSTAT_SYSINFO_KEY_SOCK_ATMBLIMIT
= 5
123 ,NSTAT_SYSINFO_KEY_IPV4_AVGRTT
= 6
124 ,NSTAT_SYSINFO_KEY_IPV6_AVGRTT
= 7
125 ,NSTAT_SYSINFO_KEY_SEND_PLR
= 8
126 ,NSTAT_SYSINFO_KEY_RECV_PLR
= 9
127 ,NSTAT_SYSINFO_KEY_SEND_TLRTO
= 10
128 ,NSTAT_SYSINFO_KEY_SEND_REORDERRATE
= 11
129 ,NSTAT_SYSINFO_CONNECTION_ATTEMPTS
= 12
130 ,NSTAT_SYSINFO_CONNECTION_ACCEPTS
= 13
131 ,NSTAT_SYSINFO_ECN_CLIENT_SETUP
= 14
132 ,NSTAT_SYSINFO_ECN_SERVER_SETUP
= 15
133 ,NSTAT_SYSINFO_ECN_CLIENT_SUCCESS
= 16
134 ,NSTAT_SYSINFO_ECN_SERVER_SUCCESS
= 17
135 ,NSTAT_SYSINFO_ECN_NOT_SUPPORTED
= 18
136 ,NSTAT_SYSINFO_ECN_LOST_SYN
= 19
137 ,NSTAT_SYSINFO_ECN_LOST_SYNACK
= 20
138 ,NSTAT_SYSINFO_ECN_RECV_CE
= 21
139 ,NSTAT_SYSINFO_ECN_RECV_ECE
= 22
140 ,NSTAT_SYSINFO_ECN_SENT_ECE
= 23
141 ,NSTAT_SYSINFO_ECN_CONN_RECV_CE
= 24
142 ,NSTAT_SYSINFO_ECN_CONN_PLNOCE
= 25
143 ,NSTAT_SYSINFO_ECN_CONN_PL_CE
= 26
144 ,NSTAT_SYSINFO_ECN_CONN_NOPL_CE
= 27
145 ,NSTAT_SYSINFO_MBUF_16KB_TOTAL
= 28
146 ,NSTAT_SYSINFO_ECN_CLIENT_ENABLED
= 29
147 ,NSTAT_SYSINFO_ECN_SERVER_ENABLED
= 30
148 ,NSTAT_SYSINFO_ECN_CONN_RECV_ECE
= 31
149 ,NSTAT_SYSINFO_MBUF_MEM_RELEASED
= 32
150 ,NSTAT_SYSINFO_MBUF_DRAIN_CNT
= 33
151 ,NSTAT_SYSINFO_TFO_SYN_DATA_RCV
= 34
152 ,NSTAT_SYSINFO_TFO_COOKIE_REQ_RCV
= 35
153 ,NSTAT_SYSINFO_TFO_COOKIE_SENT
= 36
154 ,NSTAT_SYSINFO_TFO_COOKIE_INVALID
= 37
155 ,NSTAT_SYSINFO_TFO_COOKIE_REQ
= 38
156 ,NSTAT_SYSINFO_TFO_COOKIE_RCV
= 39
157 ,NSTAT_SYSINFO_TFO_SYN_DATA_SENT
= 40
158 ,NSTAT_SYSINFO_TFO_SYN_DATA_ACKED
= 41
159 ,NSTAT_SYSINFO_TFO_SYN_LOSS
= 42
160 ,NSTAT_SYSINFO_TFO_BLACKHOLE
= 43
161 ,NSTAT_SYSINFO_ECN_FALLBACK_SYNLOSS
= 44
162 ,NSTAT_SYSINFO_ECN_FALLBACK_REORDER
= 45
163 ,NSTAT_SYSINFO_ECN_FALLBACK_CE
= 46
164 ,NSTAT_SYSINFO_ECN_IFNET_TYPE
= 47
165 ,NSTAT_SYSINFO_ECN_IFNET_PROTO
= 48
166 ,NSTAT_SYSINFO_ECN_IFNET_CLIENT_SETUP
= 49
167 ,NSTAT_SYSINFO_ECN_IFNET_SERVER_SETUP
= 50
168 ,NSTAT_SYSINFO_ECN_IFNET_CLIENT_SUCCESS
= 51
169 ,NSTAT_SYSINFO_ECN_IFNET_SERVER_SUCCESS
= 52
170 ,NSTAT_SYSINFO_ECN_IFNET_PEER_NOSUPPORT
= 53
171 ,NSTAT_SYSINFO_ECN_IFNET_SYN_LOST
= 54
172 ,NSTAT_SYSINFO_ECN_IFNET_SYNACK_LOST
= 55
173 ,NSTAT_SYSINFO_ECN_IFNET_RECV_CE
= 56
174 ,NSTAT_SYSINFO_ECN_IFNET_RECV_ECE
= 57
175 ,NSTAT_SYSINFO_ECN_IFNET_SENT_ECE
= 58
176 ,NSTAT_SYSINFO_ECN_IFNET_CONN_RECV_CE
= 59
177 ,NSTAT_SYSINFO_ECN_IFNET_CONN_RECV_ECE
= 60
178 ,NSTAT_SYSINFO_ECN_IFNET_CONN_PLNOCE
= 61
179 ,NSTAT_SYSINFO_ECN_IFNET_CONN_PLCE
= 62
180 ,NSTAT_SYSINFO_ECN_IFNET_CONN_NOPLCE
= 63
181 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_SYNLOSS
= 64
182 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_REORDER
= 65
183 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_CE
= 66
184 ,NSTAT_SYSINFO_ECN_IFNET_ON_RTT_AVG
= 67
185 ,NSTAT_SYSINFO_ECN_IFNET_ON_RTT_VAR
= 68
186 ,NSTAT_SYSINFO_ECN_IFNET_ON_OOPERCENT
= 69
187 ,NSTAT_SYSINFO_ECN_IFNET_ON_SACK_EPISODE
= 70
188 ,NSTAT_SYSINFO_ECN_IFNET_ON_REORDER_PERCENT
= 71
189 ,NSTAT_SYSINFO_ECN_IFNET_ON_RXMIT_PERCENT
= 72
190 ,NSTAT_SYSINFO_ECN_IFNET_ON_RXMIT_DROP
= 73
191 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RTT_AVG
= 74
192 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RTT_VAR
= 75
193 ,NSTAT_SYSINFO_ECN_IFNET_OFF_OOPERCENT
= 76
194 ,NSTAT_SYSINFO_ECN_IFNET_OFF_SACK_EPISODE
= 77
195 ,NSTAT_SYSINFO_ECN_IFNET_OFF_REORDER_PERCENT
= 78
196 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RXMIT_PERCENT
= 79
197 ,NSTAT_SYSINFO_ECN_IFNET_OFF_RXMIT_DROP
= 80
198 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_TXPKTS
= 81
199 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_RXMTPKTS
= 82
200 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_RXPKTS
= 83
201 ,NSTAT_SYSINFO_ECN_IFNET_ON_TOTAL_OOPKTS
= 84
202 ,NSTAT_SYSINFO_ECN_IFNET_ON_DROP_RST
= 85
203 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_TXPKTS
= 86
204 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_RXMTPKTS
= 87
205 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_RXPKTS
= 88
206 ,NSTAT_SYSINFO_ECN_IFNET_OFF_TOTAL_OOPKTS
= 89
207 ,NSTAT_SYSINFO_ECN_IFNET_OFF_DROP_RST
= 90
208 ,NSTAT_SYSINFO_ECN_IFNET_TOTAL_CONN
= 91
209 ,NSTAT_SYSINFO_TFO_COOKIE_WRONG
= 92
210 ,NSTAT_SYSINFO_TFO_NO_COOKIE_RCV
= 93
211 ,NSTAT_SYSINFO_TFO_HEURISTICS_DISABLE
= 94
212 ,NSTAT_SYSINFO_TFO_SEND_BLACKHOLE
= 95
213 ,NSTAT_SYSINFO_KEY_SOCK_MBFLOOR
= 96
214 ,NSTAT_SYSINFO_IFNET_UNSENT_DATA
= 97
215 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_DROPRST
= 98
216 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_DROPRXMT
= 99
217 ,NSTAT_SYSINFO_LIM_IFNET_SIGNATURE
= 100
218 ,NSTAT_SYSINFO_LIM_IFNET_DL_MAX_BANDWIDTH
= 101
219 ,NSTAT_SYSINFO_LIM_IFNET_UL_MAX_BANDWIDTH
= 102
220 ,NSTAT_SYSINFO_LIM_IFNET_PACKET_LOSS_PERCENT
= 103
221 ,NSTAT_SYSINFO_LIM_IFNET_PACKET_OOO_PERCENT
= 104
222 ,NSTAT_SYSINFO_LIM_IFNET_RTT_VARIANCE
= 105
223 ,NSTAT_SYSINFO_LIM_IFNET_RTT_MIN
= 106
224 ,NSTAT_SYSINFO_LIM_IFNET_RTT_AVG
= 107
225 ,NSTAT_SYSINFO_LIM_IFNET_CONN_TIMEOUT_PERCENT
= 108
226 ,NSTAT_SYSINFO_LIM_IFNET_DL_DETECTED
= 109
227 ,NSTAT_SYSINFO_LIM_IFNET_UL_DETECTED
= 110
228 ,NSTAT_SYSINFO_LIM_IFNET_TYPE
= 111
230 ,NSTAT_SYSINFO_API_IF_FLTR_ATTACH
= 112
231 ,NSTAT_SYSINFO_API_IF_FLTR_ATTACH_OS
= 113
232 ,NSTAT_SYSINFO_API_IP_FLTR_ADD
= 114
233 ,NSTAT_SYSINFO_API_IP_FLTR_ADD_OS
= 115
234 ,NSTAT_SYSINFO_API_SOCK_FLTR_ATTACH
= 116
235 ,NSTAT_SYSINFO_API_SOCK_FLTR_ATTACH_OS
= 117
237 ,NSTAT_SYSINFO_API_SOCK_ALLOC_TOTAL
= 118
238 ,NSTAT_SYSINFO_API_SOCK_ALLOC_KERNEL
= 119
239 ,NSTAT_SYSINFO_API_SOCK_ALLOC_KERNEL_OS
= 120
240 ,NSTAT_SYSINFO_API_SOCK_NECP_CLIENTUUID
= 121
242 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_LOCAL
= 122
243 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_ROUTE
= 123
244 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_INET
= 124
245 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_INET6
= 125
246 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_SYSTEM
= 126
247 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_MULTIPATH
= 127
248 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_KEY
= 128
249 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_NDRV
= 129
250 ,NSTAT_SYSINFO_API_SOCK_DOMAIN_OTHER
= 130
252 ,NSTAT_SYSINFO_API_SOCK_INET_STREAM
= 131
253 ,NSTAT_SYSINFO_API_SOCK_INET_DGRAM
= 132
254 ,NSTAT_SYSINFO_API_SOCK_INET_DGRAM_CONNECTED
= 133
255 ,NSTAT_SYSINFO_API_SOCK_INET_DGRAM_DNS
= 134
256 ,NSTAT_SYSINFO_API_SOCK_INET_DGRAM_NO_DATA
= 135
258 ,NSTAT_SYSINFO_API_SOCK_INET6_STREAM
= 136
259 ,NSTAT_SYSINFO_API_SOCK_INET6_DGRAM
= 137
260 ,NSTAT_SYSINFO_API_SOCK_INET6_DGRAM_CONNECTED
= 138
261 ,NSTAT_SYSINFO_API_SOCK_INET6_DGRAM_DNS
= 139
262 ,NSTAT_SYSINFO_API_SOCK_INET6_DGRAM_NO_DATA
= 140
264 ,NSTAT_SYSINFO_API_SOCK_INET_MCAST_JOIN
= 141
265 ,NSTAT_SYSINFO_API_SOCK_INET_MCAST_JOIN_OS
= 142
267 ,NSTAT_SYSINFO_API_SOCK_INET6_STREAM_EXTHDR_IN
= 143
268 ,NSTAT_SYSINFO_API_SOCK_INET6_STREAM_EXTHDR_OUT
= 144
269 ,NSTAT_SYSINFO_API_SOCK_INET6_DGRAM_EXTHDR_IN
= 145
270 ,NSTAT_SYSINFO_API_SOCK_INET6_DGRAM_EXTHDR_OUT
= 146
272 ,NSTAT_SYSINFO_API_NEXUS_FLOW_INET_STREAM
= 147
273 ,NSTAT_SYSINFO_API_NEXUS_FLOW_INET_DATAGRAM
= 148
275 ,NSTAT_SYSINFO_API_NEXUS_FLOW_INET6_STREAM
= 149
276 ,NSTAT_SYSINFO_API_NEXUS_FLOW_INET6_DATAGRAM
= 150
278 ,NSTAT_SYSINFO_API_IFNET_ALLOC
= 151
279 ,NSTAT_SYSINFO_API_IFNET_ALLOC_OS
= 152
281 ,NSTAT_SYSINFO_API_PF_ADDRULE
= 153
282 ,NSTAT_SYSINFO_API_PF_ADDRULE_OS
= 154
284 ,NSTAT_SYSINFO_API_VMNET_START
= 155
286 ,NSTAT_SYSINFO_API_IF_NETAGENT_ENABLED
= 156
288 ,NSTAT_SYSINFO_API_REPORT_INTERVAL
= 157
290 ,NSTAT_SYSINFO_MPTCP_HANDOVER_ATTEMPT
= 158
291 ,NSTAT_SYSINFO_MPTCP_INTERACTIVE_ATTEMPT
= 159
292 ,NSTAT_SYSINFO_MPTCP_AGGREGATE_ATTEMPT
= 160
293 ,NSTAT_SYSINFO_MPTCP_FP_HANDOVER_ATTEMPT
= 161 /* _FP_ stands for first-party */
294 ,NSTAT_SYSINFO_MPTCP_FP_INTERACTIVE_ATTEMPT
= 162
295 ,NSTAT_SYSINFO_MPTCP_FP_AGGREGATE_ATTEMPT
= 163
296 ,NSTAT_SYSINFO_MPTCP_HEURISTIC_FALLBACK
= 164
297 ,NSTAT_SYSINFO_MPTCP_FP_HEURISTIC_FALLBACK
= 165
298 ,NSTAT_SYSINFO_MPTCP_HANDOVER_SUCCESS_WIFI
= 166
299 ,NSTAT_SYSINFO_MPTCP_HANDOVER_SUCCESS_CELL
= 167
300 ,NSTAT_SYSINFO_MPTCP_INTERACTIVE_SUCCESS
= 168
301 ,NSTAT_SYSINFO_MPTCP_AGGREGATE_SUCCESS
= 169
302 ,NSTAT_SYSINFO_MPTCP_FP_HANDOVER_SUCCESS_WIFI
= 170
303 ,NSTAT_SYSINFO_MPTCP_FP_HANDOVER_SUCCESS_CELL
= 171
304 ,NSTAT_SYSINFO_MPTCP_FP_INTERACTIVE_SUCCESS
= 172
305 ,NSTAT_SYSINFO_MPTCP_FP_AGGREGATE_SUCCESS
= 173
306 ,NSTAT_SYSINFO_MPTCP_HANDOVER_CELL_FROM_WIFI
= 174
307 ,NSTAT_SYSINFO_MPTCP_HANDOVER_WIFI_FROM_CELL
= 175
308 ,NSTAT_SYSINFO_MPTCP_INTERACTIVE_CELL_FROM_WIFI
= 176
309 ,NSTAT_SYSINFO_MPTCP_HANDOVER_CELL_BYTES
= 177
310 ,NSTAT_SYSINFO_MPTCP_INTERACTIVE_CELL_BYTES
= 178
311 ,NSTAT_SYSINFO_MPTCP_AGGREGATE_CELL_BYTES
= 179
312 ,NSTAT_SYSINFO_MPTCP_HANDOVER_ALL_BYTES
= 180
313 ,NSTAT_SYSINFO_MPTCP_INTERACTIVE_ALL_BYTES
= 181
314 ,NSTAT_SYSINFO_MPTCP_AGGREGATE_ALL_BYTES
= 182
315 ,NSTAT_SYSINFO_MPTCP_BACK_TO_WIFI
= 183
316 ,NSTAT_SYSINFO_MPTCP_WIFI_PROXY
= 184
317 ,NSTAT_SYSINFO_MPTCP_CELL_PROXY
= 185
318 ,NSTAT_SYSINFO_ECN_IFNET_FALLBACK_SYNRST
= 186
320 // NSTAT_SYSINFO_ENUM_VERSION must be updated any time a value is added
321 #define NSTAT_SYSINFO_ENUM_VERSION 20170623
324 #define NSTAT_SYSINFO_API_FIRST NSTAT_SYSINFO_API_IF_FLTR_ATTACH
325 #define NSTAT_SYSINFO_API_LAST NSTAT_SYSINFO_API_REPORT_INTERVAL
327 #pragma mark -- Network Statistics Providers --
330 // Interface properties
332 #define NSTAT_IFNET_IS_UNKNOWN_TYPE 0x01
333 #define NSTAT_IFNET_IS_LOOPBACK 0x02
334 #define NSTAT_IFNET_IS_CELLULAR 0x04
335 #define NSTAT_IFNET_IS_WIFI 0x08
336 #define NSTAT_IFNET_IS_WIRED 0x10
337 #define NSTAT_IFNET_IS_AWDL 0x20
338 #define NSTAT_IFNET_IS_EXPENSIVE 0x40
339 #define NSTAT_IFNET_IS_VPN 0x80
340 #define NSTAT_IFNET_VIA_CELLFALLBACK 0x100
341 // Temporary properties of use for bringing up userland providers
342 #define NSTAT_IFNET_ROUTE_VALUE_UNOBTAINABLE 0x1000
343 #define NSTAT_IFNET_FLOWSWITCH_VALUE_UNOBTAINABLE 0x2000
348 NSTAT_PROVIDER_NONE
= 0
349 ,NSTAT_PROVIDER_ROUTE
= 1
350 ,NSTAT_PROVIDER_TCP_KERNEL
= 2
351 ,NSTAT_PROVIDER_TCP_USERLAND
= 3
352 ,NSTAT_PROVIDER_UDP_KERNEL
= 4
353 ,NSTAT_PROVIDER_UDP_USERLAND
= 5
354 ,NSTAT_PROVIDER_IFNET
= 6
355 ,NSTAT_PROVIDER_SYSINFO
= 7
357 #define NSTAT_PROVIDER_LAST NSTAT_PROVIDER_SYSINFO
358 #define NSTAT_PROVIDER_COUNT (NSTAT_PROVIDER_LAST+1)
360 typedef struct nstat_route_add_param
364 struct sockaddr_in v4
;
365 struct sockaddr_in6 v6
;
369 struct sockaddr_in v4
;
370 struct sockaddr_in6 v6
;
373 } nstat_route_add_param
;
375 typedef struct nstat_tcp_add_param
379 struct sockaddr_in v4
;
380 struct sockaddr_in6 v6
;
384 struct sockaddr_in v4
;
385 struct sockaddr_in6 v6
;
387 } nstat_tcp_add_param
;
389 typedef struct nstat_tcp_descriptor
391 u_int64_t upid
__attribute__((aligned(sizeof(u_int64_t
))));
392 u_int64_t eupid
__attribute__((aligned(sizeof(u_int64_t
))));
393 u_int64_t start_timestamp
__attribute__((aligned(sizeof(u_int64_t
))));
394 u_int64_t timestamp
__attribute__((aligned(sizeof(u_int64_t
))));
396 activity_bitmap_t activity_bitmap
;
401 u_int32_t sndbufsize
;
402 u_int32_t sndbufused
;
403 u_int32_t rcvbufsize
;
404 u_int32_t rcvbufused
;
408 u_int32_t traffic_class
;
409 u_int32_t traffic_mgt_flags
;
416 struct sockaddr_in v4
;
417 struct sockaddr_in6 v6
;
422 struct sockaddr_in v4
;
423 struct sockaddr_in6 v6
;
433 struct tcp_conn_status connstatus
;
434 // On armv7k, tcp_conn_status is 1 byte instead of 4
435 uint8_t __pad_connstatus
[4];
437 uint16_t ifnet_properties
__attribute__((aligned(4)));
439 u_int8_t reserved
[6];
440 } nstat_tcp_descriptor
;
442 typedef struct nstat_tcp_add_param nstat_udp_add_param
;
444 typedef struct nstat_udp_descriptor
446 u_int64_t upid
__attribute__((aligned(sizeof(u_int64_t
))));
447 u_int64_t eupid
__attribute__((aligned(sizeof(u_int64_t
))));
448 u_int64_t start_timestamp
__attribute__((aligned(sizeof(u_int64_t
))));
449 u_int64_t timestamp
__attribute__((aligned(sizeof(u_int64_t
))));
451 activity_bitmap_t activity_bitmap
;
455 struct sockaddr_in v4
;
456 struct sockaddr_in6 v6
;
461 struct sockaddr_in v4
;
462 struct sockaddr_in6 v6
;
467 u_int32_t rcvbufsize
;
468 u_int32_t rcvbufused
;
469 u_int32_t traffic_class
;
478 uint16_t ifnet_properties
;
480 u_int8_t reserved
[6];
481 } nstat_udp_descriptor
;
483 typedef struct nstat_route_descriptor
485 u_int64_t id
__attribute__((aligned(sizeof(u_int64_t
))));
486 u_int64_t parent_id
__attribute__((aligned(sizeof(u_int64_t
))));
487 u_int64_t gateway_id
__attribute__((aligned(sizeof(u_int64_t
))));
491 struct sockaddr_in v4
;
492 struct sockaddr_in6 v6
;
498 struct sockaddr_in v4
;
499 struct sockaddr_in6 v6
;
505 struct sockaddr_in v4
;
506 struct sockaddr_in6 v6
;
513 u_int8_t reserved
[4];
514 } nstat_route_descriptor
;
516 typedef struct nstat_ifnet_add_param
518 u_int64_t threshold
__attribute__((aligned(sizeof(u_int64_t
))));
521 u_int8_t reserved
[4];
522 } nstat_ifnet_add_param
;
524 typedef struct nstat_ifnet_desc_cellular_status
526 u_int32_t valid_bitmask
; /* indicates which fields are valid */
527 #define NSTAT_IFNET_DESC_CELL_LINK_QUALITY_METRIC_VALID 0x1
528 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
529 #define NSTAT_IFNET_DESC_CELL_UL_MAX_BANDWIDTH_VALID 0x4
530 #define NSTAT_IFNET_DESC_CELL_UL_MIN_LATENCY_VALID 0x8
531 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
532 #define NSTAT_IFNET_DESC_CELL_UL_MAX_LATENCY_VALID 0x20
533 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_VALID 0x40
534 #define NSTAT_IFNET_DESC_CELL_UL_BYTES_LOST_VALID 0x80
535 #define NSTAT_IFNET_DESC_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
536 #define NSTAT_IFNET_DESC_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
537 #define NSTAT_IFNET_DESC_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
538 #define NSTAT_IFNET_DESC_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
539 #define NSTAT_IFNET_DESC_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
540 #define NSTAT_IFNET_DESC_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
541 #define NSTAT_IFNET_DESC_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
542 #define NSTAT_IFNET_DESC_CELL_MSS_RECOMMENDED_VALID 0x8000
543 u_int32_t link_quality_metric
;
544 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on
545 current activity (bps) */
546 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth
548 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop
550 u_int32_t ul_effective_latency
; /* current expected uplink latency for
552 u_int32_t ul_max_latency
; /* max expected uplink latency first hop
554 u_int32_t ul_retxt_level
; /* Retransmission metric */
555 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_NONE 1
556 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_LOW 2
557 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_MEDIUM 3
558 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_HIGH 4
560 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10
562 u_int32_t ul_min_queue_size
; /* minimum bytes in queue */
563 u_int32_t ul_avg_queue_size
; /* average bytes in queue */
564 u_int32_t ul_max_queue_size
; /* maximum bytes in queue */
565 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based
566 on current activity (bps) */
567 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth
569 u_int32_t config_inactivity_time
; /* ms */
570 u_int32_t config_backoff_time
; /* new connections backoff time in ms */
571 #define NSTAT_IFNET_DESC_MSS_RECOMMENDED_NONE 0x0
572 #define NSTAT_IFNET_DESC_MSS_RECOMMENDED_MEDIUM 0x1
573 #define NSTAT_IFNET_DESC_MSS_RECOMMENDED_LOW 0x2
574 u_int16_t mss_recommended
; /* recommended MSS */
575 u_int8_t reserved
[2];
576 } nstat_ifnet_desc_cellular_status
;
578 typedef struct nstat_ifnet_desc_wifi_status
{
579 u_int32_t valid_bitmask
;
580 #define NSTAT_IFNET_DESC_WIFI_LINK_QUALITY_METRIC_VALID 0x1
581 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
582 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
583 #define NSTAT_IFNET_DESC_WIFI_UL_MIN_LATENCY_VALID 0x8
584 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
585 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_LATENCY_VALID 0x20
586 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_VALID 0x40
587 #define NSTAT_IFNET_DESC_WIFI_UL_ERROR_RATE_VALID 0x80
588 #define NSTAT_IFNET_DESC_WIFI_UL_BYTES_LOST_VALID 0x100
589 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
590 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
591 #define NSTAT_IFNET_DESC_WIFI_DL_MIN_LATENCY_VALID 0x800
592 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
593 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_LATENCY_VALID 0x2000
594 #define NSTAT_IFNET_DESC_WIFI_DL_ERROR_RATE_VALID 0x4000
595 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_VALID 0x8000
596 #define NSTAT_IFNET_DESC_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
597 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
598 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
599 u_int32_t link_quality_metric
; /* link quality metric */
600 u_int32_t ul_effective_bandwidth
; /* Measured uplink bandwidth based on
601 current activity (bps) */
602 u_int32_t ul_max_bandwidth
; /* Maximum supported uplink bandwidth
604 u_int32_t ul_min_latency
; /* min expected uplink latency for first hop
606 u_int32_t ul_effective_latency
; /* current expected uplink latency for
608 u_int32_t ul_max_latency
; /* max expected uplink latency for first hop
610 u_int32_t ul_retxt_level
; /* Retransmission metric */
611 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_NONE 1
612 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_LOW 2
613 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_MEDIUM 3
614 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_HIGH 4
616 u_int32_t ul_bytes_lost
; /* % of total bytes lost on uplink in Q10
618 u_int32_t ul_error_rate
; /* % of bytes dropped on uplink after many
619 retransmissions in Q10 format */
620 u_int32_t dl_effective_bandwidth
; /* Measured downlink bandwidth based
621 on current activity (bps) */
622 u_int32_t dl_max_bandwidth
; /* Maximum supported downlink bandwidth
625 * The download latency values indicate the time AP may have to wait
626 * for the driver to receive the packet. These values give the range
627 * of expected latency mainly due to co-existence events and channel
628 * hopping where the interface becomes unavailable.
630 u_int32_t dl_min_latency
; /* min expected latency for first hop in ms */
631 u_int32_t dl_effective_latency
; /* current expected latency for first
633 u_int32_t dl_max_latency
; /* max expected latency for first hop in ms */
634 u_int32_t dl_error_rate
; /* % of CRC or other errors in Q10 format */
635 u_int32_t config_frequency
; /* 2.4 or 5 GHz */
636 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
637 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
638 u_int32_t config_multicast_rate
; /* bps */
639 u_int32_t scan_count
; /* scan count during the previous period */
640 u_int32_t scan_duration
; /* scan duration in ms */
641 } nstat_ifnet_desc_wifi_status
;
645 NSTAT_IFNET_DESC_LINK_STATUS_TYPE_NONE
= 0
646 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_CELLULAR
= 1
647 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_WIFI
= 2
648 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_ETHERNET
= 3
651 typedef struct nstat_ifnet_desc_link_status
653 u_int32_t link_status_type
;
655 nstat_ifnet_desc_cellular_status cellular
;
656 nstat_ifnet_desc_wifi_status wifi
;
658 } nstat_ifnet_desc_link_status
;
661 #define IF_DESCSIZE 128
663 typedef struct nstat_ifnet_descriptor
665 u_int64_t threshold
__attribute__((aligned(sizeof(u_int64_t
))));
667 nstat_ifnet_desc_link_status link_status
;
669 char description
[IF_DESCSIZE
];
670 char name
[IFNAMSIZ
+1];
671 u_int8_t reserved
[3];
672 } nstat_ifnet_descriptor
;
674 typedef struct nstat_sysinfo_descriptor
677 } nstat_sysinfo_descriptor
;
679 typedef struct nstat_sysinfo_add_param
681 /* To indicate which system level information should be collected */
683 } nstat_sysinfo_add_param
;
685 #define NSTAT_SYSINFO_MBUF_STATS 0x0001
686 #define NSTAT_SYSINFO_TCP_STATS 0x0002
687 #define NSTAT_SYSINFO_IFNET_ECN_STATS 0x0003
688 #define NSTAT_SYSINFO_LIM_STATS 0x0004 /* Low Internet mode stats */
689 #define NSTAT_SYSINFO_NET_API_STATS 0x0005 /* API and KPI stats */
691 #pragma mark -- Network Statistics User Client --
693 #define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
697 // generic response messages
698 NSTAT_MSG_TYPE_SUCCESS
= 0
699 ,NSTAT_MSG_TYPE_ERROR
= 1
702 ,NSTAT_MSG_TYPE_ADD_SRC
= 1001
703 ,NSTAT_MSG_TYPE_ADD_ALL_SRCS
= 1002
704 ,NSTAT_MSG_TYPE_REM_SRC
= 1003
705 ,NSTAT_MSG_TYPE_QUERY_SRC
= 1004
706 ,NSTAT_MSG_TYPE_GET_SRC_DESC
= 1005
707 ,NSTAT_MSG_TYPE_SET_FILTER
= 1006
708 ,NSTAT_MSG_TYPE_GET_UPDATE
= 1007
709 ,NSTAT_MSG_TYPE_SUBSCRIBE_SYSINFO
= 1008
711 // Responses/Notfications
712 ,NSTAT_MSG_TYPE_SRC_ADDED
= 10001
713 ,NSTAT_MSG_TYPE_SRC_REMOVED
= 10002
714 ,NSTAT_MSG_TYPE_SRC_DESC
= 10003
715 ,NSTAT_MSG_TYPE_SRC_COUNTS
= 10004
716 ,NSTAT_MSG_TYPE_SYSINFO_COUNTS
= 10005
717 ,NSTAT_MSG_TYPE_SRC_UPDATE
= 10006
722 NSTAT_SRC_REF_ALL
= 0xffffffffffffffffULL
723 ,NSTAT_SRC_REF_INVALID
= 0
726 /* Source-level filters */
729 NSTAT_FILTER_NOZEROBYTES
= 0x00000001
732 /* Provider-level filters */
735 NSTAT_FILTER_ACCEPT_UNKNOWN
= 0x00000001
736 ,NSTAT_FILTER_ACCEPT_LOOPBACK
= 0x00000002
737 ,NSTAT_FILTER_ACCEPT_CELLULAR
= 0x00000004
738 ,NSTAT_FILTER_ACCEPT_WIFI
= 0x00000008
739 ,NSTAT_FILTER_ACCEPT_WIRED
= 0x00000010
740 ,NSTAT_FILTER_ACCEPT_AWDL
= 0x00000020
741 ,NSTAT_FILTER_ACCEPT_EXPENSIVE
= 0x00000040
742 ,NSTAT_FILTER_ACCEPT_CELLFALLBACK
= 0x00000100
743 ,NSTAT_FILTER_IFNET_FLAGS
= 0x00000FFF
745 ,NSTAT_FILTER_TCP_NO_LISTENER
= 0x00001000
746 ,NSTAT_FILTER_TCP_ONLY_LISTENER
= 0x00002000
747 ,NSTAT_FILTER_TCP_INTERFACE_ATTACH
= 0x00004000
748 ,NSTAT_FILTER_TCP_NO_EARLY_CLOSE
= 0x00008000
749 ,NSTAT_FILTER_TCP_FLAGS
= 0x0000F000
751 ,NSTAT_FILTER_UDP_INTERFACE_ATTACH
= 0x00010000
752 ,NSTAT_FILTER_UDP_FLAGS
= 0x000F0000
754 ,NSTAT_FILTER_SUPPRESS_SRC_ADDED
= 0x00100000
755 ,NSTAT_FILTER_REQUIRE_SRC_ADDED
= 0x00200000
756 ,NSTAT_FILTER_PROVIDER_NOZEROBYTES
= 0x00400000
758 ,NSTAT_FILTER_SPECIFIC_USER_BY_PID
= 0x01000000
759 ,NSTAT_FILTER_SPECIFIC_USER_BY_EPID
= 0x02000000
760 ,NSTAT_FILTER_SPECIFIC_USER_BY_UUID
= 0x04000000
761 ,NSTAT_FILTER_SPECIFIC_USER_BY_EUUID
= 0x08000000
762 ,NSTAT_FILTER_SPECIFIC_USER
= 0x0F000000
767 NSTAT_MSG_HDR_FLAG_SUPPORTS_AGGREGATE
= 1 << 0,
768 NSTAT_MSG_HDR_FLAG_CONTINUATION
= 1 << 1,
769 NSTAT_MSG_HDR_FLAG_CLOSING
= 1 << 2,
772 typedef struct nstat_msg_hdr
774 u_int64_t context
__attribute__((aligned(sizeof(u_int64_t
))));
780 typedef struct nstat_msg_error
783 u_int32_t error
; // errno error
784 u_int8_t reserved
[4];
787 #define NSTAT_ADD_SRC_FIELDS \
789 nstat_provider_id_t provider; \
790 u_int8_t reserved[4] \
792 typedef struct nstat_msg_add_src
794 NSTAT_ADD_SRC_FIELDS
;
796 } nstat_msg_add_src_req
;
798 typedef struct nstat_msg_add_src_header
800 NSTAT_ADD_SRC_FIELDS
;
801 } nstat_msg_add_src_header
;
803 typedef struct nstat_msg_add_src_convenient
805 nstat_msg_add_src_header hdr
;
807 nstat_route_add_param route
;
808 nstat_tcp_add_param tcp
;
809 nstat_udp_add_param udp
;
810 nstat_ifnet_add_param ifnet
;
811 nstat_sysinfo_add_param sysinfo
;
813 } nstat_msg_add_src_convenient
;
815 #undef NSTAT_ADD_SRC_FIELDS
817 typedef struct nstat_msg_add_all_srcs
820 u_int64_t filter
__attribute__((aligned(sizeof(u_int64_t
))));
821 nstat_event_flags_t events
__attribute__((aligned(sizeof(u_int64_t
))));
822 nstat_provider_id_t provider
;
825 } nstat_msg_add_all_srcs
;
827 typedef struct nstat_msg_src_added
830 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
831 nstat_provider_id_t provider
;
832 u_int8_t reserved
[4];
833 } nstat_msg_src_added
;
835 typedef struct nstat_msg_rem_src
838 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
839 } nstat_msg_rem_src_req
;
841 typedef struct nstat_msg_get_src_description
844 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
845 } nstat_msg_get_src_description
;
847 typedef struct nstat_msg_set_filter
850 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
852 u_int8_t reserved
[4];
853 } nstat_msg_set_filter
;
855 #define NSTAT_SRC_DESCRIPTION_FIELDS \
857 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t)))); \
858 nstat_event_flags_t event_flags __attribute__((aligned(sizeof(u_int64_t)))); \
859 nstat_provider_id_t provider; \
862 typedef struct nstat_msg_src_description
864 NSTAT_SRC_DESCRIPTION_FIELDS
;
866 } nstat_msg_src_description
;
868 typedef struct nstat_msg_src_description_header
870 NSTAT_SRC_DESCRIPTION_FIELDS
;
871 } nstat_msg_src_description_header
;
873 typedef struct nstat_msg_src_description_convenient
875 nstat_msg_src_description_header hdr
;
877 nstat_tcp_descriptor tcp
;
878 nstat_udp_descriptor udp
;
879 nstat_route_descriptor route
;
880 nstat_ifnet_descriptor ifnet
;
881 nstat_sysinfo_descriptor sysinfo
;
883 } nstat_msg_src_description_convenient
;
885 #undef NSTAT_SRC_DESCRIPTION_FIELDS
887 typedef struct nstat_msg_query_src
890 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
891 } nstat_msg_query_src_req
;
893 typedef struct nstat_msg_src_counts
896 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
897 nstat_event_flags_t event_flags
__attribute__((aligned(sizeof(u_int64_t
))));
899 } nstat_msg_src_counts
;
901 #define NSTAT_SRC_UPDATE_FIELDS \
903 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t)))); \
904 nstat_event_flags_t event_flags __attribute__((aligned(sizeof(u_int64_t)))); \
905 nstat_counts counts; \
906 nstat_provider_id_t provider; \
909 typedef struct nstat_msg_src_update
911 NSTAT_SRC_UPDATE_FIELDS
;
913 } nstat_msg_src_update
;
915 typedef struct nstat_msg_src_update_hdr
917 NSTAT_SRC_UPDATE_FIELDS
;
918 } nstat_msg_src_update_hdr
;
920 typedef struct nstat_msg_src_update_convenient
922 nstat_msg_src_update_hdr hdr
;
924 nstat_tcp_descriptor tcp
;
925 nstat_udp_descriptor udp
;
926 nstat_route_descriptor route
;
927 nstat_ifnet_descriptor ifnet
;
928 nstat_sysinfo_descriptor sysinfo
;
930 } nstat_msg_src_update_convenient
;
932 #undef NSTAT_SRC_UPDATE_FIELDS
934 typedef struct nstat_msg_src_removed
937 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
938 } nstat_msg_src_removed
;
940 typedef struct nstat_msg_sysinfo_counts
943 nstat_src_ref_t srcref
__attribute__((aligned(sizeof(u_int64_t
))));
944 nstat_sysinfo_counts counts
;
945 } nstat_msg_sysinfo_counts
;
947 #pragma mark -- Statitiscs about Network Statistics --
950 u_int32_t nstat_successmsgfailures
;
951 u_int32_t nstat_sendcountfailures
;
952 u_int32_t nstat_sysinfofailures
;
953 u_int32_t nstat_srcupatefailures
;
954 u_int32_t nstat_descriptionfailures
;
955 u_int32_t nstat_msgremovedfailures
;
956 u_int32_t nstat_srcaddedfailures
;
957 u_int32_t nstat_msgerrorfailures
;
958 u_int32_t nstat_copy_descriptor_failures
;
959 u_int32_t nstat_provider_counts_failures
;
960 u_int32_t nstat_control_send_description_failures
;
961 u_int32_t nstat_control_send_goodbye_failures
;
962 u_int32_t nstat_flush_accumulated_msgs_failures
;
963 u_int32_t nstat_accumulate_msg_failures
;
964 u_int32_t nstat_control_cleanup_source_failures
;
965 u_int32_t nstat_handle_msg_failures
;
970 #ifdef XNU_KERNEL_PRIVATE
971 #include <sys/mcache.h>
973 #pragma mark -- System Information Internal Support --
975 typedef struct nstat_sysinfo_mbuf_stats
977 u_int32_t total_256b
; /* Peak usage, 256B pool */
978 u_int32_t total_2kb
; /* Peak usage, 2KB pool */
979 u_int32_t total_4kb
; /* Peak usage, 4KB pool */
980 u_int32_t total_16kb
; /* Peak usage, 16KB pool */
981 u_int32_t sbmb_total
; /* Total mbufs in sock buffer pool */
982 u_int32_t sb_atmbuflimit
; /* Memory limit reached for socket buffer autoscaling */
983 u_int32_t draincnt
; /* Number of times mbuf pool has been drained under memory pressure */
984 u_int32_t memreleased
; /* Memory (bytes) released from mbuf pool to VM */
985 u_int32_t sbmb_floor
; /* Lowest mbufs in sock buffer pool */
986 } nstat_sysinfo_mbuf_stats
;
988 typedef struct nstat_sysinfo_tcp_stats
990 /* When adding/removing here, also adjust NSTAT_SYSINFO_TCP_STATS_COUNT */
991 u_int32_t ipv4_avgrtt
; /* Average RTT for IPv4 */
992 u_int32_t ipv6_avgrtt
; /* Average RTT for IPv6 */
993 u_int32_t send_plr
; /* Average uplink packet loss rate */
994 u_int32_t recv_plr
; /* Average downlink packet loss rate */
995 u_int32_t send_tlrto_rate
; /* Average rxt timeout after tail loss */
996 u_int32_t send_reorder_rate
; /* Average packet reordering rate */
997 u_int32_t connection_attempts
; /* TCP client connection attempts */
998 u_int32_t connection_accepts
; /* TCP server connection accepts */
999 u_int32_t ecn_client_enabled
; /* Global setting for ECN client side */
1000 u_int32_t ecn_server_enabled
; /* Global setting for ECN server side */
1001 u_int32_t ecn_client_setup
; /* Attempts to setup TCP client connection with ECN */
1002 u_int32_t ecn_server_setup
; /* Attempts to setup TCP server connection with ECN */
1003 u_int32_t ecn_client_success
; /* Number of successful negotiations of ECN for a client connection */
1004 u_int32_t ecn_server_success
; /* Number of successful negotiations of ECN for a server connection */
1005 u_int32_t ecn_not_supported
; /* Number of falbacks to Non-ECN, no support from peer */
1006 u_int32_t ecn_lost_syn
; /* Number of SYNs lost with ECN bits */
1007 u_int32_t ecn_lost_synack
; /* Number of SYN-ACKs lost with ECN bits */
1008 u_int32_t ecn_recv_ce
; /* Number of CEs received from network */
1009 u_int32_t ecn_recv_ece
; /* Number of ECEs received from receiver */
1010 u_int32_t ecn_sent_ece
; /* Number of ECEs sent in response to CE */
1011 u_int32_t ecn_conn_recv_ce
; /* Number of connections using ECN received CE at least once */
1012 u_int32_t ecn_conn_recv_ece
; /* Number of connections using ECN received ECE at least once */
1013 u_int32_t ecn_conn_plnoce
; /* Number of connections using ECN seen packet loss but never received CE */
1014 u_int32_t ecn_conn_pl_ce
; /* Number of connections using ECN seen packet loss and CE */
1015 u_int32_t ecn_conn_nopl_ce
; /* Number of connections using ECN with no packet loss but received CE */
1016 u_int32_t ecn_fallback_synloss
; /* Number of times we did fall back due to SYN-Loss */
1017 u_int32_t ecn_fallback_reorder
; /* Number of times we fallback because we detected the PAWS-issue */
1018 u_int32_t ecn_fallback_ce
; /* Number of times we fallback because we received too many CEs */
1019 u_int32_t tfo_syn_data_rcv
; /* Number of SYN+data received with valid cookie */
1020 u_int32_t tfo_cookie_req_rcv
;/* Number of TFO cookie-requests received */
1021 u_int32_t tfo_cookie_sent
; /* Number of TFO-cookies offered to the client */
1022 u_int32_t tfo_cookie_invalid
;/* Number of invalid TFO-cookies received */
1023 u_int32_t tfo_cookie_req
; /* Number of SYNs with cookie request received*/
1024 u_int32_t tfo_cookie_rcv
; /* Number of SYN/ACKs with Cookie received */
1025 u_int32_t tfo_syn_data_sent
; /* Number of SYNs+data+cookie sent */
1026 u_int32_t tfo_syn_data_acked
;/* Number of times our SYN+data has been acknowledged */
1027 u_int32_t tfo_syn_loss
; /* Number of times SYN+TFO has been lost and we fallback */
1028 u_int32_t tfo_blackhole
; /* Number of times SYN+TFO has been lost and we fallback */
1029 u_int32_t tfo_cookie_wrong
; /* TFO-cookie we sent was wrong */
1030 u_int32_t tfo_no_cookie_rcv
; /* We asked for a cookie but didn't get one */
1031 u_int32_t tfo_heuristics_disable
; /* TFO got disabled due to heuristics */
1032 u_int32_t tfo_sndblackhole
; /* TFO got blackholed in the sending direction */
1033 u_int32_t mptcp_handover_attempt
; /* Total number of MPTCP-attempts using handover mode */
1034 u_int32_t mptcp_interactive_attempt
; /* Total number of MPTCP-attempts using interactive mode */
1035 u_int32_t mptcp_aggregate_attempt
; /* Total number of MPTCP-attempts using aggregate mode */
1036 u_int32_t mptcp_fp_handover_attempt
; /* Same as previous three but only for first-party apps */
1037 u_int32_t mptcp_fp_interactive_attempt
;
1038 u_int32_t mptcp_fp_aggregate_attempt
;
1039 u_int32_t mptcp_heuristic_fallback
; /* Total number of MPTCP-connections that fell back due to heuristics */
1040 u_int32_t mptcp_fp_heuristic_fallback
; /* Same as previous but for first-party apps */
1041 u_int32_t mptcp_handover_success_wifi
; /* Total number of successfull handover-mode connections that *started* on WiFi */
1042 u_int32_t mptcp_handover_success_cell
; /* Total number of successfull handover-mode connections that *started* on Cell */
1043 u_int32_t mptcp_interactive_success
; /* Total number of interactive-mode connections that negotiated MPTCP */
1044 u_int32_t mptcp_aggregate_success
; /* Same as previous but for aggregate */
1045 u_int32_t mptcp_fp_handover_success_wifi
; /* Same as previous four, but for first-party apps */
1046 u_int32_t mptcp_fp_handover_success_cell
;
1047 u_int32_t mptcp_fp_interactive_success
;
1048 u_int32_t mptcp_fp_aggregate_success
;
1049 u_int32_t mptcp_handover_cell_from_wifi
; /* Total number of connections that use cell in handover-mode (coming from WiFi) */
1050 u_int32_t mptcp_handover_wifi_from_cell
; /* Total number of connections that use WiFi in handover-mode (coming from cell) */
1051 u_int32_t mptcp_interactive_cell_from_wifi
; /* Total number of connections that use cell in interactive mode (coming from WiFi) */
1052 u_int32_t mptcp_back_to_wifi
; /* Total number of connections that succeed to move traffic away from cell (when starting on cell) */
1053 u_int64_t mptcp_handover_cell_bytes
; /* Total number of bytes sent on cell in handover-mode (on new subflows, ignoring initial one) */
1054 u_int64_t mptcp_interactive_cell_bytes
; /* Same as previous but for interactive */
1055 u_int64_t mptcp_aggregate_cell_bytes
;
1056 u_int64_t mptcp_handover_all_bytes
; /* Total number of bytes sent in handover */
1057 u_int64_t mptcp_interactive_all_bytes
;
1058 u_int64_t mptcp_aggregate_all_bytes
;
1059 u_int32_t mptcp_wifi_proxy
; /* Total number of new subflows that fell back to regular TCP on cell */
1060 u_int32_t mptcp_cell_proxy
; /* Total number of new subflows that fell back to regular TCP on WiFi */
1061 /* When adding/removing here, also adjust NSTAT_SYSINFO_TCP_STATS_COUNT */
1062 } nstat_sysinfo_tcp_stats
;
1063 #define NSTAT_SYSINFO_TCP_STATS_COUNT 70
1066 NSTAT_IFNET_ECN_PROTO_IPV4
= 1
1067 ,NSTAT_IFNET_ECN_PROTO_IPV6
1071 NSTAT_IFNET_ECN_TYPE_CELLULAR
= 1
1072 ,NSTAT_IFNET_ECN_TYPE_WIFI
1073 ,NSTAT_IFNET_ECN_TYPE_ETHERNET
1076 typedef struct nstat_sysinfo_ifnet_ecn_stats
{
1077 u_int32_t ifnet_proto
;
1078 u_int32_t ifnet_type
;
1079 struct if_tcp_ecn_stat ecn_stat
;
1080 } nstat_sysinfo_ifnet_ecn_stats
;
1082 /* Total number of Low Internet stats that will be reported */
1083 #define NSTAT_LIM_STAT_KEYVAL_COUNT 12
1084 typedef struct nstat_sysinfo_lim_stats
{
1085 u_int8_t ifnet_signature
[NSTAT_SYSINFO_KEYVAL_STRING_MAXSIZE
];
1086 u_int32_t ifnet_siglen
;
1087 u_int32_t ifnet_type
;
1088 struct if_lim_perf_stat lim_stat
;
1089 } nstat_sysinfo_lim_stats
;
1091 #define NSTAT_NET_API_STAT_KEYVAL_COUNT (NSTAT_SYSINFO_API_LAST - NSTAT_SYSINFO_API_FIRST + 1)
1092 typedef struct nstat_sysinfo_net_api_stats
{
1093 u_int32_t report_interval
;
1095 struct net_api_stats net_api_stats
;
1096 } nstat_sysinfo_net_api_stats
;
1098 typedef struct nstat_sysinfo_data
1101 uint32_t unsent_data_cnt
; /* Before sleeping */
1103 nstat_sysinfo_mbuf_stats mb_stats
;
1104 nstat_sysinfo_tcp_stats tcp_stats
;
1105 nstat_sysinfo_ifnet_ecn_stats ifnet_ecn_stats
;
1106 nstat_sysinfo_lim_stats lim_stats
;
1107 nstat_sysinfo_net_api_stats net_api_stats
;
1109 } nstat_sysinfo_data
;
1111 #pragma mark -- Generic Network Statistics Provider --
1113 typedef void * nstat_provider_cookie_t
;
1115 #pragma mark -- Route Statistics Gathering Functions --
1120 NSTAT_TX_FLAG_RETRANSMIT
= 1
1125 NSTAT_RX_FLAG_DUPLICATE
= 1,
1126 NSTAT_RX_FLAG_OUT_OF_ORDER
= 2
1129 // indicates whether or not collection of statistics is enabled
1130 extern int nstat_collect
;
1132 void nstat_init(void);
1134 // Route collection routines
1135 void nstat_route_connect_attempt(struct rtentry
*rte
);
1136 void nstat_route_connect_success(struct rtentry
*rte
);
1137 void nstat_route_tx(struct rtentry
*rte
, u_int32_t packets
, u_int32_t bytes
, u_int32_t flags
);
1138 void nstat_route_rx(struct rtentry
*rte
, u_int32_t packets
, u_int32_t bytes
, u_int32_t flags
);
1139 void nstat_route_rtt(struct rtentry
*rte
, u_int32_t rtt
, u_int32_t rtt_var
);
1140 void nstat_route_update(struct rtentry
*rte
, uint32_t connect_attempts
, uint32_t connect_successes
,
1141 uint32_t rx_packets
, uint32_t rx_bytes
, uint32_t rx_duplicatebytes
, uint32_t rx_outoforderbytes
,
1142 uint32_t tx_packets
, uint32_t tx_bytes
, uint32_t tx_retransmit
,
1143 uint32_t rtt
, uint32_t rtt_var
);
1144 struct nstat_counts
* nstat_route_attach(struct rtentry
*rte
);
1145 void nstat_route_detach(struct rtentry
*rte
);
1149 void nstat_tcp_new_pcb(struct inpcb
*inp
);
1150 void nstat_udp_new_pcb(struct inpcb
*inp
);
1151 void nstat_route_new_entry(struct rtentry
*rt
);
1152 void nstat_pcb_detach(struct inpcb
*inp
);
1153 void nstat_pcb_cache(struct inpcb
*inp
);
1154 void nstat_pcb_invalidate_cache(struct inpcb
*inp
);
1157 void nstat_ifnet_threshold_reached(unsigned int ifindex
);
1159 void nstat_sysinfo_send_data(struct nstat_sysinfo_data
*);
1162 // Utilities for userland stats reporting
1163 u_int16_t
nstat_ifnet_to_flags(struct ifnet
*ifp
);
1165 // locked_add_64 uses atomic operations on 32bit so the 64bit
1166 // value can be properly read. The values are only ever incremented
1167 // while under the socket lock, so on 64bit we don't actually need
1168 // atomic operations to increment.
1169 #if defined(__LP64__)
1170 #define locked_add_64(__addr, __count) do { \
1171 *(__addr) += (__count); \
1174 #define locked_add_64(__addr, __count) do { \
1175 atomic_add_64((__addr), (__count)); \
1179 #endif /* XNU_KERNEL_PRIVATE */
1181 #endif /* __NTSTAT_H__ */