]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/ntstat.h
1d479d3ab6d8bd5279b634a7a45676e81d253a0a
[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 };
177
178 #pragma mark -- Network Statistics Providers --
179
180
181 // Interface properties
182
183 #define NSTAT_IFNET_IS_UNKNOWN_TYPE 0x01
184 #define NSTAT_IFNET_IS_LOOPBACK 0x02
185 #define NSTAT_IFNET_IS_CELLULAR 0x04
186 #define NSTAT_IFNET_IS_WIFI 0x08
187 #define NSTAT_IFNET_IS_WIRED 0x10
188 #define NSTAT_IFNET_IS_AWDL 0x20
189 #define NSTAT_IFNET_IS_EXPENSIVE 0x40
190 #define NSTAT_IFNET_IS_VPN 0x80
191
192
193 enum
194 {
195 NSTAT_PROVIDER_NONE = 0
196 ,NSTAT_PROVIDER_ROUTE = 1
197 ,NSTAT_PROVIDER_TCP = 2
198 ,NSTAT_PROVIDER_UDP = 3
199 ,NSTAT_PROVIDER_IFNET = 4
200 ,NSTAT_PROVIDER_SYSINFO = 5
201 };
202 #define NSTAT_PROVIDER_LAST NSTAT_PROVIDER_SYSINFO
203 #define NSTAT_PROVIDER_COUNT (NSTAT_PROVIDER_LAST+1)
204
205 typedef struct nstat_route_add_param
206 {
207 union
208 {
209 struct sockaddr_in v4;
210 struct sockaddr_in6 v6;
211 } dst;
212 union
213 {
214 struct sockaddr_in v4;
215 struct sockaddr_in6 v6;
216 } mask;
217 u_int32_t ifindex;
218 } nstat_route_add_param;
219
220 typedef struct nstat_tcp_add_param
221 {
222 union
223 {
224 struct sockaddr_in v4;
225 struct sockaddr_in6 v6;
226 } local;
227 union
228 {
229 struct sockaddr_in v4;
230 struct sockaddr_in6 v6;
231 } remote;
232 } nstat_tcp_add_param;
233
234 typedef struct nstat_tcp_descriptor
235 {
236 union
237 {
238 struct sockaddr_in v4;
239 struct sockaddr_in6 v6;
240 } local;
241
242 union
243 {
244 struct sockaddr_in v4;
245 struct sockaddr_in6 v6;
246 } remote;
247
248 u_int32_t ifindex;
249
250 u_int32_t state;
251
252 u_int32_t sndbufsize;
253 u_int32_t sndbufused;
254 u_int32_t rcvbufsize;
255 u_int32_t rcvbufused;
256 u_int32_t txunacked;
257 u_int32_t txwindow;
258 u_int32_t txcwindow;
259 u_int32_t traffic_class;
260 u_int32_t traffic_mgt_flags;
261 char cc_algo[16];
262
263 u_int64_t upid;
264 u_int32_t pid;
265 char pname[64];
266 u_int64_t eupid;
267 u_int32_t epid;
268
269 uint8_t uuid[16];
270 uint8_t euuid[16];
271 uint8_t vuuid[16];
272 struct tcp_conn_status connstatus;
273 uint16_t ifnet_properties __attribute__((aligned(4)));
274 } nstat_tcp_descriptor;
275
276 typedef struct nstat_tcp_add_param nstat_udp_add_param;
277
278 typedef struct nstat_udp_descriptor
279 {
280 union
281 {
282 struct sockaddr_in v4;
283 struct sockaddr_in6 v6;
284 } local;
285
286 union
287 {
288 struct sockaddr_in v4;
289 struct sockaddr_in6 v6;
290 } remote;
291
292 u_int32_t ifindex;
293
294 u_int32_t rcvbufsize;
295 u_int32_t rcvbufused;
296 u_int32_t traffic_class;
297
298 u_int64_t upid;
299 u_int32_t pid;
300 char pname[64];
301 u_int64_t eupid;
302 u_int32_t epid;
303
304 uint8_t uuid[16];
305 uint8_t euuid[16];
306 uint8_t vuuid[16];
307 uint16_t ifnet_properties;
308 } nstat_udp_descriptor;
309
310 typedef struct nstat_route_descriptor
311 {
312 u_int64_t id;
313 u_int64_t parent_id;
314 u_int64_t gateway_id;
315
316 union
317 {
318 struct sockaddr_in v4;
319 struct sockaddr_in6 v6;
320 struct sockaddr sa;
321 } dst;
322
323 union
324 {
325 struct sockaddr_in v4;
326 struct sockaddr_in6 v6;
327 struct sockaddr sa;
328 } mask;
329
330 union
331 {
332 struct sockaddr_in v4;
333 struct sockaddr_in6 v6;
334 struct sockaddr sa;
335 } gateway;
336
337 u_int32_t ifindex;
338 u_int32_t flags;
339
340 } nstat_route_descriptor;
341
342 typedef struct nstat_ifnet_add_param
343 {
344 u_int32_t ifindex;
345 u_int64_t threshold;
346 } nstat_ifnet_add_param;
347
348 typedef struct nstat_ifnet_desc_cellular_status
349 {
350 u_int32_t valid_bitmask; /* indicates which fields are valid */
351 #define NSTAT_IFNET_DESC_CELL_LINK_QUALITY_METRIC_VALID 0x1
352 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
353 #define NSTAT_IFNET_DESC_CELL_UL_MAX_BANDWIDTH_VALID 0x4
354 #define NSTAT_IFNET_DESC_CELL_UL_MIN_LATENCY_VALID 0x8
355 #define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
356 #define NSTAT_IFNET_DESC_CELL_UL_MAX_LATENCY_VALID 0x20
357 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_VALID 0x40
358 #define NSTAT_IFNET_DESC_CELL_UL_BYTES_LOST_VALID 0x80
359 #define NSTAT_IFNET_DESC_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
360 #define NSTAT_IFNET_DESC_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
361 #define NSTAT_IFNET_DESC_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
362 #define NSTAT_IFNET_DESC_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
363 #define NSTAT_IFNET_DESC_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
364 #define NSTAT_IFNET_DESC_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
365 #define NSTAT_IFNET_DESC_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
366 u_int32_t link_quality_metric;
367 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on
368 current activity (bps) */
369 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth
370 (bps) */
371 u_int32_t ul_min_latency; /* min expected uplink latency for first hop
372 (ms) */
373 u_int32_t ul_effective_latency; /* current expected uplink latency for
374 first hop (ms) */
375 u_int32_t ul_max_latency; /* max expected uplink latency first hop
376 (ms) */
377 u_int32_t ul_retxt_level; /* Retransmission metric */
378 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_NONE 1
379 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_LOW 2
380 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_MEDIUM 3
381 #define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_HIGH 4
382
383 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10
384 format */
385 u_int32_t ul_min_queue_size; /* minimum bytes in queue */
386 u_int32_t ul_avg_queue_size; /* average bytes in queue */
387 u_int32_t ul_max_queue_size; /* maximum bytes in queue */
388 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based
389 on current activity (bps) */
390 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth
391 (bps) */
392 u_int32_t config_inactivity_time; /* ms */
393 u_int32_t config_backoff_time; /* new connections backoff time in ms */
394 } nstat_ifnet_desc_cellular_status;
395
396 typedef struct nstat_ifnet_desc_wifi_status {
397 u_int32_t valid_bitmask;
398 #define NSTAT_IFNET_DESC_WIFI_LINK_QUALITY_METRIC_VALID 0x1
399 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
400 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
401 #define NSTAT_IFNET_DESC_WIFI_UL_MIN_LATENCY_VALID 0x8
402 #define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
403 #define NSTAT_IFNET_DESC_WIFI_UL_MAX_LATENCY_VALID 0x20
404 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_VALID 0x40
405 #define NSTAT_IFNET_DESC_WIFI_UL_ERROR_RATE_VALID 0x80
406 #define NSTAT_IFNET_DESC_WIFI_UL_BYTES_LOST_VALID 0x100
407 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
408 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
409 #define NSTAT_IFNET_DESC_WIFI_DL_MIN_LATENCY_VALID 0x800
410 #define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
411 #define NSTAT_IFNET_DESC_WIFI_DL_MAX_LATENCY_VALID 0x2000
412 #define NSTAT_IFNET_DESC_WIFI_DL_ERROR_RATE_VALID 0x4000
413 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_VALID 0x8000
414 #define NSTAT_IFNET_DESC_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
415 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
416 #define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
417 u_int32_t link_quality_metric; /* link quality metric */
418 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on
419 current activity (bps) */
420 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth
421 (bps) */
422 u_int32_t ul_min_latency; /* min expected uplink latency for first hop
423 (ms) */
424 u_int32_t ul_effective_latency; /* current expected uplink latency for
425 first hop (ms) */
426 u_int32_t ul_max_latency; /* max expected uplink latency for first hop
427 (ms) */
428 u_int32_t ul_retxt_level; /* Retransmission metric */
429 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_NONE 1
430 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_LOW 2
431 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_MEDIUM 3
432 #define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_HIGH 4
433
434 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10
435 format */
436 u_int32_t ul_error_rate; /* % of bytes dropped on uplink after many
437 retransmissions in Q10 format */
438 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based
439 on current activity (bps) */
440 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth
441 (bps) */
442 /*
443 * The download latency values indicate the time AP may have to wait
444 * for the driver to receive the packet. These values give the range
445 * of expected latency mainly due to co-existence events and channel
446 * hopping where the interface becomes unavailable.
447 */
448 u_int32_t dl_min_latency; /* min expected latency for first hop in ms */
449 u_int32_t dl_effective_latency; /* current expected latency for first
450 hop in ms */
451 u_int32_t dl_max_latency; /* max expected latency for first hop in ms */
452 u_int32_t dl_error_rate; /* % of CRC or other errors in Q10 format */
453 u_int32_t config_frequency; /* 2.4 or 5 GHz */
454 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
455 #define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
456 u_int32_t config_multicast_rate; /* bps */
457 u_int32_t scan_count; /* scan count during the previous period */
458 u_int32_t scan_duration; /* scan duration in ms */
459 } nstat_ifnet_desc_wifi_status;
460
461 enum
462 {
463 NSTAT_IFNET_DESC_LINK_STATUS_TYPE_NONE = 0
464 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_CELLULAR = 1
465 ,NSTAT_IFNET_DESC_LINK_STATUS_TYPE_WIFI = 2
466 };
467
468 typedef struct nstat_ifnet_desc_link_status
469 {
470 u_int32_t link_status_type;
471 union {
472 nstat_ifnet_desc_cellular_status cellular;
473 nstat_ifnet_desc_wifi_status wifi;
474 } u;
475 } nstat_ifnet_desc_link_status;
476
477 #ifndef IF_DESCSIZE
478 #define IF_DESCSIZE 128
479 #endif
480 typedef struct nstat_ifnet_descriptor
481 {
482 char name[IFNAMSIZ+1];
483 u_int32_t ifindex;
484 u_int64_t threshold;
485 unsigned int type;
486 char description[IF_DESCSIZE];
487 nstat_ifnet_desc_link_status link_status;
488 } nstat_ifnet_descriptor;
489
490 typedef struct nstat_sysinfo_descriptor
491 {
492 u_int32_t flags;
493 } nstat_sysinfo_descriptor;
494
495 typedef struct nstat_sysinfo_add_param
496 {
497 /* To indicate which system level information should be collected */
498 u_int32_t flags;
499 } nstat_sysinfo_add_param;
500
501 #define NSTAT_SYSINFO_MBUF_STATS 0x0001
502 #define NSTAT_SYSINFO_TCP_STATS 0x0002
503 #define NSTAT_SYSINFO_IFNET_ECN_STATS 0x0003
504
505 #pragma mark -- Network Statistics User Client --
506
507 #define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
508
509 enum
510 {
511 // generic response messages
512 NSTAT_MSG_TYPE_SUCCESS = 0
513 ,NSTAT_MSG_TYPE_ERROR = 1
514
515 // Requests
516 ,NSTAT_MSG_TYPE_ADD_SRC = 1001
517 ,NSTAT_MSG_TYPE_ADD_ALL_SRCS = 1002
518 ,NSTAT_MSG_TYPE_REM_SRC = 1003
519 ,NSTAT_MSG_TYPE_QUERY_SRC = 1004
520 ,NSTAT_MSG_TYPE_GET_SRC_DESC = 1005
521 ,NSTAT_MSG_TYPE_SET_FILTER = 1006
522 ,NSTAT_MSG_TYPE_GET_UPDATE = 1007
523 ,NSTAT_MSG_TYPE_SUBSCRIBE_SYSINFO = 1008
524
525 // Responses/Notfications
526 ,NSTAT_MSG_TYPE_SRC_ADDED = 10001
527 ,NSTAT_MSG_TYPE_SRC_REMOVED = 10002
528 ,NSTAT_MSG_TYPE_SRC_DESC = 10003
529 ,NSTAT_MSG_TYPE_SRC_COUNTS = 10004
530 ,NSTAT_MSG_TYPE_SYSINFO_COUNTS = 10005
531 ,NSTAT_MSG_TYPE_SRC_UPDATE = 10006
532 };
533
534 enum
535 {
536 NSTAT_SRC_REF_ALL = 0xffffffff
537 ,NSTAT_SRC_REF_INVALID = 0
538 };
539
540 /* Source-level filters */
541 enum
542 {
543 NSTAT_FILTER_NOZEROBYTES = 0x00000001
544 };
545
546 /* Provider-level filters */
547 enum
548 {
549 NSTAT_FILTER_ACCEPT_UNKNOWN = 0x00000001
550 ,NSTAT_FILTER_ACCEPT_LOOPBACK = 0x00000002
551 ,NSTAT_FILTER_ACCEPT_CELLULAR = 0x00000004
552 ,NSTAT_FILTER_ACCEPT_WIFI = 0x00000008
553 ,NSTAT_FILTER_ACCEPT_WIRED = 0x00000010
554 ,NSTAT_FILTER_ACCEPT_ALL = 0x0000001F
555 ,NSTAT_FILTER_IFNET_FLAGS = 0x000000FF
556
557 ,NSTAT_FILTER_PROVIDER_NOZEROBYTES = 0x00000100
558
559 ,NSTAT_FILTER_TCP_NO_LISTENER = 0x00001000
560 ,NSTAT_FILTER_TCP_ONLY_LISTENER = 0x00002000
561 ,NSTAT_FILTER_TCP_INTERFACE_ATTACH = 0x00004000
562 ,NSTAT_FILTER_TCP_FLAGS = 0x0000F000
563
564 ,NSTAT_FILTER_UDP_INTERFACE_ATTACH = 0x00010000
565 ,NSTAT_FILTER_UDP_FLAGS = 0x000F0000
566
567 ,NSTAT_FILTER_SUPPRESS_SRC_ADDED = 0x00100000
568 ,NSTAT_FILTER_REQUIRE_SRC_ADDED = 0x00200000
569 };
570
571 enum
572 {
573 NSTAT_MSG_HDR_FLAG_SUPPORTS_AGGREGATE = 1 << 0,
574 NSTAT_MSG_HDR_FLAG_CONTINUATION = 1 << 1,
575 NSTAT_MSG_HDR_FLAG_CLOSING = 1 << 2,
576 };
577
578 typedef struct nstat_msg_hdr
579 {
580 u_int64_t context;
581 u_int32_t type;
582 u_int16_t length;
583 u_int16_t flags;
584 } nstat_msg_hdr;
585
586 typedef struct nstat_msg_error
587 {
588 nstat_msg_hdr hdr;
589 u_int32_t error; // errno error
590 } nstat_msg_error;
591
592 typedef struct nstat_msg_add_src
593 {
594 nstat_msg_hdr hdr;
595 nstat_provider_id_t provider;
596 u_int8_t param[];
597 } nstat_msg_add_src_req;
598
599 typedef struct nstat_msg_add_all_srcs
600 {
601 nstat_msg_hdr hdr;
602 nstat_provider_id_t provider;
603 u_int64_t filter;
604 } nstat_msg_add_all_srcs;
605
606 typedef struct nstat_msg_src_added
607 {
608 nstat_msg_hdr hdr;
609 nstat_provider_id_t provider;
610 nstat_src_ref_t srcref;
611 } nstat_msg_src_added;
612
613 typedef struct nstat_msg_rem_src
614 {
615 nstat_msg_hdr hdr;
616 nstat_src_ref_t srcref;
617 } nstat_msg_rem_src_req;
618
619 typedef struct nstat_msg_get_src_description
620 {
621 nstat_msg_hdr hdr;
622 nstat_src_ref_t srcref;
623 } nstat_msg_get_src_description;
624
625 typedef struct nstat_msg_set_filter
626 {
627 nstat_msg_hdr hdr;
628 nstat_src_ref_t srcref;
629 u_int32_t filter;
630 } nstat_msg_set_filter;
631
632 typedef struct nstat_msg_src_description
633 {
634 nstat_msg_hdr hdr;
635 nstat_src_ref_t srcref;
636 nstat_provider_id_t provider;
637 u_int8_t data[];
638 } nstat_msg_src_description;
639
640 typedef struct nstat_msg_query_src
641 {
642 nstat_msg_hdr hdr;
643 nstat_src_ref_t srcref;
644 } nstat_msg_query_src_req;
645
646 typedef struct nstat_msg_src_counts
647 {
648 nstat_msg_hdr hdr;
649 nstat_src_ref_t srcref;
650 nstat_counts counts;
651 } nstat_msg_src_counts;
652
653 typedef struct nstat_msg_src_update
654 {
655 nstat_msg_hdr hdr;
656 nstat_src_ref_t srcref;
657 nstat_counts counts;
658 nstat_provider_id_t provider;
659 u_int8_t data[];
660 } nstat_msg_src_update;
661
662 typedef struct nstat_msg_src_removed
663 {
664 nstat_msg_hdr hdr;
665 nstat_src_ref_t srcref;
666 } nstat_msg_src_removed;
667
668 typedef struct nstat_msg_sysinfo_counts
669 {
670 nstat_msg_hdr hdr;
671 nstat_src_ref_t srcref;
672 nstat_sysinfo_counts counts;
673 } __attribute__((packed)) nstat_msg_sysinfo_counts;
674
675 #pragma pack(pop)
676
677 #pragma mark -- Statitiscs about Network Statistics --
678
679 struct nstat_stats {
680 u_int32_t nstat_successmsgfailures;
681 u_int32_t nstat_sendcountfailures;
682 u_int32_t nstat_sysinfofailures;
683 u_int32_t nstat_srcupatefailures;
684 u_int32_t nstat_descriptionfailures;
685 u_int32_t nstat_msgremovedfailures;
686 u_int32_t nstat_srcaddedfailures;
687 u_int32_t nstat_msgerrorfailures;
688 u_int32_t nstat_copy_descriptor_failures;
689 u_int32_t nstat_provider_counts_failures;
690 u_int32_t nstat_control_send_description_failures;
691 u_int32_t nstat_control_send_goodbye_failures;
692 u_int32_t nstat_flush_accumulated_msgs_failures;
693 u_int32_t nstat_accumulate_msg_failures;
694 u_int32_t nstat_control_cleanup_source_failures;
695 u_int32_t nstat_handle_msg_failures;
696 };
697
698 #endif /* PRIVATE */
699
700 #ifdef XNU_KERNEL_PRIVATE
701 #include <sys/mcache.h>
702
703 #pragma mark -- System Information Internal Support --
704
705 typedef struct nstat_sysinfo_mbuf_stats
706 {
707 u_int32_t total_256b; /* Peak usage, 256B pool */
708 u_int32_t total_2kb; /* Peak usage, 2KB pool */
709 u_int32_t total_4kb; /* Peak usage, 4KB pool */
710 u_int32_t total_16kb; /* Peak usage, 16KB pool */
711 u_int32_t sbmb_total; /* Total mbufs in sock buffer pool */
712 u_int32_t sb_atmbuflimit; /* Memory limit reached for socket buffer autoscaling */
713 u_int32_t draincnt; /* Number of times mbuf pool has been drained under memory pressure */
714 u_int32_t memreleased; /* Memory (bytes) released from mbuf pool to VM */
715 } nstat_sysinfo_mbuf_stats;
716
717 typedef struct nstat_sysinfo_tcp_stats
718 {
719 u_int32_t ipv4_avgrtt; /* Average RTT for IPv4 */
720 u_int32_t ipv6_avgrtt; /* Average RTT for IPv6 */
721 u_int32_t send_plr; /* Average uplink packet loss rate */
722 u_int32_t recv_plr; /* Average downlink packet loss rate */
723 u_int32_t send_tlrto_rate; /* Average rxt timeout after tail loss */
724 u_int32_t send_reorder_rate; /* Average packet reordering rate */
725 u_int32_t connection_attempts; /* TCP client connection attempts */
726 u_int32_t connection_accepts; /* TCP server connection accepts */
727 u_int32_t ecn_client_enabled; /* Global setting for ECN client side */
728 u_int32_t ecn_server_enabled; /* Global setting for ECN server side */
729 u_int32_t ecn_client_setup; /* Attempts to setup TCP client connection with ECN */
730 u_int32_t ecn_server_setup; /* Attempts to setup TCP server connection with ECN */
731 u_int32_t ecn_client_success; /* Number of successful negotiations of ECN for a client connection */
732 u_int32_t ecn_server_success; /* Number of successful negotiations of ECN for a server connection */
733 u_int32_t ecn_not_supported; /* Number of falbacks to Non-ECN, no support from peer */
734 u_int32_t ecn_lost_syn; /* Number of SYNs lost with ECN bits */
735 u_int32_t ecn_lost_synack; /* Number of SYN-ACKs lost with ECN bits */
736 u_int32_t ecn_recv_ce; /* Number of CEs received from network */
737 u_int32_t ecn_recv_ece; /* Number of ECEs received from receiver */
738 u_int32_t ecn_sent_ece; /* Number of ECEs sent in response to CE */
739 u_int32_t ecn_conn_recv_ce; /* Number of connections using ECN received CE at least once */
740 u_int32_t ecn_conn_recv_ece; /* Number of connections using ECN received ECE at least once */
741 u_int32_t ecn_conn_plnoce; /* Number of connections using ECN seen packet loss but never received CE */
742 u_int32_t ecn_conn_pl_ce; /* Number of connections using ECN seen packet loss and CE */
743 u_int32_t ecn_conn_nopl_ce; /* Number of connections using ECN with no packet loss but received CE */
744 u_int32_t ecn_fallback_synloss; /* Number of times we did fall back due to SYN-Loss */
745 u_int32_t ecn_fallback_reorder; /* Number of times we fallback because we detected the PAWS-issue */
746 u_int32_t ecn_fallback_ce; /* Number of times we fallback because we received too many CEs */
747 u_int32_t tfo_syn_data_rcv; /* Number of SYN+data received with valid cookie */
748 u_int32_t tfo_cookie_req_rcv;/* Number of TFO cookie-requests received */
749 u_int32_t tfo_cookie_sent; /* Number of TFO-cookies offered to the client */
750 u_int32_t tfo_cookie_invalid;/* Number of invalid TFO-cookies received */
751 u_int32_t tfo_cookie_req; /* Number of SYNs with cookie request received*/
752 u_int32_t tfo_cookie_rcv; /* Number of SYN/ACKs with Cookie received */
753 u_int32_t tfo_syn_data_sent; /* Number of SYNs+data+cookie sent */
754 u_int32_t tfo_syn_data_acked;/* Number of times our SYN+data has been acknowledged */
755 u_int32_t tfo_syn_loss; /* Number of times SYN+TFO has been lost and we fallback */
756 u_int32_t tfo_blackhole; /* Number of times SYN+TFO has been lost and we fallback */
757 } nstat_sysinfo_tcp_stats;
758
759 enum {
760 NSTAT_IFNET_ECN_PROTO_IPV4 = 1
761 ,NSTAT_IFNET_ECN_PROTO_IPV6
762 };
763
764 enum {
765 NSTAT_IFNET_ECN_TYPE_CELLULAR = 1
766 ,NSTAT_IFNET_ECN_TYPE_WIFI
767 ,NSTAT_IFNET_ECN_TYPE_ETHERNET
768 };
769
770 typedef struct nstat_sysinfo_ifnet_ecn_stats {
771 u_int32_t ifnet_proto;
772 u_int32_t ifnet_type;
773 struct if_tcp_ecn_stat ecn_stat;
774 } nstat_sysinfo_ifnet_ecn_stats;
775
776 typedef struct nstat_sysinfo_data
777 {
778 u_int32_t flags;
779 union {
780 nstat_sysinfo_mbuf_stats mb_stats;
781 nstat_sysinfo_tcp_stats tcp_stats;
782 nstat_sysinfo_ifnet_ecn_stats ifnet_ecn_stats;
783 } u;
784 } nstat_sysinfo_data;
785
786 #pragma mark -- Generic Network Statistics Provider --
787
788 typedef void * nstat_provider_cookie_t;
789
790 #pragma mark -- Route Statistics Gathering Functions --
791 struct rtentry;
792
793 enum
794 {
795 NSTAT_TX_FLAG_RETRANSMIT = 1
796 };
797
798 enum
799 {
800 NSTAT_RX_FLAG_DUPLICATE = 1,
801 NSTAT_RX_FLAG_OUT_OF_ORDER = 2
802 };
803
804 // indicates whether or not collection of statistics is enabled
805 extern int nstat_collect;
806
807 void nstat_init(void);
808
809 // Route collection routines
810 void nstat_route_connect_attempt(struct rtentry *rte);
811 void nstat_route_connect_success(struct rtentry *rte);
812 void nstat_route_tx(struct rtentry *rte, u_int32_t packets, u_int32_t bytes, u_int32_t flags);
813 void nstat_route_rx(struct rtentry *rte, u_int32_t packets, u_int32_t bytes, u_int32_t flags);
814 void nstat_route_rtt(struct rtentry *rte, u_int32_t rtt, u_int32_t rtt_var);
815 void nstat_route_detach(struct rtentry *rte);
816
817 // watcher support
818 struct inpcb;
819 void nstat_tcp_new_pcb(struct inpcb *inp);
820 void nstat_udp_new_pcb(struct inpcb *inp);
821 void nstat_route_new_entry(struct rtentry *rt);
822 void nstat_pcb_detach(struct inpcb *inp);
823 void nstat_pcb_cache(struct inpcb *inp);
824 void nstat_pcb_invalidate_cache(struct inpcb *inp);
825
826
827 void nstat_ifnet_threshold_reached(unsigned int ifindex);
828
829 void nstat_sysinfo_send_data(struct nstat_sysinfo_data *);
830
831 // locked_add_64 uses atomic operations on 32bit so the 64bit
832 // value can be properly read. The values are only ever incremented
833 // while under the socket lock, so on 64bit we don't actually need
834 // atomic operations to increment.
835 #if defined(__LP64__)
836 #define locked_add_64(__addr, __count) do { \
837 *(__addr) += (__count); \
838 } while (0)
839 #else
840 #define locked_add_64(__addr, __count) do { \
841 atomic_add_64((__addr), (__count)); \
842 } while (0)
843 #endif
844
845 #endif /* XNU_KERNEL_PRIVATE */
846
847 #endif /* __NTSTAT_H__ */