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