]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/ntstat.h
xnu-3248.40.184.tar.gz
[apple/xnu.git] / bsd / net / ntstat.h
1 /*
2 * Copyright (c) 2010-2015 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 <netinet/tcp.h>
34
35 #ifdef PRIVATE
36 #pragma pack(push, 4)
37 #pragma mark -- Common Data Structures --
38
39 #define __NSTAT_REVISION__ 7
40
41 typedef u_int32_t nstat_provider_id_t;
42 typedef u_int32_t nstat_src_ref_t;
43
44 typedef struct nstat_counts
45 {
46 /* Counters */
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)));
51
52 u_int32_t nstat_rxduplicatebytes;
53 u_int32_t nstat_rxoutoforderbytes;
54 u_int32_t nstat_txretransmit;
55
56 u_int32_t nstat_connectattempts;
57 u_int32_t nstat_connectsuccesses;
58
59 u_int32_t nstat_min_rtt;
60 u_int32_t nstat_avg_rtt;
61 u_int32_t nstat_var_rtt;
62
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)));
69 } nstat_counts;
70
71 typedef struct nstat_sysinfo_keyval
72 {
73 u_int32_t nstat_sysinfo_key;
74 u_int32_t nstat_sysinfo_flags;
75 union {
76 int64_t nstat_sysinfo_scalar;
77 double nstat_sysinfo_distribution;
78 } u;
79 } __attribute__((packed)) nstat_sysinfo_keyval;
80
81 #define NSTAT_SYSINFO_FLAG_SCALAR 0x0001
82 #define NSTAT_SYSINFO_FLAG_DISTRIBUTION 0x0002
83
84 #define NSTAT_MAX_MSG_SIZE 4096
85
86 typedef struct nstat_sysinfo_counts
87 {
88 /* Counters */
89 u_int32_t nstat_sysinfo_len;
90 u_int32_t pad;
91 u_int8_t nstat_sysinfo_keyvals[];
92 } __attribute__((packed)) nstat_sysinfo_counts;
93
94 enum
95 {
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
189 };
190
191 #pragma mark -- Network Statistics Providers --
192
193
194 // Interface properties
195
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
205
206
207 enum
208 {
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
215 };
216 #define NSTAT_PROVIDER_LAST NSTAT_PROVIDER_SYSINFO
217 #define NSTAT_PROVIDER_COUNT (NSTAT_PROVIDER_LAST+1)
218
219 typedef struct nstat_route_add_param
220 {
221 union
222 {
223 struct sockaddr_in v4;
224 struct sockaddr_in6 v6;
225 } dst;
226 union
227 {
228 struct sockaddr_in v4;
229 struct sockaddr_in6 v6;
230 } mask;
231 u_int32_t ifindex;
232 } nstat_route_add_param;
233
234 typedef struct nstat_tcp_add_param
235 {
236 union
237 {
238 struct sockaddr_in v4;
239 struct sockaddr_in6 v6;
240 } local;
241 union
242 {
243 struct sockaddr_in v4;
244 struct sockaddr_in6 v6;
245 } remote;
246 } nstat_tcp_add_param;
247
248 typedef struct nstat_tcp_descriptor
249 {
250 union
251 {
252 struct sockaddr_in v4;
253 struct sockaddr_in6 v6;
254 } local;
255
256 union
257 {
258 struct sockaddr_in v4;
259 struct sockaddr_in6 v6;
260 } remote;
261
262 u_int32_t ifindex;
263
264 u_int32_t state;
265
266 u_int32_t sndbufsize;
267 u_int32_t sndbufused;
268 u_int32_t rcvbufsize;
269 u_int32_t rcvbufused;
270 u_int32_t txunacked;
271 u_int32_t txwindow;
272 u_int32_t txcwindow;
273 u_int32_t traffic_class;
274 u_int32_t traffic_mgt_flags;
275 char cc_algo[16];
276
277 u_int64_t upid;
278 u_int32_t pid;
279 char pname[64];
280 u_int64_t eupid;
281 u_int32_t epid;
282
283 uint8_t uuid[16];
284 uint8_t euuid[16];
285 uint8_t vuuid[16];
286 struct tcp_conn_status connstatus;
287 uint16_t ifnet_properties __attribute__((aligned(4)));
288 } nstat_tcp_descriptor;
289
290 typedef struct nstat_tcp_add_param nstat_udp_add_param;
291
292 typedef struct nstat_udp_descriptor
293 {
294 union
295 {
296 struct sockaddr_in v4;
297 struct sockaddr_in6 v6;
298 } local;
299
300 union
301 {
302 struct sockaddr_in v4;
303 struct sockaddr_in6 v6;
304 } remote;
305
306 u_int32_t ifindex;
307
308 u_int32_t rcvbufsize;
309 u_int32_t rcvbufused;
310 u_int32_t traffic_class;
311
312 u_int64_t upid;
313 u_int32_t pid;
314 char pname[64];
315 u_int64_t eupid;
316 u_int32_t epid;
317
318 uint8_t uuid[16];
319 uint8_t euuid[16];
320 uint8_t vuuid[16];
321 uint16_t ifnet_properties;
322 } nstat_udp_descriptor;
323
324 typedef struct nstat_route_descriptor
325 {
326 u_int64_t id;
327 u_int64_t parent_id;
328 u_int64_t gateway_id;
329
330 union
331 {
332 struct sockaddr_in v4;
333 struct sockaddr_in6 v6;
334 struct sockaddr sa;
335 } dst;
336
337 union
338 {
339 struct sockaddr_in v4;
340 struct sockaddr_in6 v6;
341 struct sockaddr sa;
342 } mask;
343
344 union
345 {
346 struct sockaddr_in v4;
347 struct sockaddr_in6 v6;
348 struct sockaddr sa;
349 } gateway;
350
351 u_int32_t ifindex;
352 u_int32_t flags;
353
354 } nstat_route_descriptor;
355
356 typedef struct nstat_ifnet_add_param
357 {
358 u_int32_t ifindex;
359 u_int64_t threshold;
360 } nstat_ifnet_add_param;
361
362 typedef struct nstat_ifnet_desc_cellular_status
363 {
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
384 (bps) */
385 u_int32_t ul_min_latency; /* min expected uplink latency for first hop
386 (ms) */
387 u_int32_t ul_effective_latency; /* current expected uplink latency for
388 first hop (ms) */
389 u_int32_t ul_max_latency; /* max expected uplink latency first hop
390 (ms) */
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
396
397 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10
398 format */
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
405 (bps) */
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;
409
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
435 (bps) */
436 u_int32_t ul_min_latency; /* min expected uplink latency for first hop
437 (ms) */
438 u_int32_t ul_effective_latency; /* current expected uplink latency for
439 first hop (ms) */
440 u_int32_t ul_max_latency; /* max expected uplink latency for first hop
441 (ms) */
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
447
448 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10
449 format */
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
455 (bps) */
456 /*
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.
461 */
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
464 hop in ms */
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;
474
475 enum
476 {
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
480 };
481
482 typedef struct nstat_ifnet_desc_link_status
483 {
484 u_int32_t link_status_type;
485 union {
486 nstat_ifnet_desc_cellular_status cellular;
487 nstat_ifnet_desc_wifi_status wifi;
488 } u;
489 } nstat_ifnet_desc_link_status;
490
491 #ifndef IF_DESCSIZE
492 #define IF_DESCSIZE 128
493 #endif
494 typedef struct nstat_ifnet_descriptor
495 {
496 char name[IFNAMSIZ+1];
497 u_int32_t ifindex;
498 u_int64_t threshold;
499 unsigned int type;
500 char description[IF_DESCSIZE];
501 nstat_ifnet_desc_link_status link_status;
502 } nstat_ifnet_descriptor;
503
504 typedef struct nstat_sysinfo_descriptor
505 {
506 u_int32_t flags;
507 } nstat_sysinfo_descriptor;
508
509 typedef struct nstat_sysinfo_add_param
510 {
511 /* To indicate which system level information should be collected */
512 u_int32_t flags;
513 } nstat_sysinfo_add_param;
514
515 #define NSTAT_SYSINFO_MBUF_STATS 0x0001
516 #define NSTAT_SYSINFO_TCP_STATS 0x0002
517 #define NSTAT_SYSINFO_IFNET_ECN_STATS 0x0003
518
519 #pragma mark -- Network Statistics User Client --
520
521 #define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
522
523 enum
524 {
525 // generic response messages
526 NSTAT_MSG_TYPE_SUCCESS = 0
527 ,NSTAT_MSG_TYPE_ERROR = 1
528
529 // Requests
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
538
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
546 };
547
548 enum
549 {
550 NSTAT_SRC_REF_ALL = 0xffffffff
551 ,NSTAT_SRC_REF_INVALID = 0
552 };
553
554 /* Source-level filters */
555 enum
556 {
557 NSTAT_FILTER_NOZEROBYTES = 0x00000001
558 };
559
560 /* Provider-level filters */
561 enum
562 {
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
570
571 ,NSTAT_FILTER_PROVIDER_NOZEROBYTES = 0x00000100
572
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
577
578 ,NSTAT_FILTER_UDP_INTERFACE_ATTACH = 0x00010000
579 ,NSTAT_FILTER_UDP_FLAGS = 0x000F0000
580
581 ,NSTAT_FILTER_SUPPRESS_SRC_ADDED = 0x00100000
582 ,NSTAT_FILTER_REQUIRE_SRC_ADDED = 0x00200000
583 };
584
585 enum
586 {
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,
590 };
591
592 typedef struct nstat_msg_hdr
593 {
594 u_int64_t context;
595 u_int32_t type;
596 u_int16_t length;
597 u_int16_t flags;
598 } nstat_msg_hdr;
599
600 typedef struct nstat_msg_error
601 {
602 nstat_msg_hdr hdr;
603 u_int32_t error; // errno error
604 } nstat_msg_error;
605
606 typedef struct nstat_msg_add_src
607 {
608 nstat_msg_hdr hdr;
609 nstat_provider_id_t provider;
610 u_int8_t param[];
611 } nstat_msg_add_src_req;
612
613 typedef struct nstat_msg_add_all_srcs
614 {
615 nstat_msg_hdr hdr;
616 nstat_provider_id_t provider;
617 u_int64_t filter;
618 } nstat_msg_add_all_srcs;
619
620 typedef struct nstat_msg_src_added
621 {
622 nstat_msg_hdr hdr;
623 nstat_provider_id_t provider;
624 nstat_src_ref_t srcref;
625 } nstat_msg_src_added;
626
627 typedef struct nstat_msg_rem_src
628 {
629 nstat_msg_hdr hdr;
630 nstat_src_ref_t srcref;
631 } nstat_msg_rem_src_req;
632
633 typedef struct nstat_msg_get_src_description
634 {
635 nstat_msg_hdr hdr;
636 nstat_src_ref_t srcref;
637 } nstat_msg_get_src_description;
638
639 typedef struct nstat_msg_set_filter
640 {
641 nstat_msg_hdr hdr;
642 nstat_src_ref_t srcref;
643 u_int32_t filter;
644 } nstat_msg_set_filter;
645
646 typedef struct nstat_msg_src_description
647 {
648 nstat_msg_hdr hdr;
649 nstat_src_ref_t srcref;
650 nstat_provider_id_t provider;
651 u_int8_t data[];
652 } nstat_msg_src_description;
653
654 typedef struct nstat_msg_query_src
655 {
656 nstat_msg_hdr hdr;
657 nstat_src_ref_t srcref;
658 } nstat_msg_query_src_req;
659
660 typedef struct nstat_msg_src_counts
661 {
662 nstat_msg_hdr hdr;
663 nstat_src_ref_t srcref;
664 nstat_counts counts;
665 } nstat_msg_src_counts;
666
667 typedef struct nstat_msg_src_update
668 {
669 nstat_msg_hdr hdr;
670 nstat_src_ref_t srcref;
671 nstat_counts counts;
672 nstat_provider_id_t provider;
673 u_int8_t data[];
674 } nstat_msg_src_update;
675
676 typedef struct nstat_msg_src_removed
677 {
678 nstat_msg_hdr hdr;
679 nstat_src_ref_t srcref;
680 } nstat_msg_src_removed;
681
682 typedef struct nstat_msg_sysinfo_counts
683 {
684 nstat_msg_hdr hdr;
685 nstat_src_ref_t srcref;
686 nstat_sysinfo_counts counts;
687 } __attribute__((packed)) nstat_msg_sysinfo_counts;
688
689 #pragma pack(pop)
690
691 #pragma mark -- Statitiscs about Network Statistics --
692
693 struct nstat_stats {
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;
710 };
711
712 #endif /* PRIVATE */
713
714 #ifdef XNU_KERNEL_PRIVATE
715 #include <sys/mcache.h>
716
717 #pragma mark -- System Information Internal Support --
718
719 typedef struct nstat_sysinfo_mbuf_stats
720 {
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;
730
731 typedef struct nstat_sysinfo_tcp_stats
732 {
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;
772
773 enum {
774 NSTAT_IFNET_ECN_PROTO_IPV4 = 1
775 ,NSTAT_IFNET_ECN_PROTO_IPV6
776 };
777
778 enum {
779 NSTAT_IFNET_ECN_TYPE_CELLULAR = 1
780 ,NSTAT_IFNET_ECN_TYPE_WIFI
781 ,NSTAT_IFNET_ECN_TYPE_ETHERNET
782 };
783
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;
789
790 typedef struct nstat_sysinfo_data
791 {
792 u_int32_t flags;
793 union {
794 nstat_sysinfo_mbuf_stats mb_stats;
795 nstat_sysinfo_tcp_stats tcp_stats;
796 nstat_sysinfo_ifnet_ecn_stats ifnet_ecn_stats;
797 } u;
798 } nstat_sysinfo_data;
799
800 #pragma mark -- Generic Network Statistics Provider --
801
802 typedef void * nstat_provider_cookie_t;
803
804 #pragma mark -- Route Statistics Gathering Functions --
805 struct rtentry;
806
807 enum
808 {
809 NSTAT_TX_FLAG_RETRANSMIT = 1
810 };
811
812 enum
813 {
814 NSTAT_RX_FLAG_DUPLICATE = 1,
815 NSTAT_RX_FLAG_OUT_OF_ORDER = 2
816 };
817
818 // indicates whether or not collection of statistics is enabled
819 extern int nstat_collect;
820
821 void nstat_init(void);
822
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);
830
831 // watcher support
832 struct inpcb;
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);
839
840
841 void nstat_ifnet_threshold_reached(unsigned int ifindex);
842
843 void nstat_sysinfo_send_data(struct nstat_sysinfo_data *);
844
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); \
852 } while (0)
853 #else
854 #define locked_add_64(__addr, __count) do { \
855 atomic_add_64((__addr), (__count)); \
856 } while (0)
857 #endif
858
859 #endif /* XNU_KERNEL_PRIVATE */
860
861 #endif /* __NTSTAT_H__ */