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