]> git.saurik.com Git - apple/xnu.git/blame - bsd/net/ntstat.h
xnu-6153.61.1.tar.gz
[apple/xnu.git] / bsd / net / ntstat.h
CommitLineData
6d2010ae 1/*
5ba3f43e 2 * Copyright (c) 2010-2017 Apple Inc. All rights reserved.
6d2010ae
A
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
39037602 5 *
6d2010ae
A
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.
39037602 14 *
6d2010ae
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
39037602 17 *
6d2010ae
A
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.
39037602 25 *
6d2010ae
A
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28#ifndef __NTSTAT_H__
29#define __NTSTAT_H__
30#include <netinet/in.h>
39236c6e
A
31#include <net/if.h>
32#include <net/if_var.h>
5ba3f43e
A
33#include <net/net_api_stats.h>
34#include <netinet/in_stat.h>
3e170ce0 35#include <netinet/tcp.h>
6d2010ae
A
36
37#ifdef PRIVATE
6d2010ae
A
38#pragma mark -- Common Data Structures --
39
0a7de745 40#define __NSTAT_REVISION__ 9
6d2010ae 41
0a7de745
A
42typedef u_int32_t nstat_provider_id_t;
43typedef u_int64_t nstat_src_ref_t;
44typedef u_int64_t nstat_event_flags_t;
39037602
A
45
46// The following event definitions are very provisional..
0a7de745 47enum{
cb323159
A
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
0a7de745
A
56 , NSTAT_EVENT_SRC_WILL_CHANGE_PROPERTY = 0x00000100
57 , NSTAT_EVENT_SRC_DID_CHANGE_PROPERTY = 0x00000200
cb323159
A
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) */
39037602 64};
6d2010ae 65
0a7de745 66typedef struct nstat_counts {
6d2010ae 67 /* Counters */
0a7de745
A
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;
6d2010ae
A
90} nstat_counts;
91
0a7de745
A
92#define NSTAT_SYSINFO_KEYVAL_STRING_MAXSIZE 24
93typedef struct nstat_sysinfo_keyval {
94 u_int32_t nstat_sysinfo_key;
95 u_int32_t nstat_sysinfo_flags;
fe8ab488 96 union {
0a7de745
A
97 int64_t nstat_sysinfo_scalar;
98 double nstat_sysinfo_distribution;
99 u_int8_t nstat_sysinfo_string[NSTAT_SYSINFO_KEYVAL_STRING_MAXSIZE];
fe8ab488 100 } u;
0a7de745
A
101 u_int32_t nstat_sysinfo_valsize;
102 u_int8_t reserved[4];
5ba3f43e 103} nstat_sysinfo_keyval;
fe8ab488 104
0a7de745
A
105#define NSTAT_SYSINFO_FLAG_SCALAR 0x0001
106#define NSTAT_SYSINFO_FLAG_DISTRIBUTION 0x0002
107#define NSTAT_SYSINFO_FLAG_STRING 0x0004
fe8ab488 108
0a7de745 109#define NSTAT_MAX_MSG_SIZE 4096
3e170ce0 110
0a7de745 111typedef struct nstat_sysinfo_counts {
fe8ab488 112 /* Counters */
0a7de745
A
113 u_int32_t nstat_sysinfo_len;
114 u_int32_t pad;
115 u_int8_t nstat_sysinfo_keyvals[];
5ba3f43e 116} nstat_sysinfo_counts;
fe8ab488 117
0a7de745 118enum{
cb323159 119 NSTAT_SYSINFO_KEY_MBUF_256B_TOTAL = 1
0a7de745
A
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
5ba3f43e 321
490019cf 322// NSTAT_SYSINFO_ENUM_VERSION must be updated any time a value is added
0a7de745 323#define NSTAT_SYSINFO_ENUM_VERSION 20180416
fe8ab488
A
324};
325
0a7de745
A
326#define NSTAT_SYSINFO_API_FIRST NSTAT_SYSINFO_API_IF_FLTR_ATTACH
327#define NSTAT_SYSINFO_API_LAST NSTAT_SYSINFO_API_REPORT_INTERVAL
5ba3f43e 328
6d2010ae
A
329#pragma mark -- Network Statistics Providers --
330
3e170ce0
A
331
332// Interface properties
333
cb323159
A
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
5ba3f43e 349// Temporary properties of use for bringing up userland providers
cb323159
A
350#define NSTAT_IFNET_ROUTE_VALUE_UNOBTAINABLE 0x2000
351#define NSTAT_IFNET_FLOWSWITCH_VALUE_UNOBTAINABLE 0x4000
3e170ce0
A
352
353
cb323159
A
354typedef enum {
355 NSTAT_PROVIDER_NONE = 0
356 , NSTAT_PROVIDER_ROUTE = 1
357 , NSTAT_PROVIDER_TCP_KERNEL = 2
0a7de745 358 , NSTAT_PROVIDER_TCP_USERLAND = 3
cb323159 359 , NSTAT_PROVIDER_UDP_KERNEL = 4
0a7de745 360 , NSTAT_PROVIDER_UDP_USERLAND = 5
cb323159
A
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
3e170ce0 366#define NSTAT_PROVIDER_COUNT (NSTAT_PROVIDER_LAST+1)
6d2010ae 367
0a7de745
A
368typedef struct nstat_route_add_param {
369 union{
370 struct sockaddr_in v4;
371 struct sockaddr_in6 v6;
6d2010ae 372 } dst;
0a7de745
A
373 union{
374 struct sockaddr_in v4;
375 struct sockaddr_in6 v6;
6d2010ae 376 } mask;
0a7de745 377 u_int32_t ifindex;
6d2010ae
A
378} nstat_route_add_param;
379
0a7de745
A
380typedef struct nstat_tcp_add_param {
381 union{
382 struct sockaddr_in v4;
383 struct sockaddr_in6 v6;
6d2010ae 384 } local;
0a7de745
A
385 union{
386 struct sockaddr_in v4;
387 struct sockaddr_in6 v6;
6d2010ae
A
388 } remote;
389} nstat_tcp_add_param;
390
0a7de745
A
391typedef 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))));
39037602 396
5ba3f43e 397 activity_bitmap_t activity_bitmap;
39037602 398
0a7de745
A
399 u_int32_t ifindex;
400 u_int32_t state;
401
402 u_int32_t sndbufsize;
403 u_int32_t sndbufused;
404 u_int32_t rcvbufsize;
405 u_int32_t rcvbufused;
406 u_int32_t txunacked;
407 u_int32_t txwindow;
408 u_int32_t txcwindow;
409 u_int32_t traffic_class;
410 u_int32_t traffic_mgt_flags;
411
412 u_int32_t pid;
413 u_int32_t epid;
414
415 union{
416 struct sockaddr_in v4;
417 struct sockaddr_in6 v6;
5ba3f43e
A
418 } local;
419
0a7de745
A
420 union{
421 struct sockaddr_in v4;
422 struct sockaddr_in6 v6;
5ba3f43e
A
423 } remote;
424
0a7de745
A
425 char cc_algo[16];
426 char pname[64];
5ba3f43e 427
0a7de745
A
428 uuid_t uuid;
429 uuid_t euuid;
430 uuid_t vuuid;
5ba3f43e
A
431 union {
432 struct tcp_conn_status connstatus;
433 // On armv7k, tcp_conn_status is 1 byte instead of 4
0a7de745 434 uint8_t __pad_connstatus[4];
5ba3f43e 435 };
0a7de745 436 uint16_t ifnet_properties __attribute__((aligned(4)));
5ba3f43e 437
0a7de745 438 u_int8_t reserved[6];
6d2010ae
A
439} nstat_tcp_descriptor;
440
0a7de745 441typedef struct nstat_tcp_add_param nstat_udp_add_param;
6d2010ae 442
0a7de745
A
443typedef struct nstat_udp_descriptor {
444 u_int64_t upid __attribute__((aligned(sizeof(u_int64_t))));
445 u_int64_t eupid __attribute__((aligned(sizeof(u_int64_t))));
446 u_int64_t start_timestamp __attribute__((aligned(sizeof(u_int64_t))));
447 u_int64_t timestamp __attribute__((aligned(sizeof(u_int64_t))));
5ba3f43e
A
448
449 activity_bitmap_t activity_bitmap;
450
0a7de745
A
451 union{
452 struct sockaddr_in v4;
453 struct sockaddr_in6 v6;
6d2010ae 454 } local;
39037602 455
0a7de745
A
456 union{
457 struct sockaddr_in v4;
458 struct sockaddr_in6 v6;
6d2010ae 459 } remote;
39037602 460
0a7de745 461 u_int32_t ifindex;
39037602 462
0a7de745
A
463 u_int32_t rcvbufsize;
464 u_int32_t rcvbufused;
465 u_int32_t traffic_class;
39037602 466
0a7de745
A
467 u_int32_t pid;
468 char pname[64];
469 u_int32_t epid;
39236c6e 470
0a7de745
A
471 uuid_t uuid;
472 uuid_t euuid;
473 uuid_t vuuid;
474 uint16_t ifnet_properties;
5ba3f43e 475
0a7de745 476 u_int8_t reserved[6];
6d2010ae
A
477} nstat_udp_descriptor;
478
cb323159
A
479/*
480 * XXX For now just typedef'ing TCP Nstat descriptor to nstat_quic_descriptor
481 * as for now they report very similar data.
482 * Later when we extend the QUIC descriptor we can just declare its own
483 * descriptor struct.
484 */
485typedef struct nstat_tcp_add_param nstat_quic_add_param;
486typedef struct nstat_tcp_descriptor nstat_quic_descriptor;
487
0a7de745
A
488typedef struct nstat_route_descriptor {
489 u_int64_t id __attribute__((aligned(sizeof(u_int64_t))));
490 u_int64_t parent_id __attribute__((aligned(sizeof(u_int64_t))));
491 u_int64_t gateway_id __attribute__((aligned(sizeof(u_int64_t))));
492
493 union{
494 struct sockaddr_in v4;
495 struct sockaddr_in6 v6;
496 struct sockaddr sa;
6d2010ae 497 } dst;
39037602 498
0a7de745
A
499 union{
500 struct sockaddr_in v4;
501 struct sockaddr_in6 v6;
502 struct sockaddr sa;
6d2010ae 503 } mask;
39037602 504
0a7de745
A
505 union{
506 struct sockaddr_in v4;
507 struct sockaddr_in6 v6;
508 struct sockaddr sa;
6d2010ae 509 } gateway;
39037602 510
0a7de745
A
511 u_int32_t ifindex;
512 u_int32_t flags;
39037602 513
0a7de745 514 u_int8_t reserved[4];
6d2010ae
A
515} nstat_route_descriptor;
516
0a7de745
A
517typedef struct nstat_ifnet_add_param {
518 u_int64_t threshold __attribute__((aligned(sizeof(u_int64_t))));
519 u_int32_t ifindex;
5ba3f43e 520
0a7de745 521 u_int8_t reserved[4];
39236c6e
A
522} nstat_ifnet_add_param;
523
0a7de745 524typedef struct nstat_ifnet_desc_cellular_status {
3e170ce0 525 u_int32_t valid_bitmask; /* indicates which fields are valid */
0a7de745
A
526#define NSTAT_IFNET_DESC_CELL_LINK_QUALITY_METRIC_VALID 0x1
527#define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
528#define NSTAT_IFNET_DESC_CELL_UL_MAX_BANDWIDTH_VALID 0x4
529#define NSTAT_IFNET_DESC_CELL_UL_MIN_LATENCY_VALID 0x8
530#define NSTAT_IFNET_DESC_CELL_UL_EFFECTIVE_LATENCY_VALID 0x10
531#define NSTAT_IFNET_DESC_CELL_UL_MAX_LATENCY_VALID 0x20
532#define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_VALID 0x40
533#define NSTAT_IFNET_DESC_CELL_UL_BYTES_LOST_VALID 0x80
534#define NSTAT_IFNET_DESC_CELL_UL_MIN_QUEUE_SIZE_VALID 0x100
535#define NSTAT_IFNET_DESC_CELL_UL_AVG_QUEUE_SIZE_VALID 0x200
536#define NSTAT_IFNET_DESC_CELL_UL_MAX_QUEUE_SIZE_VALID 0x400
537#define NSTAT_IFNET_DESC_CELL_DL_EFFECTIVE_BANDWIDTH_VALID 0x800
538#define NSTAT_IFNET_DESC_CELL_DL_MAX_BANDWIDTH_VALID 0x1000
539#define NSTAT_IFNET_DESC_CELL_CONFIG_INACTIVITY_TIME_VALID 0x2000
540#define NSTAT_IFNET_DESC_CELL_CONFIG_BACKOFF_TIME_VALID 0x4000
541#define NSTAT_IFNET_DESC_CELL_MSS_RECOMMENDED_VALID 0x8000
3e170ce0
A
542 u_int32_t link_quality_metric;
543 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on
0a7de745 544 * current activity (bps) */
3e170ce0 545 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth
0a7de745 546 * (bps) */
3e170ce0 547 u_int32_t ul_min_latency; /* min expected uplink latency for first hop
0a7de745 548 * (ms) */
3e170ce0 549 u_int32_t ul_effective_latency; /* current expected uplink latency for
0a7de745 550 * first hop (ms) */
3e170ce0 551 u_int32_t ul_max_latency; /* max expected uplink latency first hop
0a7de745 552 * (ms) */
3e170ce0 553 u_int32_t ul_retxt_level; /* Retransmission metric */
0a7de745
A
554#define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_NONE 1
555#define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_LOW 2
556#define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_MEDIUM 3
557#define NSTAT_IFNET_DESC_CELL_UL_RETXT_LEVEL_HIGH 4
3e170ce0
A
558
559 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10
0a7de745 560 * format */
3e170ce0
A
561 u_int32_t ul_min_queue_size; /* minimum bytes in queue */
562 u_int32_t ul_avg_queue_size; /* average bytes in queue */
563 u_int32_t ul_max_queue_size; /* maximum bytes in queue */
564 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based
0a7de745 565 * on current activity (bps) */
3e170ce0 566 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth
0a7de745 567 * (bps) */
3e170ce0
A
568 u_int32_t config_inactivity_time; /* ms */
569 u_int32_t config_backoff_time; /* new connections backoff time in ms */
0a7de745
A
570#define NSTAT_IFNET_DESC_MSS_RECOMMENDED_NONE 0x0
571#define NSTAT_IFNET_DESC_MSS_RECOMMENDED_MEDIUM 0x1
572#define NSTAT_IFNET_DESC_MSS_RECOMMENDED_LOW 0x2
39037602 573 u_int16_t mss_recommended; /* recommended MSS */
0a7de745 574 u_int8_t reserved[2];
3e170ce0
A
575} nstat_ifnet_desc_cellular_status;
576
577typedef struct nstat_ifnet_desc_wifi_status {
578 u_int32_t valid_bitmask;
0a7de745
A
579#define NSTAT_IFNET_DESC_WIFI_LINK_QUALITY_METRIC_VALID 0x1
580#define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_BANDWIDTH_VALID 0x2
581#define NSTAT_IFNET_DESC_WIFI_UL_MAX_BANDWIDTH_VALID 0x4
582#define NSTAT_IFNET_DESC_WIFI_UL_MIN_LATENCY_VALID 0x8
583#define NSTAT_IFNET_DESC_WIFI_UL_EFFECTIVE_LATENCY_VALID 0x10
584#define NSTAT_IFNET_DESC_WIFI_UL_MAX_LATENCY_VALID 0x20
585#define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_VALID 0x40
586#define NSTAT_IFNET_DESC_WIFI_UL_ERROR_RATE_VALID 0x80
587#define NSTAT_IFNET_DESC_WIFI_UL_BYTES_LOST_VALID 0x100
588#define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_BANDWIDTH_VALID 0x200
589#define NSTAT_IFNET_DESC_WIFI_DL_MAX_BANDWIDTH_VALID 0x400
590#define NSTAT_IFNET_DESC_WIFI_DL_MIN_LATENCY_VALID 0x800
591#define NSTAT_IFNET_DESC_WIFI_DL_EFFECTIVE_LATENCY_VALID 0x1000
592#define NSTAT_IFNET_DESC_WIFI_DL_MAX_LATENCY_VALID 0x2000
593#define NSTAT_IFNET_DESC_WIFI_DL_ERROR_RATE_VALID 0x4000
594#define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_VALID 0x8000
595#define NSTAT_IFNET_DESC_WIFI_CONFIG_MULTICAST_RATE_VALID 0x10000
596#define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_COUNT_VALID 0x20000
597#define NSTAT_IFNET_DESC_WIFI_CONFIG_SCAN_DURATION_VALID 0x40000
3e170ce0
A
598 u_int32_t link_quality_metric; /* link quality metric */
599 u_int32_t ul_effective_bandwidth; /* Measured uplink bandwidth based on
0a7de745 600 * current activity (bps) */
3e170ce0 601 u_int32_t ul_max_bandwidth; /* Maximum supported uplink bandwidth
0a7de745 602 * (bps) */
3e170ce0 603 u_int32_t ul_min_latency; /* min expected uplink latency for first hop
0a7de745 604 * (ms) */
3e170ce0 605 u_int32_t ul_effective_latency; /* current expected uplink latency for
0a7de745 606 * first hop (ms) */
3e170ce0 607 u_int32_t ul_max_latency; /* max expected uplink latency for first hop
0a7de745 608 * (ms) */
3e170ce0 609 u_int32_t ul_retxt_level; /* Retransmission metric */
0a7de745
A
610#define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_NONE 1
611#define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_LOW 2
612#define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_MEDIUM 3
613#define NSTAT_IFNET_DESC_WIFI_UL_RETXT_LEVEL_HIGH 4
3e170ce0
A
614
615 u_int32_t ul_bytes_lost; /* % of total bytes lost on uplink in Q10
0a7de745 616 * format */
3e170ce0 617 u_int32_t ul_error_rate; /* % of bytes dropped on uplink after many
0a7de745 618 * retransmissions in Q10 format */
3e170ce0 619 u_int32_t dl_effective_bandwidth; /* Measured downlink bandwidth based
0a7de745 620 * on current activity (bps) */
3e170ce0 621 u_int32_t dl_max_bandwidth; /* Maximum supported downlink bandwidth
0a7de745 622 * (bps) */
3e170ce0
A
623 /*
624 * The download latency values indicate the time AP may have to wait
625 * for the driver to receive the packet. These values give the range
626 * of expected latency mainly due to co-existence events and channel
627 * hopping where the interface becomes unavailable.
628 */
629 u_int32_t dl_min_latency; /* min expected latency for first hop in ms */
630 u_int32_t dl_effective_latency; /* current expected latency for first
0a7de745 631 * hop in ms */
3e170ce0
A
632 u_int32_t dl_max_latency; /* max expected latency for first hop in ms */
633 u_int32_t dl_error_rate; /* % of CRC or other errors in Q10 format */
634 u_int32_t config_frequency; /* 2.4 or 5 GHz */
0a7de745
A
635#define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_2_4_GHZ 1
636#define NSTAT_IFNET_DESC_WIFI_CONFIG_FREQUENCY_5_0_GHZ 2
3e170ce0
A
637 u_int32_t config_multicast_rate; /* bps */
638 u_int32_t scan_count; /* scan count during the previous period */
639 u_int32_t scan_duration; /* scan duration in ms */
640} nstat_ifnet_desc_wifi_status;
641
0a7de745 642enum{
3e170ce0 643 NSTAT_IFNET_DESC_LINK_STATUS_TYPE_NONE = 0
0a7de745
A
644 , NSTAT_IFNET_DESC_LINK_STATUS_TYPE_CELLULAR = 1
645 , NSTAT_IFNET_DESC_LINK_STATUS_TYPE_WIFI = 2
646 , NSTAT_IFNET_DESC_LINK_STATUS_TYPE_ETHERNET = 3
3e170ce0
A
647};
648
0a7de745
A
649typedef struct nstat_ifnet_desc_link_status {
650 u_int32_t link_status_type;
3e170ce0 651 union {
0a7de745
A
652 nstat_ifnet_desc_cellular_status cellular;
653 nstat_ifnet_desc_wifi_status wifi;
3e170ce0
A
654 } u;
655} nstat_ifnet_desc_link_status;
656
0a7de745
A
657#ifndef IF_DESCSIZE
658#define IF_DESCSIZE 128
39236c6e 659#endif
0a7de745
A
660typedef struct nstat_ifnet_descriptor {
661 u_int64_t threshold __attribute__((aligned(sizeof(u_int64_t))));
662 u_int32_t ifindex;
663 nstat_ifnet_desc_link_status link_status;
664 unsigned int type;
665 char description[IF_DESCSIZE];
666 char name[IFNAMSIZ + 1];
667 u_int8_t reserved[3];
39236c6e
A
668} nstat_ifnet_descriptor;
669
0a7de745
A
670typedef struct nstat_sysinfo_descriptor {
671 u_int32_t flags;
fe8ab488
A
672} nstat_sysinfo_descriptor;
673
0a7de745 674typedef struct nstat_sysinfo_add_param {
fe8ab488 675 /* To indicate which system level information should be collected */
0a7de745 676 u_int32_t flags;
fe8ab488
A
677} nstat_sysinfo_add_param;
678
0a7de745
A
679#define NSTAT_SYSINFO_MBUF_STATS 0x0001
680#define NSTAT_SYSINFO_TCP_STATS 0x0002
681#define NSTAT_SYSINFO_IFNET_ECN_STATS 0x0003
682#define NSTAT_SYSINFO_LIM_STATS 0x0004 /* Low Internet mode stats */
683#define NSTAT_SYSINFO_NET_API_STATS 0x0005 /* API and KPI stats */
fe8ab488 684
6d2010ae
A
685#pragma mark -- Network Statistics User Client --
686
0a7de745 687#define NET_STAT_CONTROL_NAME "com.apple.network.statistics"
6d2010ae 688
0a7de745 689enum{
316670eb 690 // generic response messages
cb323159
A
691 NSTAT_MSG_TYPE_SUCCESS = 0
692 , NSTAT_MSG_TYPE_ERROR = 1
0a7de745
A
693
694 // Requests
cb323159
A
695 , NSTAT_MSG_TYPE_ADD_SRC = 1001
696 , NSTAT_MSG_TYPE_ADD_ALL_SRCS = 1002
697 , NSTAT_MSG_TYPE_REM_SRC = 1003
698 , NSTAT_MSG_TYPE_QUERY_SRC = 1004
699 , NSTAT_MSG_TYPE_GET_SRC_DESC = 1005
700 , NSTAT_MSG_TYPE_SET_FILTER = 1006
701 , NSTAT_MSG_TYPE_GET_UPDATE = 1007
702 , NSTAT_MSG_TYPE_SUBSCRIBE_SYSINFO = 1008
0a7de745
A
703
704 // Responses/Notfications
cb323159
A
705 , NSTAT_MSG_TYPE_SRC_ADDED = 10001
706 , NSTAT_MSG_TYPE_SRC_REMOVED = 10002
707 , NSTAT_MSG_TYPE_SRC_DESC = 10003
708 , NSTAT_MSG_TYPE_SRC_COUNTS = 10004
709 , NSTAT_MSG_TYPE_SYSINFO_COUNTS = 10005
710 , NSTAT_MSG_TYPE_SRC_UPDATE = 10006
6d2010ae
A
711};
712
0a7de745
A
713enum{
714 NSTAT_SRC_REF_ALL = 0xffffffffffffffffULL
715 , NSTAT_SRC_REF_INVALID = 0
6d2010ae
A
716};
717
3e170ce0 718/* Source-level filters */
0a7de745 719enum{
3e170ce0
A
720 NSTAT_FILTER_NOZEROBYTES = 0x00000001
721};
722
723/* Provider-level filters */
0a7de745 724enum{
cb323159 725 NSTAT_FILTER_ACCEPT_UNKNOWN = 0x00000001
0a7de745
A
726 , NSTAT_FILTER_ACCEPT_LOOPBACK = 0x00000002
727 , NSTAT_FILTER_ACCEPT_CELLULAR = 0x00000004
728 , NSTAT_FILTER_ACCEPT_WIFI = 0x00000008
729 , NSTAT_FILTER_ACCEPT_WIRED = 0x00000010
730 , NSTAT_FILTER_ACCEPT_AWDL = 0x00000020
731 , NSTAT_FILTER_ACCEPT_EXPENSIVE = 0x00000040
732 , NSTAT_FILTER_ACCEPT_CELLFALLBACK = 0x00000100
cb323159
A
733 , NSTAT_FILTER_ACCEPT_COMPANIONLINK = 0x00000200
734 , NSTAT_FILTER_ACCEPT_IS_CONSTRAINED = 0x00000400
735 , NSTAT_FILTER_ACCEPT_IS_LOCAL = 0x00000800
736 , NSTAT_FILTER_ACCEPT_IS_NON_LOCAL = 0x00001000
737 , NSTAT_FILTER_IFNET_FLAGS = 0x00001FFF
0a7de745 738
0a7de745
A
739 , NSTAT_FILTER_TCP_INTERFACE_ATTACH = 0x00004000
740 , NSTAT_FILTER_TCP_NO_EARLY_CLOSE = 0x00008000
cb323159 741 , NSTAT_FILTER_TCP_FLAGS = 0x0000C000
0a7de745
A
742
743 , NSTAT_FILTER_UDP_INTERFACE_ATTACH = 0x00010000
744 , NSTAT_FILTER_UDP_FLAGS = 0x000F0000
745
746 , NSTAT_FILTER_SUPPRESS_SRC_ADDED = 0x00100000
747 , NSTAT_FILTER_REQUIRE_SRC_ADDED = 0x00200000
748 , NSTAT_FILTER_PROVIDER_NOZEROBYTES = 0x00400000
749
750 , NSTAT_FILTER_SPECIFIC_USER_BY_PID = 0x01000000
751 , NSTAT_FILTER_SPECIFIC_USER_BY_EPID = 0x02000000
752 , NSTAT_FILTER_SPECIFIC_USER_BY_UUID = 0x04000000
753 , NSTAT_FILTER_SPECIFIC_USER_BY_EUUID = 0x08000000
754 , NSTAT_FILTER_SPECIFIC_USER = 0x0F000000
3e170ce0
A
755};
756
0a7de745
A
757enum{
758 NSTAT_MSG_HDR_FLAG_SUPPORTS_AGGREGATE = 1 << 0,
759 NSTAT_MSG_HDR_FLAG_CONTINUATION = 1 << 1,
760 NSTAT_MSG_HDR_FLAG_CLOSING = 1 << 2,
39236c6e
A
761};
762
0a7de745
A
763typedef struct nstat_msg_hdr {
764 u_int64_t context __attribute__((aligned(sizeof(u_int64_t))));
765 u_int32_t type;
766 u_int16_t length;
767 u_int16_t flags;
6d2010ae
A
768} nstat_msg_hdr;
769
0a7de745
A
770typedef struct nstat_msg_error {
771 nstat_msg_hdr hdr;
772 u_int32_t error; // errno error
773 u_int8_t reserved[4];
6d2010ae
A
774} nstat_msg_error;
775
0a7de745
A
776#define NSTAT_ADD_SRC_FIELDS \
777 nstat_msg_hdr hdr; \
778 nstat_provider_id_t provider; \
779 u_int8_t reserved[4] \
5ba3f43e 780
0a7de745 781typedef struct nstat_msg_add_src {
5ba3f43e 782 NSTAT_ADD_SRC_FIELDS;
0a7de745 783 u_int8_t param[];
6d2010ae
A
784} nstat_msg_add_src_req;
785
0a7de745 786typedef struct nstat_msg_add_src_header {
5ba3f43e
A
787 NSTAT_ADD_SRC_FIELDS;
788} nstat_msg_add_src_header;
789
0a7de745
A
790typedef struct nstat_msg_add_src_convenient {
791 nstat_msg_add_src_header hdr;
5ba3f43e 792 union {
0a7de745
A
793 nstat_route_add_param route;
794 nstat_tcp_add_param tcp;
795 nstat_udp_add_param udp;
796 nstat_ifnet_add_param ifnet;
797 nstat_sysinfo_add_param sysinfo;
5ba3f43e
A
798 };
799} nstat_msg_add_src_convenient;
800
801#undef NSTAT_ADD_SRC_FIELDS
802
0a7de745
A
803typedef struct nstat_msg_add_all_srcs {
804 nstat_msg_hdr hdr;
cb323159 805 u_int64_t filter __attribute__((aligned(sizeof(u_int64_t))));
0a7de745
A
806 nstat_event_flags_t events __attribute__((aligned(sizeof(u_int64_t))));
807 nstat_provider_id_t provider;
cb323159
A
808 pid_t target_pid;
809 uuid_t target_uuid;
6d2010ae
A
810} nstat_msg_add_all_srcs;
811
0a7de745
A
812typedef struct nstat_msg_src_added {
813 nstat_msg_hdr hdr;
814 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
815 nstat_provider_id_t provider;
cb323159 816 u_int8_t reserved[4];
6d2010ae
A
817} nstat_msg_src_added;
818
0a7de745
A
819typedef struct nstat_msg_rem_src {
820 nstat_msg_hdr hdr;
821 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
6d2010ae
A
822} nstat_msg_rem_src_req;
823
0a7de745
A
824typedef struct nstat_msg_get_src_description {
825 nstat_msg_hdr hdr;
826 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
6d2010ae
A
827} nstat_msg_get_src_description;
828
0a7de745
A
829typedef struct nstat_msg_set_filter {
830 nstat_msg_hdr hdr;
831 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
cb323159
A
832 u_int32_t filter;
833 u_int8_t reserved[4];
39236c6e
A
834} nstat_msg_set_filter;
835
0a7de745
A
836#define NSTAT_SRC_DESCRIPTION_FIELDS \
837 nstat_msg_hdr hdr; \
838 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t)))); \
839 nstat_event_flags_t event_flags __attribute__((aligned(sizeof(u_int64_t)))); \
840 nstat_provider_id_t provider; \
5ba3f43e
A
841 u_int8_t reserved[4]
842
0a7de745 843typedef struct nstat_msg_src_description {
5ba3f43e 844 NSTAT_SRC_DESCRIPTION_FIELDS;
0a7de745 845 u_int8_t data[];
6d2010ae
A
846} nstat_msg_src_description;
847
0a7de745 848typedef struct nstat_msg_src_description_header {
5ba3f43e
A
849 NSTAT_SRC_DESCRIPTION_FIELDS;
850} nstat_msg_src_description_header;
851
0a7de745 852typedef struct nstat_msg_src_description_convenient {
cb323159 853 nstat_msg_src_description_header hdr;
5ba3f43e 854 union {
cb323159
A
855 nstat_tcp_descriptor tcp;
856 nstat_udp_descriptor udp;
857 nstat_route_descriptor route;
858 nstat_ifnet_descriptor ifnet;
859 nstat_sysinfo_descriptor sysinfo;
860 nstat_quic_descriptor quic;
5ba3f43e
A
861 };
862} nstat_msg_src_description_convenient;
863
864#undef NSTAT_SRC_DESCRIPTION_FIELDS
865
0a7de745
A
866typedef struct nstat_msg_query_src {
867 nstat_msg_hdr hdr;
868 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
6d2010ae
A
869} nstat_msg_query_src_req;
870
0a7de745
A
871typedef struct nstat_msg_src_counts {
872 nstat_msg_hdr hdr;
873 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
874 nstat_event_flags_t event_flags __attribute__((aligned(sizeof(u_int64_t))));
875 nstat_counts counts;
6d2010ae
A
876} nstat_msg_src_counts;
877
0a7de745
A
878#define NSTAT_SRC_UPDATE_FIELDS \
879 nstat_msg_hdr hdr; \
880 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t)))); \
881 nstat_event_flags_t event_flags __attribute__((aligned(sizeof(u_int64_t)))); \
882 nstat_counts counts; \
883 nstat_provider_id_t provider; \
5ba3f43e
A
884 u_int8_t reserved[4]
885
0a7de745 886typedef struct nstat_msg_src_update {
5ba3f43e 887 NSTAT_SRC_UPDATE_FIELDS;
0a7de745 888 u_int8_t data[];
3e170ce0
A
889} nstat_msg_src_update;
890
0a7de745 891typedef struct nstat_msg_src_update_hdr {
5ba3f43e
A
892 NSTAT_SRC_UPDATE_FIELDS;
893} nstat_msg_src_update_hdr;
894
0a7de745
A
895typedef struct nstat_msg_src_update_convenient {
896 nstat_msg_src_update_hdr hdr;
5ba3f43e 897 union {
0a7de745
A
898 nstat_tcp_descriptor tcp;
899 nstat_udp_descriptor udp;
900 nstat_route_descriptor route;
901 nstat_ifnet_descriptor ifnet;
902 nstat_sysinfo_descriptor sysinfo;
cb323159 903 nstat_quic_descriptor quic;
5ba3f43e
A
904 };
905} nstat_msg_src_update_convenient;
906
907#undef NSTAT_SRC_UPDATE_FIELDS
908
0a7de745
A
909typedef struct nstat_msg_src_removed {
910 nstat_msg_hdr hdr;
911 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
6d2010ae
A
912} nstat_msg_src_removed;
913
0a7de745
A
914typedef struct nstat_msg_sysinfo_counts {
915 nstat_msg_hdr hdr;
916 nstat_src_ref_t srcref __attribute__((aligned(sizeof(u_int64_t))));
917 nstat_sysinfo_counts counts;
5ba3f43e 918} nstat_msg_sysinfo_counts;
3e170ce0
A
919
920#pragma mark -- Statitiscs about Network Statistics --
921
922struct nstat_stats {
923 u_int32_t nstat_successmsgfailures;
924 u_int32_t nstat_sendcountfailures;
925 u_int32_t nstat_sysinfofailures;
926 u_int32_t nstat_srcupatefailures;
927 u_int32_t nstat_descriptionfailures;
928 u_int32_t nstat_msgremovedfailures;
929 u_int32_t nstat_srcaddedfailures;
930 u_int32_t nstat_msgerrorfailures;
931 u_int32_t nstat_copy_descriptor_failures;
932 u_int32_t nstat_provider_counts_failures;
933 u_int32_t nstat_control_send_description_failures;
934 u_int32_t nstat_control_send_goodbye_failures;
935 u_int32_t nstat_flush_accumulated_msgs_failures;
936 u_int32_t nstat_accumulate_msg_failures;
937 u_int32_t nstat_control_cleanup_source_failures;
938 u_int32_t nstat_handle_msg_failures;
939};
940
941#endif /* PRIVATE */
942
943#ifdef XNU_KERNEL_PRIVATE
944#include <sys/mcache.h>
945
946#pragma mark -- System Information Internal Support --
fe8ab488 947
0a7de745 948typedef struct nstat_sysinfo_mbuf_stats {
cb323159
A
949 u_int32_t total_256b; /* Peak usage, 256B pool */
950 u_int32_t total_2kb; /* Peak usage, 2KB pool */
951 u_int32_t total_4kb; /* Peak usage, 4KB pool */
952 u_int32_t total_16kb; /* Peak usage, 16KB pool */
953 u_int32_t sbmb_total; /* Total mbufs in sock buffer pool */
954 u_int32_t sb_atmbuflimit; /* Memory limit reached for socket buffer autoscaling */
955 u_int32_t draincnt; /* Number of times mbuf pool has been drained under memory pressure */
956 u_int32_t memreleased; /* Memory (bytes) released from mbuf pool to VM */
957 u_int32_t sbmb_floor; /* Lowest mbufs in sock buffer pool */
fe8ab488
A
958} nstat_sysinfo_mbuf_stats;
959
0a7de745 960typedef struct nstat_sysinfo_tcp_stats {
5ba3f43e 961 /* When adding/removing here, also adjust NSTAT_SYSINFO_TCP_STATS_COUNT */
cb323159
A
962 u_int32_t ipv4_avgrtt; /* Average RTT for IPv4 */
963 u_int32_t ipv6_avgrtt; /* Average RTT for IPv6 */
964 u_int32_t send_plr; /* Average uplink packet loss rate */
965 u_int32_t recv_plr; /* Average downlink packet loss rate */
966 u_int32_t send_tlrto_rate; /* Average rxt timeout after tail loss */
967 u_int32_t send_reorder_rate; /* Average packet reordering rate */
968 u_int32_t connection_attempts; /* TCP client connection attempts */
969 u_int32_t connection_accepts; /* TCP server connection accepts */
970 u_int32_t ecn_client_enabled; /* Global setting for ECN client side */
971 u_int32_t ecn_server_enabled; /* Global setting for ECN server side */
972 u_int32_t ecn_client_setup; /* Attempts to setup TCP client connection with ECN */
973 u_int32_t ecn_server_setup; /* Attempts to setup TCP server connection with ECN */
974 u_int32_t ecn_client_success; /* Number of successful negotiations of ECN for a client connection */
975 u_int32_t ecn_server_success; /* Number of successful negotiations of ECN for a server connection */
976 u_int32_t ecn_not_supported; /* Number of falbacks to Non-ECN, no support from peer */
977 u_int32_t ecn_lost_syn; /* Number of SYNs lost with ECN bits */
978 u_int32_t ecn_lost_synack; /* Number of SYN-ACKs lost with ECN bits */
979 u_int32_t ecn_recv_ce; /* Number of CEs received from network */
980 u_int32_t ecn_recv_ece; /* Number of ECEs received from receiver */
981 u_int32_t ecn_sent_ece; /* Number of ECEs sent in response to CE */
982 u_int32_t ecn_conn_recv_ce; /* Number of connections using ECN received CE at least once */
983 u_int32_t ecn_conn_recv_ece; /* Number of connections using ECN received ECE at least once */
984 u_int32_t ecn_conn_plnoce; /* Number of connections using ECN seen packet loss but never received CE */
985 u_int32_t ecn_conn_pl_ce; /* Number of connections using ECN seen packet loss and CE */
986 u_int32_t ecn_conn_nopl_ce; /* Number of connections using ECN with no packet loss but received CE */
987 u_int32_t ecn_fallback_synloss; /* Number of times we did fall back due to SYN-Loss */
988 u_int32_t ecn_fallback_reorder; /* Number of times we fallback because we detected the PAWS-issue */
989 u_int32_t ecn_fallback_ce; /* Number of times we fallback because we received too many CEs */
990 u_int32_t tfo_syn_data_rcv; /* Number of SYN+data received with valid cookie */
991 u_int32_t tfo_cookie_req_rcv;/* Number of TFO cookie-requests received */
992 u_int32_t tfo_cookie_sent; /* Number of TFO-cookies offered to the client */
993 u_int32_t tfo_cookie_invalid;/* Number of invalid TFO-cookies received */
994 u_int32_t tfo_cookie_req; /* Number of SYNs with cookie request received*/
995 u_int32_t tfo_cookie_rcv; /* Number of SYN/ACKs with Cookie received */
996 u_int32_t tfo_syn_data_sent; /* Number of SYNs+data+cookie sent */
997 u_int32_t tfo_syn_data_acked;/* Number of times our SYN+data has been acknowledged */
998 u_int32_t tfo_syn_loss; /* Number of times SYN+TFO has been lost and we fallback */
999 u_int32_t tfo_blackhole; /* Number of times SYN+TFO has been lost and we fallback */
1000 u_int32_t tfo_cookie_wrong; /* TFO-cookie we sent was wrong */
1001 u_int32_t tfo_no_cookie_rcv; /* We asked for a cookie but didn't get one */
1002 u_int32_t tfo_heuristics_disable; /* TFO got disabled due to heuristics */
1003 u_int32_t tfo_sndblackhole; /* TFO got blackholed in the sending direction */
1004 u_int32_t mptcp_handover_attempt; /* Total number of MPTCP-attempts using handover mode */
1005 u_int32_t mptcp_interactive_attempt; /* Total number of MPTCP-attempts using interactive mode */
1006 u_int32_t mptcp_aggregate_attempt; /* Total number of MPTCP-attempts using aggregate mode */
1007 u_int32_t mptcp_fp_handover_attempt; /* Same as previous three but only for first-party apps */
1008 u_int32_t mptcp_fp_interactive_attempt;
1009 u_int32_t mptcp_fp_aggregate_attempt;
1010 u_int32_t mptcp_heuristic_fallback; /* Total number of MPTCP-connections that fell back due to heuristics */
1011 u_int32_t mptcp_fp_heuristic_fallback; /* Same as previous but for first-party apps */
1012 u_int32_t mptcp_handover_success_wifi; /* Total number of successfull handover-mode connections that *started* on WiFi */
1013 u_int32_t mptcp_handover_success_cell; /* Total number of successfull handover-mode connections that *started* on Cell */
1014 u_int32_t mptcp_interactive_success; /* Total number of interactive-mode connections that negotiated MPTCP */
1015 u_int32_t mptcp_aggregate_success; /* Same as previous but for aggregate */
1016 u_int32_t mptcp_fp_handover_success_wifi; /* Same as previous four, but for first-party apps */
1017 u_int32_t mptcp_fp_handover_success_cell;
1018 u_int32_t mptcp_fp_interactive_success;
1019 u_int32_t mptcp_fp_aggregate_success;
1020 u_int32_t mptcp_handover_cell_from_wifi; /* Total number of connections that use cell in handover-mode (coming from WiFi) */
1021 u_int32_t mptcp_handover_wifi_from_cell; /* Total number of connections that use WiFi in handover-mode (coming from cell) */
1022 u_int32_t mptcp_interactive_cell_from_wifi; /* Total number of connections that use cell in interactive mode (coming from WiFi) */
1023 u_int32_t mptcp_back_to_wifi; /* Total number of connections that succeed to move traffic away from cell (when starting on cell) */
1024 u_int64_t mptcp_handover_cell_bytes; /* Total number of bytes sent on cell in handover-mode (on new subflows, ignoring initial one) */
1025 u_int64_t mptcp_interactive_cell_bytes; /* Same as previous but for interactive */
1026 u_int64_t mptcp_aggregate_cell_bytes;
1027 u_int64_t mptcp_handover_all_bytes; /* Total number of bytes sent in handover */
1028 u_int64_t mptcp_interactive_all_bytes;
1029 u_int64_t mptcp_aggregate_all_bytes;
1030 u_int32_t mptcp_wifi_proxy; /* Total number of new subflows that fell back to regular TCP on cell */
1031 u_int32_t mptcp_cell_proxy; /* Total number of new subflows that fell back to regular TCP on WiFi */
1032 u_int32_t mptcp_triggered_cell; /* Total number of times an MPTCP-connection triggered cell bringup */
1033 u_int32_t _padding;
5ba3f43e 1034 /* When adding/removing here, also adjust NSTAT_SYSINFO_TCP_STATS_COUNT */
fe8ab488 1035} nstat_sysinfo_tcp_stats;
0a7de745 1036#define NSTAT_SYSINFO_TCP_STATS_COUNT 71
fe8ab488 1037
4bd07ac2
A
1038enum {
1039 NSTAT_IFNET_ECN_PROTO_IPV4 = 1
0a7de745 1040 , NSTAT_IFNET_ECN_PROTO_IPV6
4bd07ac2
A
1041};
1042
1043enum {
1044 NSTAT_IFNET_ECN_TYPE_CELLULAR = 1
0a7de745
A
1045 , NSTAT_IFNET_ECN_TYPE_WIFI
1046 , NSTAT_IFNET_ECN_TYPE_ETHERNET
4bd07ac2
A
1047};
1048
1049typedef struct nstat_sysinfo_ifnet_ecn_stats {
cb323159
A
1050 u_int32_t ifnet_proto;
1051 u_int32_t ifnet_type;
1052 struct if_tcp_ecn_stat ecn_stat;
4bd07ac2
A
1053} nstat_sysinfo_ifnet_ecn_stats;
1054
5ba3f43e 1055/* Total number of Low Internet stats that will be reported */
0a7de745 1056#define NSTAT_LIM_STAT_KEYVAL_COUNT 12
5ba3f43e 1057typedef struct nstat_sysinfo_lim_stats {
cb323159
A
1058 u_int8_t ifnet_signature[NSTAT_SYSINFO_KEYVAL_STRING_MAXSIZE];
1059 u_int32_t ifnet_siglen;
1060 u_int32_t ifnet_type;
1061 struct if_lim_perf_stat lim_stat;
5ba3f43e
A
1062} nstat_sysinfo_lim_stats;
1063
0a7de745 1064#define NSTAT_NET_API_STAT_KEYVAL_COUNT (NSTAT_SYSINFO_API_LAST - NSTAT_SYSINFO_API_FIRST + 1)
5ba3f43e 1065typedef struct nstat_sysinfo_net_api_stats {
cb323159
A
1066 u_int32_t report_interval;
1067 u_int32_t _padding;
1068 struct net_api_stats net_api_stats;
5ba3f43e
A
1069} nstat_sysinfo_net_api_stats;
1070
0a7de745
A
1071typedef struct nstat_sysinfo_data {
1072 uint32_t flags;
1073 uint32_t unsent_data_cnt; /* Before sleeping */
fe8ab488
A
1074 union {
1075 nstat_sysinfo_mbuf_stats mb_stats;
1076 nstat_sysinfo_tcp_stats tcp_stats;
4bd07ac2 1077 nstat_sysinfo_ifnet_ecn_stats ifnet_ecn_stats;
5ba3f43e
A
1078 nstat_sysinfo_lim_stats lim_stats;
1079 nstat_sysinfo_net_api_stats net_api_stats;
fe8ab488
A
1080 } u;
1081} nstat_sysinfo_data;
1082
6d2010ae
A
1083#pragma mark -- Generic Network Statistics Provider --
1084
0a7de745 1085typedef void * nstat_provider_cookie_t;
6d2010ae
A
1086
1087#pragma mark -- Route Statistics Gathering Functions --
1088struct rtentry;
1089
0a7de745
A
1090enum{
1091 NSTAT_TX_FLAG_RETRANSMIT = 1
6d2010ae
A
1092};
1093
0a7de745
A
1094enum{
1095 NSTAT_RX_FLAG_DUPLICATE = 1,
1096 NSTAT_RX_FLAG_OUT_OF_ORDER = 2
6d2010ae
A
1097};
1098
1099// indicates whether or not collection of statistics is enabled
0a7de745 1100extern int nstat_collect;
6d2010ae 1101
316670eb
A
1102void nstat_init(void);
1103
6d2010ae
A
1104// Route collection routines
1105void nstat_route_connect_attempt(struct rtentry *rte);
1106void nstat_route_connect_success(struct rtentry *rte);
1107void nstat_route_tx(struct rtentry *rte, u_int32_t packets, u_int32_t bytes, u_int32_t flags);
1108void nstat_route_rx(struct rtentry *rte, u_int32_t packets, u_int32_t bytes, u_int32_t flags);
1109void nstat_route_rtt(struct rtentry *rte, u_int32_t rtt, u_int32_t rtt_var);
5ba3f43e 1110void nstat_route_update(struct rtentry *rte, uint32_t connect_attempts, uint32_t connect_successes,
0a7de745
A
1111 uint32_t rx_packets, uint32_t rx_bytes, uint32_t rx_duplicatebytes, uint32_t rx_outoforderbytes,
1112 uint32_t tx_packets, uint32_t tx_bytes, uint32_t tx_retransmit,
1113 uint32_t rtt, uint32_t rtt_var);
1114struct nstat_counts* nstat_route_attach(struct rtentry *rte);
6d2010ae
A
1115void nstat_route_detach(struct rtentry *rte);
1116
1117// watcher support
1118struct inpcb;
1119void nstat_tcp_new_pcb(struct inpcb *inp);
1120void nstat_udp_new_pcb(struct inpcb *inp);
1121void nstat_route_new_entry(struct rtentry *rt);
316670eb 1122void nstat_pcb_detach(struct inpcb *inp);
cb323159 1123void nstat_pcb_event(struct inpcb *inp, u_int64_t event);
fe8ab488
A
1124void nstat_pcb_cache(struct inpcb *inp);
1125void nstat_pcb_invalidate_cache(struct inpcb *inp);
6d2010ae 1126
39236c6e
A
1127
1128void nstat_ifnet_threshold_reached(unsigned int ifindex);
1129
fe8ab488
A
1130void nstat_sysinfo_send_data(struct nstat_sysinfo_data *);
1131
d9a64523
A
1132int ntstat_tcp_progress_indicators(struct sysctl_req *req);
1133
39037602 1134
5ba3f43e
A
1135// Utilities for userland stats reporting
1136u_int16_t nstat_ifnet_to_flags(struct ifnet *ifp);
39037602 1137
6d2010ae
A
1138// locked_add_64 uses atomic operations on 32bit so the 64bit
1139// value can be properly read. The values are only ever incremented
1140// while under the socket lock, so on 64bit we don't actually need
1141// atomic operations to increment.
1142#if defined(__LP64__)
0a7de745 1143#define locked_add_64(__addr, __count) do { \
6d2010ae
A
1144 *(__addr) += (__count); \
1145} while (0)
1146#else
0a7de745 1147#define locked_add_64(__addr, __count) do { \
6d2010ae
A
1148 atomic_add_64((__addr), (__count)); \
1149} while (0)
1150#endif
1151
1152#endif /* XNU_KERNEL_PRIVATE */
1153
1154#endif /* __NTSTAT_H__ */