]>
Commit | Line | Data |
---|---|---|
fe8ab488 | 1 | /* |
cb323159 | 2 | * Copyright (c) 2013-2019 Apple Inc. All rights reserved. |
fe8ab488 A |
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 | ||
0a7de745 A |
29 | #ifndef _NET_NECP_H_ |
30 | #define _NET_NECP_H_ | |
fe8ab488 | 31 | |
39037602 A |
32 | #include <net/net_kev.h> |
33 | #ifdef PRIVATE | |
34 | ||
fe8ab488 | 35 | #include <netinet/in.h> |
5ba3f43e | 36 | #include <netinet/in_stat.h> |
fe8ab488 | 37 | #include <sys/socket.h> |
39037602 | 38 | #include <net/if.h> |
fe8ab488 A |
39 | |
40 | /* | |
4ba76501 | 41 | * Name registered by the NECP |
fe8ab488 | 42 | */ |
0a7de745 | 43 | #define NECP_CONTROL_NAME "com.apple.net.necp_control" |
fe8ab488 | 44 | |
0a7de745 | 45 | #define NECP_TLV_LENGTH_UINT32 1 |
3e170ce0 | 46 | |
fe8ab488 | 47 | struct necp_packet_header { |
0a7de745 A |
48 | u_int8_t packet_type; |
49 | u_int8_t flags; | |
50 | u_int32_t message_id; | |
fe8ab488 | 51 | }; |
39037602 A |
52 | |
53 | /* | |
54 | * Control message commands | |
55 | */ | |
0a7de745 A |
56 | #define NECP_PACKET_TYPE_POLICY_ADD 1 |
57 | #define NECP_PACKET_TYPE_POLICY_GET 2 | |
58 | #define NECP_PACKET_TYPE_POLICY_DELETE 3 | |
59 | #define NECP_PACKET_TYPE_POLICY_APPLY_ALL 4 | |
60 | #define NECP_PACKET_TYPE_POLICY_LIST_ALL 5 | |
61 | #define NECP_PACKET_TYPE_POLICY_DELETE_ALL 6 | |
62 | #define NECP_PACKET_TYPE_SET_SESSION_PRIORITY 7 | |
63 | #define NECP_PACKET_TYPE_LOCK_SESSION_TO_PROC 8 | |
64 | #define NECP_PACKET_TYPE_REGISTER_SERVICE 9 | |
65 | #define NECP_PACKET_TYPE_UNREGISTER_SERVICE 10 | |
66 | #define NECP_PACKET_TYPE_POLICY_DUMP_ALL 11 | |
fe8ab488 | 67 | |
5ba3f43e A |
68 | /* |
69 | * Session actions | |
70 | */ | |
0a7de745 A |
71 | #define NECP_SESSION_ACTION_POLICY_ADD 1 // In: Policy TLVs Out: necp_policy_id |
72 | #define NECP_SESSION_ACTION_POLICY_GET 2 // In: necp_policy_id Out: Policy TLVs | |
73 | #define NECP_SESSION_ACTION_POLICY_DELETE 3 // In: necp_policy_id Out: None | |
74 | #define NECP_SESSION_ACTION_POLICY_APPLY_ALL 4 // In: None Out: None | |
75 | #define NECP_SESSION_ACTION_POLICY_LIST_ALL 5 // In: None Out: TLVs of IDs | |
76 | #define NECP_SESSION_ACTION_POLICY_DELETE_ALL 6 // In: None Out: None | |
77 | #define NECP_SESSION_ACTION_SET_SESSION_PRIORITY 7 // In: necp_session_priority Out: None | |
78 | #define NECP_SESSION_ACTION_LOCK_SESSION_TO_PROC 8 // In: None Out: None | |
79 | #define NECP_SESSION_ACTION_REGISTER_SERVICE 9 // In: uuid_t Out: None | |
80 | #define NECP_SESSION_ACTION_UNREGISTER_SERVICE 10 // In: uuid_t Out: None | |
81 | #define NECP_SESSION_ACTION_POLICY_DUMP_ALL 11 // In: None Out: uint32_t bytes length, then Policy TLVs | |
5ba3f43e | 82 | |
39037602 A |
83 | /* |
84 | * Control message flags | |
85 | */ | |
0a7de745 | 86 | #define NECP_PACKET_FLAGS_RESPONSE 0x01 // Used for acks, errors, and query responses |
fe8ab488 | 87 | |
39037602 A |
88 | /* |
89 | * Control message TLV types | |
90 | */ | |
0a7de745 A |
91 | #define NECP_TLV_NIL 0 |
92 | #define NECP_TLV_ERROR 1 // u_int32_t | |
93 | #define NECP_TLV_POLICY_ORDER 2 // u_int32_t | |
94 | #define NECP_TLV_POLICY_CONDITION 3 | |
95 | #define NECP_TLV_POLICY_RESULT 4 | |
96 | #define NECP_TLV_POLICY_ID 5 // u_int32_t | |
97 | #define NECP_TLV_SESSION_PRIORITY 6 // u_int32_t | |
98 | #define NECP_TLV_ATTRIBUTE_DOMAIN 7 // char[] | |
99 | #define NECP_TLV_ATTRIBUTE_ACCOUNT 8 // char[] | |
100 | #define NECP_TLV_SERVICE_UUID 9 // uuid_t | |
101 | #define NECP_TLV_ROUTE_RULE 10 | |
fe8ab488 | 102 | |
39037602 A |
103 | /* |
104 | * Control message TLV sent only by the kernel to userspace | |
105 | */ | |
0a7de745 A |
106 | #define NECP_TLV_POLICY_OWNER 100 // char [] |
107 | #define NECP_TLV_POLICY_DUMP 101 | |
108 | #define NECP_TLV_POLICY_RESULT_STRING 102 // char [] | |
109 | #define NECP_TLV_POLICY_SESSION_ORDER 103 // u_int32_t | |
39037602 A |
110 | |
111 | /* | |
112 | * Condition flags | |
113 | */ | |
0a7de745 | 114 | #define NECP_POLICY_CONDITION_FLAGS_NEGATIVE 0x01 // Negative |
fe8ab488 | 115 | |
39037602 A |
116 | /* |
117 | * Conditions | |
118 | * Used for setting policies as well as passing parameters to necp_match_policy. | |
119 | */ | |
0a7de745 | 120 | #define NECP_POLICY_CONDITION_DEFAULT 0 // N/A, not valid with any other conditions |
fe8ab488 | 121 | // Socket/Application conditions |
0a7de745 A |
122 | #define NECP_POLICY_CONDITION_APPLICATION 1 // uuid_t, uses effective UUID when possible |
123 | #define NECP_POLICY_CONDITION_REAL_APPLICATION 2 // uuid_t, never uses effective UUID. Only valid with NECP_POLICY_CONDITION_APPLICATION | |
124 | #define NECP_POLICY_CONDITION_DOMAIN 3 // String, such as apple.com | |
125 | #define NECP_POLICY_CONDITION_ACCOUNT 4 // String | |
126 | #define NECP_POLICY_CONDITION_ENTITLEMENT 5 // String | |
127 | #define NECP_POLICY_CONDITION_PID 6 // pid_t | |
128 | #define NECP_POLICY_CONDITION_UID 7 // uid_t | |
129 | #define NECP_POLICY_CONDITION_ALL_INTERFACES 8 // N/A | |
130 | #define NECP_POLICY_CONDITION_BOUND_INTERFACE 9 // String | |
131 | #define NECP_POLICY_CONDITION_TRAFFIC_CLASS 10 // necp_policy_condition_tc_range | |
fe8ab488 | 132 | // Socket/IP conditions |
cb323159 | 133 | #define NECP_POLICY_CONDITION_IP_PROTOCOL 11 // u_int16_t |
0a7de745 A |
134 | #define NECP_POLICY_CONDITION_LOCAL_ADDR 12 // necp_policy_condition_addr |
135 | #define NECP_POLICY_CONDITION_REMOTE_ADDR 13 // necp_policy_condition_addr | |
136 | #define NECP_POLICY_CONDITION_LOCAL_ADDR_RANGE 14 // necp_policy_condition_addr_range | |
137 | #define NECP_POLICY_CONDITION_REMOTE_ADDR_RANGE 15 // necp_policy_condition_addr_range | |
138 | #define NECP_POLICY_CONDITION_AGENT_TYPE 16 // struct necp_policy_condition_agent_type | |
cb323159 A |
139 | #define NECP_POLICY_CONDITION_HAS_CLIENT 17 // N/A |
140 | #define NECP_POLICY_CONDITION_LOCAL_NETWORKS 18 // Matches all local networks | |
141 | // Socket-only conditions | |
142 | #define NECP_POLICY_CONDITION_FLOW_IP_PROTOCOL 19 // u_int16_t | |
143 | #define NECP_POLICY_CONDITION_FLOW_LOCAL_ADDR 20 // necp_policy_condition_addr | |
144 | #define NECP_POLICY_CONDITION_FLOW_REMOTE_ADDR 21 // necp_policy_condition_addr | |
145 | #define NECP_POLICY_CONDITION_FLOW_LOCAL_ADDR_RANGE 22 // necp_policy_condition_addr_range | |
146 | #define NECP_POLICY_CONDITION_FLOW_REMOTE_ADDR_RANGE 23 // necp_policy_condition_addr_range | |
147 | // Socket/Application conditions, continued | |
148 | #define NECP_POLICY_CONDITION_CLIENT_FLAGS 24 // u_int32_t, values from NECP_CLIENT_PARAMETER_FLAG_* | |
149 | #define NECP_POLICY_CONDITION_FLOW_LOCAL_ADDR_EMPTY 25 // N/A | |
150 | #define NECP_POLICY_CONDITION_FLOW_REMOTE_ADDR_EMPTY 26 // N/A | |
151 | #define NECP_POLICY_CONDITION_PLATFORM_BINARY 27 // N/A | |
eb6b6ca3 | 152 | #define NECP_POLICY_CONDITION_SIGNING_IDENTIFIER 28 // String |
fe8ab488 | 153 | |
39037602 A |
154 | /* |
155 | * Results | |
156 | */ | |
0a7de745 A |
157 | #define NECP_POLICY_RESULT_PASS 1 // N/A |
158 | #define NECP_POLICY_RESULT_SKIP 2 // u_int32_t, policy order to skip to. 0 to skip all session policies. | |
159 | #define NECP_POLICY_RESULT_DROP 3 // N/A | |
160 | #define NECP_POLICY_RESULT_SOCKET_DIVERT 4 // u_int32_t, flow divert control unit | |
161 | #define NECP_POLICY_RESULT_SOCKET_FILTER 5 // u_int32_t, filter control unit | |
162 | #define NECP_POLICY_RESULT_IP_TUNNEL 6 // String, interface name | |
163 | #define NECP_POLICY_RESULT_IP_FILTER 7 // ? | |
164 | #define NECP_POLICY_RESULT_TRIGGER 8 // service uuid_t | |
165 | #define NECP_POLICY_RESULT_TRIGGER_IF_NEEDED 9 // service uuid_t | |
166 | #define NECP_POLICY_RESULT_TRIGGER_SCOPED 10 // service uuid_t | |
167 | #define NECP_POLICY_RESULT_NO_TRIGGER_SCOPED 11 // service uuid_t | |
168 | #define NECP_POLICY_RESULT_SOCKET_SCOPED 12 // String, interface name | |
169 | #define NECP_POLICY_RESULT_ROUTE_RULES 13 // N/A, must have route rules defined | |
170 | #define NECP_POLICY_RESULT_USE_NETAGENT 14 // netagent uuid_t | |
171 | #define NECP_POLICY_RESULT_NETAGENT_SCOPED 15 // netagent uuid_t | |
172 | #define NECP_POLICY_RESULT_SCOPED_DIRECT 16 // N/A, scopes to primary physical interface | |
ea3f0419 | 173 | #define NECP_POLICY_RESULT_ALLOW_UNENTITLED 17 // N/A |
0a7de745 | 174 | |
ea3f0419 A |
175 | #define NECP_POLICY_RESULT_MAX NECP_POLICY_RESULT_ALLOW_UNENTITLED |
176 | ||
177 | /* | |
178 | * PASS Result Flags | |
179 | */ | |
180 | #define NECP_POLICY_PASS_NO_SKIP_IPSEC 0x01 | |
fe8ab488 | 181 | |
39037602 A |
182 | /* |
183 | * Route Rules | |
184 | * Detailed parameters for NECP_POLICY_RESULT_ROUTE_RULES. | |
185 | */ | |
0a7de745 A |
186 | #define NECP_ROUTE_RULE_NONE 0 // N/A |
187 | #define NECP_ROUTE_RULE_DENY_INTERFACE 1 // String, or empty to match all | |
188 | #define NECP_ROUTE_RULE_ALLOW_INTERFACE 2 // String, or empty to match all | |
189 | #define NECP_ROUTE_RULE_QOS_MARKING 3 // String, or empty to match all | |
190 | #define NECP_ROUTE_RULE_DENY_LQM_ABORT 4 // String, or empty to match all | |
3e170ce0 | 191 | |
0a7de745 | 192 | #define NECP_ROUTE_RULE_FLAG_CELLULAR 0x01 |
cb323159 A |
193 | #define NECP_ROUTE_RULE_FLAG_WIFI 0x02 |
194 | #define NECP_ROUTE_RULE_FLAG_WIRED 0x04 | |
0a7de745 | 195 | #define NECP_ROUTE_RULE_FLAG_EXPENSIVE 0x08 |
cb323159 | 196 | #define NECP_ROUTE_RULE_FLAG_CONSTRAINED 0x10 |
fe8ab488 | 197 | |
39037602 A |
198 | /* |
199 | * Error types | |
200 | */ | |
0a7de745 A |
201 | #define NECP_ERROR_INTERNAL 0 |
202 | #define NECP_ERROR_UNKNOWN_PACKET_TYPE 1 | |
203 | #define NECP_ERROR_INVALID_TLV 2 | |
204 | #define NECP_ERROR_POLICY_RESULT_INVALID 3 | |
205 | #define NECP_ERROR_POLICY_CONDITIONS_INVALID 4 | |
206 | #define NECP_ERROR_POLICY_ID_NOT_FOUND 5 | |
207 | #define NECP_ERROR_INVALID_PROCESS 6 | |
208 | #define NECP_ERROR_ROUTE_RULES_INVALID 7 | |
fe8ab488 A |
209 | |
210 | // Modifiers | |
0a7de745 | 211 | #define NECP_MASK_USERSPACE_ONLY 0x80000000 // on filter_control_unit value |
fe8ab488 A |
212 | |
213 | struct necp_policy_condition_tc_range { | |
214 | u_int32_t start_tc; | |
215 | u_int32_t end_tc; | |
216 | } __attribute__((__packed__)); | |
217 | ||
218 | struct necp_policy_condition_addr { | |
0a7de745 | 219 | u_int8_t prefix; |
fe8ab488 | 220 | union { |
0a7de745 A |
221 | struct sockaddr sa; |
222 | struct sockaddr_in sin; | |
223 | struct sockaddr_in6 sin6; | |
fe8ab488 A |
224 | } address; |
225 | } __attribute__((__packed__)); | |
226 | ||
227 | struct necp_policy_condition_addr_range { | |
228 | union { | |
0a7de745 A |
229 | struct sockaddr sa; |
230 | struct sockaddr_in sin; | |
231 | struct sockaddr_in6 sin6; | |
fe8ab488 A |
232 | } start_address; |
233 | union { | |
0a7de745 A |
234 | struct sockaddr sa; |
235 | struct sockaddr_in sin; | |
236 | struct sockaddr_in6 sin6; | |
fe8ab488 A |
237 | } end_address; |
238 | } __attribute__((__packed__)); | |
239 | ||
d9a64523 A |
240 | struct necp_policy_condition_agent_type { |
241 | char agent_domain[32]; | |
242 | char agent_type[32]; | |
243 | } __attribute__((__packed__)); | |
244 | ||
0a7de745 A |
245 | #define NECP_SESSION_PRIORITY_UNKNOWN 0 |
246 | #define NECP_SESSION_PRIORITY_CONTROL 1 | |
ea3f0419 A |
247 | #define NECP_SESSION_PRIORITY_PRIVILEGED_TUNNEL 2 |
248 | #define NECP_SESSION_PRIORITY_HIGH 3 | |
249 | #define NECP_SESSION_PRIORITY_HIGH_1 4 | |
250 | #define NECP_SESSION_PRIORITY_HIGH_2 5 | |
251 | #define NECP_SESSION_PRIORITY_HIGH_3 6 | |
252 | #define NECP_SESSION_PRIORITY_HIGH_4 7 | |
253 | #define NECP_SESSION_PRIORITY_HIGH_RESTRICTED 8 | |
254 | #define NECP_SESSION_PRIORITY_DEFAULT 9 | |
255 | #define NECP_SESSION_PRIORITY_LOW 10 | |
0a7de745 | 256 | #define NECP_SESSION_NUM_PRIORITIES NECP_SESSION_PRIORITY_LOW |
fe8ab488 A |
257 | |
258 | typedef u_int32_t necp_policy_id; | |
259 | typedef u_int32_t necp_policy_order; | |
5ba3f43e | 260 | typedef u_int32_t necp_session_priority; |
fe8ab488 A |
261 | |
262 | typedef u_int32_t necp_kernel_policy_result; | |
263 | typedef u_int32_t necp_kernel_policy_filter; | |
264 | ||
265 | typedef union { | |
0a7de745 A |
266 | u_int tunnel_interface_index; |
267 | u_int scoped_interface_index; | |
268 | u_int32_t flow_divert_control_unit; | |
269 | u_int32_t filter_control_unit; | |
fe8ab488 A |
270 | } necp_kernel_policy_routing_result_parameter; |
271 | ||
0a7de745 A |
272 | #define NECP_SERVICE_FLAGS_REGISTERED 0x01 |
273 | #define NECP_MAX_NETAGENTS 8 | |
5ba3f43e | 274 | |
0a7de745 | 275 | #define NECP_AGENT_USE_FLAG_SCOPE 0x01 |
d9a64523 | 276 | |
5ba3f43e | 277 | #define NECP_TFO_COOKIE_LEN_MAX 16 |
fe8ab488 | 278 | struct necp_aggregate_result { |
0a7de745 A |
279 | necp_kernel_policy_result routing_result; |
280 | necp_kernel_policy_routing_result_parameter routing_result_parameter; | |
281 | necp_kernel_policy_filter filter_control_unit; | |
282 | necp_kernel_policy_result service_action; | |
283 | uuid_t service_uuid; | |
284 | u_int32_t service_flags; | |
285 | u_int32_t service_data; | |
286 | u_int routed_interface_index; | |
287 | u_int32_t policy_id; | |
288 | uuid_t netagents[NECP_MAX_NETAGENTS]; | |
289 | u_int32_t netagent_use_flags[NECP_MAX_NETAGENTS]; | |
290 | u_int8_t mss_recommended; | |
3e170ce0 A |
291 | }; |
292 | ||
39037602 A |
293 | /* |
294 | * Statistics. It would be nice if the definitions in ntstat.h could be used, | |
295 | * but they get entangled with #defines for v4 etc in pfvar.h and it may be better practice | |
296 | * to have separate definitions here. | |
297 | */ | |
0a7de745 | 298 | struct necp_stat_counts { |
39037602 | 299 | /* Counters */ |
0a7de745 A |
300 | u_int64_t necp_stat_rxpackets __attribute__((aligned(8))); |
301 | u_int64_t necp_stat_rxbytes __attribute__((aligned(8))); | |
302 | u_int64_t necp_stat_txpackets __attribute__((aligned(8))); | |
303 | u_int64_t necp_stat_txbytes __attribute__((aligned(8))); | |
39037602 | 304 | |
0a7de745 A |
305 | u_int32_t necp_stat_rxduplicatebytes; |
306 | u_int32_t necp_stat_rxoutoforderbytes; | |
307 | u_int32_t necp_stat_txretransmit; | |
39037602 | 308 | |
0a7de745 A |
309 | u_int32_t necp_stat_connectattempts; |
310 | u_int32_t necp_stat_connectsuccesses; | |
39037602 | 311 | |
0a7de745 A |
312 | u_int32_t necp_stat_min_rtt; |
313 | u_int32_t necp_stat_avg_rtt; | |
314 | u_int32_t necp_stat_var_rtt; | |
39037602 | 315 | |
0a7de745 A |
316 | #define NECP_STAT_ROUTE_FLAGS 1 |
317 | u_int32_t necp_stat_route_flags; | |
5ba3f43e | 318 | }; |
39037602 A |
319 | |
320 | // Note, some metadata is implicit in the necp client itself: | |
321 | // From the process itself : pid, upid, uuid, proc name. | |
322 | // From the necp client parameters: local and remote addresses, euuid, traffic class, ifindex | |
323 | // | |
324 | // The following may well be supplied via future necp client parameters, | |
325 | // but they are here so they don't get forgotten. | |
0a7de745 A |
326 | struct necp_basic_metadata { |
327 | u_int32_t rcvbufsize; | |
328 | u_int32_t rcvbufused; | |
5ba3f43e | 329 | }; |
39037602 | 330 | |
cb323159 | 331 | struct necp_connection_probe_status { |
0a7de745 A |
332 | unsigned int probe_activated : 1; |
333 | unsigned int write_probe_failed : 1; | |
334 | unsigned int read_probe_failed : 1; | |
335 | unsigned int conn_probe_failed : 1; | |
39037602 A |
336 | }; |
337 | ||
0a7de745 | 338 | struct necp_extra_tcp_metadata { |
cb323159 | 339 | struct necp_connection_probe_status probestatus; |
39037602 | 340 | |
0a7de745 A |
341 | u_int32_t sndbufsize; |
342 | u_int32_t sndbufused; | |
343 | u_int32_t txunacked; | |
344 | u_int32_t txwindow; | |
345 | u_int32_t txcwindow; | |
346 | u_int32_t flags; // use SOF_* | |
347 | u_int32_t flags1; // use SOF1_* | |
348 | u_int32_t traffic_mgt_flags; | |
349 | u_int32_t cc_alg_index; | |
350 | u_int32_t state; | |
5ba3f43e | 351 | }; |
39037602 | 352 | |
5ba3f43e | 353 | struct necp_stats_hdr { |
0a7de745 A |
354 | u_int32_t necp_stats_type __attribute__((aligned(8))); |
355 | u_int32_t necp_stats_ver; | |
356 | u_int64_t __necp_stats_reserved; // Pad the field for future use | |
5ba3f43e | 357 | }; |
39037602 | 358 | |
0a7de745 A |
359 | #define NECP_CLIENT_STATISTICS_TYPE_TCP 1 // Identifies use of necp_tcp_stats |
360 | #define NECP_CLIENT_STATISTICS_TYPE_UDP 2 // Identifies use of necp_udp_stats | |
cb323159 A |
361 | #define NECP_CLIENT_STATISTICS_TYPE_QUIC 3 // Identifies use of necp_quic_stats |
362 | ||
0a7de745 A |
363 | #define NECP_CLIENT_STATISTICS_TYPE_TCP_VER_1 1 // Currently supported version for TCP |
364 | #define NECP_CLIENT_STATISTICS_TYPE_UDP_VER_1 1 // Currently supported version for UDP | |
cb323159 | 365 | #define NECP_CLIENT_STATISTICS_TYPE_QUIC_VER_1 1 // Currently supported version for QUIC |
39037602 | 366 | |
0a7de745 A |
367 | #define NECP_CLIENT_STATISTICS_TYPE_TCP_CURRENT_VER NECP_CLIENT_STATISTICS_TYPE_TCP_VER_1 |
368 | #define NECP_CLIENT_STATISTICS_TYPE_UDP_CURRENT_VER NECP_CLIENT_STATISTICS_TYPE_UDP_VER_1 | |
cb323159 | 369 | #define NECP_CLIENT_STATISTICS_TYPE_QUIC_CURRENT_VER NECP_CLIENT_STATISTICS_TYPE_QUIC_VER_1 |
5ba3f43e | 370 | |
0a7de745 A |
371 | #define NECP_CLIENT_STATISTICS_EVENT_INIT 0x00000000 // Register the flow |
372 | #define NECP_CLIENT_STATISTICS_EVENT_TIME_WAIT 0x00000001 // The flow is effectively finished but waiting on timer | |
5ba3f43e A |
373 | |
374 | struct necp_tcp_stats { | |
0a7de745 A |
375 | struct necp_stats_hdr necp_tcp_hdr; |
376 | struct necp_stat_counts necp_tcp_counts; | |
377 | struct necp_basic_metadata necp_tcp_basic; | |
378 | struct necp_extra_tcp_metadata necp_tcp_extra; | |
5ba3f43e | 379 | }; |
39037602 | 380 | |
5ba3f43e | 381 | struct necp_udp_stats { |
0a7de745 A |
382 | struct necp_stats_hdr necp_udp_hdr; |
383 | struct necp_stat_counts necp_udp_counts; | |
384 | struct necp_basic_metadata necp_udp_basic; | |
5ba3f43e | 385 | }; |
39037602 | 386 | |
cb323159 A |
387 | |
388 | /* | |
389 | * The following reflects the special case for QUIC. | |
390 | * It is a streaming protocol built on top of UDP. | |
391 | * Therefore QUIC stats are defined as basic UDP stats | |
392 | * with some extra meta data. | |
393 | * TODO: For now the extra metadata is an exact replica | |
394 | * of the metadata for TCP. However keeping that separate allows | |
395 | * the structures to diverge later as new stats are added. | |
396 | */ | |
397 | #define QUIC_STATELESS_RESET_TOKEN_SIZE 16 | |
398 | struct necp_extra_quic_metadata { | |
399 | u_int32_t sndbufsize; | |
400 | u_int32_t sndbufused; | |
401 | u_int32_t txunacked; | |
402 | u_int32_t txwindow; | |
403 | u_int32_t txcwindow; | |
404 | u_int32_t traffic_mgt_flags; | |
405 | u_int32_t cc_alg_index; | |
406 | u_int32_t state; | |
407 | u_int8_t ssr_token[QUIC_STATELESS_RESET_TOKEN_SIZE]; | |
408 | }; | |
409 | ||
410 | #define necp_quic_hdr necp_quic_udp_stats.necp_udp_hdr | |
411 | #define necp_quic_counts necp_quic_udp_stats.necp_udp_counts | |
412 | #define necp_quic_basic necp_quic_udp_stats.necp_udp_basic | |
413 | struct necp_quic_stats { | |
414 | struct necp_udp_stats necp_quic_udp_stats; | |
415 | struct necp_extra_quic_metadata necp_quic_extra; | |
416 | }; | |
417 | ||
39037602 A |
418 | typedef struct necp_all_stats { |
419 | union { | |
0a7de745 A |
420 | struct necp_tcp_stats tcp_stats; |
421 | struct necp_udp_stats udp_stats; | |
cb323159 | 422 | struct necp_quic_stats quic_stats; |
39037602 A |
423 | } all_stats_u; |
424 | } necp_all_stats; | |
425 | ||
5ba3f43e A |
426 | // Memory for statistics is requested via a necp_stats_bufreq |
427 | // | |
428 | struct necp_stats_bufreq { | |
0a7de745 A |
429 | u_int32_t necp_stats_bufreq_id __attribute__((aligned(8))); |
430 | u_int32_t necp_stats_bufreq_type; // NECP_CLIENT_STATISTICS_TYPE_* | |
431 | u_int32_t necp_stats_bufreq_ver; // NECP_CLIENT_STATISTICS_TYPE_*_VER | |
432 | u_int32_t necp_stats_bufreq_size; | |
5ba3f43e | 433 | union { |
0a7de745 A |
434 | void *necp_stats_bufreq_addr; |
435 | mach_vm_address_t necp_stats_bufreq_uaddr; | |
5ba3f43e A |
436 | }; |
437 | }; | |
438 | ||
0a7de745 | 439 | #define NECP_CLIENT_STATISTICS_BUFREQ_ID 0xbf // Distinguishes from statistics actions taking a necp_all_stats struct |
5ba3f43e A |
440 | |
441 | // There is a limit to the number of statistics structures that may be allocated per process, subject to change | |
442 | // | |
0a7de745 | 443 | #define NECP_MAX_PER_PROCESS_CLIENT_STATISTICS_STRUCTS 512 |
5ba3f43e A |
444 | |
445 | #define NECP_TCP_ECN_HEURISTICS_SYN_RST 1 | |
446 | typedef struct necp_tcp_ecn_cache { | |
447 | u_int8_t necp_tcp_ecn_heuristics_success:1; | |
448 | u_int8_t necp_tcp_ecn_heuristics_loss:1; | |
449 | u_int8_t necp_tcp_ecn_heuristics_drop_rst:1; | |
450 | u_int8_t necp_tcp_ecn_heuristics_drop_rxmt:1; | |
451 | u_int8_t necp_tcp_ecn_heuristics_aggressive:1; | |
452 | u_int8_t necp_tcp_ecn_heuristics_syn_rst:1; | |
453 | } necp_tcp_ecn_cache; | |
454 | ||
455 | #define NECP_TCP_TFO_HEURISTICS_RST 1 | |
456 | typedef struct necp_tcp_tfo_cache { | |
457 | u_int8_t necp_tcp_tfo_cookie[NECP_TFO_COOKIE_LEN_MAX]; | |
458 | u_int8_t necp_tcp_tfo_cookie_len; | |
459 | u_int8_t necp_tcp_tfo_heuristics_success:1; // TFO succeeded with data in the SYN | |
460 | u_int8_t necp_tcp_tfo_heuristics_loss:1; // TFO SYN-loss with data | |
461 | u_int8_t necp_tcp_tfo_heuristics_middlebox:1; // TFO middlebox detected | |
462 | u_int8_t necp_tcp_tfo_heuristics_success_req:1; // TFO succeeded with the TFO-option in the SYN | |
463 | u_int8_t necp_tcp_tfo_heuristics_loss_req:1; // TFO SYN-loss with the TFO-option | |
464 | u_int8_t necp_tcp_tfo_heuristics_rst_data:1; // Recevied RST upon SYN with data in the SYN | |
465 | u_int8_t necp_tcp_tfo_heuristics_rst_req:1; // Received RST upon SYN with the TFO-option | |
466 | } necp_tcp_tfo_cache; | |
467 | ||
0a7de745 A |
468 | #define NECP_CLIENT_CACHE_TYPE_ECN 1 // Identifies use of necp_tcp_ecn_cache |
469 | #define NECP_CLIENT_CACHE_TYPE_TFO 2 // Identifies use of necp_tcp_tfo_cache | |
5ba3f43e | 470 | |
0a7de745 A |
471 | #define NECP_CLIENT_CACHE_TYPE_ECN_VER_1 1 // Currently supported version for ECN |
472 | #define NECP_CLIENT_CACHE_TYPE_TFO_VER_1 1 // Currently supported version for TFO | |
5ba3f43e A |
473 | |
474 | typedef struct necp_cache_buffer { | |
475 | u_int8_t necp_cache_buf_type; // NECP_CLIENT_CACHE_TYPE_* | |
476 | u_int8_t necp_cache_buf_ver; // NECP_CLIENT_CACHE_TYPE_*_VER | |
477 | u_int32_t necp_cache_buf_size; | |
478 | mach_vm_address_t necp_cache_buf_addr; | |
479 | } necp_cache_buffer; | |
480 | ||
39037602 A |
481 | /* |
482 | * NECP Client definitions | |
483 | */ | |
0a7de745 A |
484 | #define NECP_MAX_CLIENT_PARAMETERS_SIZE 1024 |
485 | #define NECP_MAX_CLIENT_RESULT_SIZE 512 | |
486 | ||
487 | #define NECP_OPEN_FLAG_OBSERVER 0x01 // Observers can query clients they don't own | |
488 | #define NECP_OPEN_FLAG_BACKGROUND 0x02 // Mark this fd as backgrounded | |
489 | #define NECP_OPEN_FLAG_PUSH_OBSERVER 0x04 // When used with the OBSERVER flag, allows updates to be pushed. Adding clients is not allowed in this mode. | |
490 | ||
491 | #define NECP_FD_SUPPORTS_GUARD 1 | |
492 | ||
493 | #define NECP_CLIENT_ACTION_ADD 1 // Register a new client. Input: parameters in buffer; Output: client_id | |
494 | #define NECP_CLIENT_ACTION_REMOVE 2 // Unregister a client. Input: client_id, optional struct ifnet_stats_per_flow | |
495 | #define NECP_CLIENT_ACTION_COPY_PARAMETERS 3 // Copy client parameters. Input: client_id; Output: parameters in buffer | |
496 | #define NECP_CLIENT_ACTION_COPY_RESULT 4 // Copy client result. Input: client_id; Output: result in buffer | |
497 | #define NECP_CLIENT_ACTION_COPY_LIST 5 // Copy all client IDs. Output: struct necp_client_list in buffer | |
498 | #define NECP_CLIENT_ACTION_REQUEST_NEXUS_INSTANCE 6 // Request a nexus instance from a nexus provider, optional struct necp_stats_bufreq | |
499 | #define NECP_CLIENT_ACTION_AGENT 7 // Interact with agent. Input: client_id, agent parameters | |
500 | #define NECP_CLIENT_ACTION_COPY_AGENT 8 // Copy agent content. Input: agent UUID; Output: struct netagent | |
501 | #define NECP_CLIENT_ACTION_COPY_INTERFACE 9 // Copy interface details. Input: ifindex cast to UUID; Output: struct necp_interface_details | |
502 | #define NECP_CLIENT_ACTION_SET_STATISTICS 10 // Deprecated | |
503 | #define NECP_CLIENT_ACTION_COPY_ROUTE_STATISTICS 11 // Get route statistics. Input: client_id; Output: struct necp_stat_counts | |
504 | #define NECP_CLIENT_ACTION_AGENT_USE 12 // Return the use count and increment the use count. Input/Output: struct necp_agent_use_parameters | |
505 | #define NECP_CLIENT_ACTION_MAP_SYSCTLS 13 // Get the read-only sysctls memory location. Output: mach_vm_address_t | |
506 | #define NECP_CLIENT_ACTION_UPDATE_CACHE 14 // Update heuristics and cache | |
507 | #define NECP_CLIENT_ACTION_COPY_CLIENT_UPDATE 15 // Fetch an updated client for push-mode observer. Output: Client id, struct necp_client_observer_update in buffer | |
508 | #define NECP_CLIENT_ACTION_COPY_UPDATED_RESULT 16 // Copy client result only if changed. Input: client_id; Output: result in buffer | |
509 | #define NECP_CLIENT_ACTION_ADD_FLOW 17 // Add a flow. Input: client_id; Output: struct necp_client_add_flow | |
510 | #define NECP_CLIENT_ACTION_REMOVE_FLOW 18 // Remove a flow. Input: flow_id, optional struct ifnet_stats_per_flow | |
cb323159 A |
511 | #define NECP_CLIENT_ACTION_CLAIM 19 // Claim a client that has been added for this unique PID. Input: client_id |
512 | #define NECP_CLIENT_ACTION_SIGN 20 // Sign a resolver answer. Input: struct necp_client_resolver_answer; Output: signed tag, expected to be 32 bytes | |
0a7de745 A |
513 | |
514 | #define NECP_CLIENT_PARAMETER_APPLICATION NECP_POLICY_CONDITION_APPLICATION // Requires entitlement | |
515 | #define NECP_CLIENT_PARAMETER_REAL_APPLICATION NECP_POLICY_CONDITION_REAL_APPLICATION // Requires entitlement | |
516 | #define NECP_CLIENT_PARAMETER_DOMAIN NECP_POLICY_CONDITION_DOMAIN | |
517 | #define NECP_CLIENT_PARAMETER_ACCOUNT NECP_POLICY_CONDITION_ACCOUNT | |
518 | #define NECP_CLIENT_PARAMETER_PID NECP_POLICY_CONDITION_PID // Requires entitlement | |
519 | #define NECP_CLIENT_PARAMETER_UID NECP_POLICY_CONDITION_UID // Requires entitlement | |
520 | #define NECP_CLIENT_PARAMETER_BOUND_INTERFACE NECP_POLICY_CONDITION_BOUND_INTERFACE | |
521 | #define NECP_CLIENT_PARAMETER_TRAFFIC_CLASS NECP_POLICY_CONDITION_TRAFFIC_CLASS | |
522 | #define NECP_CLIENT_PARAMETER_IP_PROTOCOL NECP_POLICY_CONDITION_IP_PROTOCOL | |
523 | #define NECP_CLIENT_PARAMETER_LOCAL_ADDRESS NECP_POLICY_CONDITION_LOCAL_ADDR | |
524 | #define NECP_CLIENT_PARAMETER_REMOTE_ADDRESS NECP_POLICY_CONDITION_REMOTE_ADDR | |
525 | #define NECP_CLIENT_PARAMETER_NEXUS_KEY 102 | |
39037602 A |
526 | |
527 | // "Prohibit" will never choose an interface with that property | |
0a7de745 A |
528 | #define NECP_CLIENT_PARAMETER_PROHIBIT_INTERFACE 100 // String, interface name |
529 | #define NECP_CLIENT_PARAMETER_PROHIBIT_IF_TYPE 101 // u_int8_t, see ifru_functional_type in <net/if.h> | |
530 | #define NECP_CLIENT_PARAMETER_PROHIBIT_AGENT 102 // uuid_t, network agent UUID | |
531 | #define NECP_CLIENT_PARAMETER_PROHIBIT_AGENT_TYPE 103 // struct necp_client_parameter_netagent_type | |
39037602 A |
532 | |
533 | // "Require" will choose an interface with that property, or none if not found | |
0a7de745 A |
534 | #define NECP_CLIENT_PARAMETER_REQUIRE_IF_TYPE 111 // u_int8_t, see ifru_functional_type in <net/if.h> |
535 | #define NECP_CLIENT_PARAMETER_REQUIRE_AGENT 112 // uuid_t, network agent UUID | |
536 | #define NECP_CLIENT_PARAMETER_REQUIRE_AGENT_TYPE 113 // struct necp_client_parameter_netagent_type | |
39037602 | 537 | |
d9a64523 | 538 | // "Prefer" will choose an interface with an agent, or best otherwise if not found |
0a7de745 A |
539 | #define NECP_CLIENT_PARAMETER_PREFER_AGENT 122 // uuid_t, network agent UUID |
540 | #define NECP_CLIENT_PARAMETER_PREFER_AGENT_TYPE 123 // struct necp_client_parameter_netagent_type | |
39037602 | 541 | |
d9a64523 | 542 | // "Avoid" will choose an interface without an agent, or best otherwise if unavoidable |
0a7de745 A |
543 | #define NECP_CLIENT_PARAMETER_AVOID_AGENT 124 // uuid_t, network agent UUID |
544 | #define NECP_CLIENT_PARAMETER_AVOID_AGENT_TYPE 125 // struct necp_client_parameter_netagent_type | |
d9a64523 | 545 | |
39037602 | 546 | // Use actions with NECP_CLIENT_ACTION_AGENT |
0a7de745 A |
547 | #define NECP_CLIENT_PARAMETER_TRIGGER_AGENT 130 // uuid_t, network agent UUID |
548 | #define NECP_CLIENT_PARAMETER_ASSERT_AGENT 131 // uuid_t, network agent UUID | |
549 | #define NECP_CLIENT_PARAMETER_UNASSERT_AGENT 132 // uuid_t, network agent UUID | |
550 | ||
cb323159 A |
551 | #define NECP_CLIENT_PARAMETER_PARENT_ID 150 // uuid_t, client UUID |
552 | ||
0a7de745 A |
553 | #define NECP_CLIENT_PARAMETER_LOCAL_ENDPOINT 200 // struct necp_client_endpoint |
554 | #define NECP_CLIENT_PARAMETER_REMOTE_ENDPOINT 201 // struct necp_client_endpoint | |
cb323159 A |
555 | #define NECP_CLIENT_PARAMETER_BROWSE_DESCRIPTOR 202 // struct necp_client_endpoint |
556 | #define NECP_CLIENT_PARAMETER_RESOLVER_TAG 203 // Tag as bytes, expected to be 32 bytes | |
557 | #define NECP_CLIENT_PARAMETER_ADVERTISE_DESCRIPTOR 204 // struct necp_client_endpoint | |
558 | ||
559 | #define NECP_CLIENT_PARAMETER_DELEGATED_UPID 210 // u_int64_t, requires entitlement | |
560 | ||
561 | #define NECP_CLIENT_PARAMETER_ETHERTYPE 220 // u_int16_t, ethertype | |
562 | #define NECP_CLIENT_PARAMETER_TRANSPORT_PROTOCOL 221 // u_int8_t, IPPROTO_ | |
563 | ||
564 | #define NECP_CLIENT_PARAMETER_LOCAL_ADDRESS_PREFERENCE 230 // u_int8_t, NECP_CLIENT_PARAMETER_LOCAL_ADDRESS_PREFERENCE_ | |
565 | ||
566 | #define NECP_CLIENT_PARAMETER_LOCAL_ADDRESS_PREFERENCE_DEFAULT 0 | |
567 | #define NECP_CLIENT_PARAMETER_LOCAL_ADDRESS_PREFERENCE_TEMPORARY 1 | |
568 | #define NECP_CLIENT_PARAMETER_LOCAL_ADDRESS_PREFERENCE_STABLE 2 | |
0a7de745 A |
569 | |
570 | #define NECP_CLIENT_PARAMETER_FLAGS 250 // u_int32_t, see NECP_CLIENT_PAREMETER_FLAG_* values | |
571 | ||
572 | #define NECP_CLIENT_PARAMETER_FLAG_MULTIPATH 0x0001 // Get multipath interface results | |
573 | #define NECP_CLIENT_PARAMETER_FLAG_BROWSE 0x0002 // Agent assertions on nexuses are requests to browse | |
574 | #define NECP_CLIENT_PARAMETER_FLAG_PROHIBIT_EXPENSIVE 0x0004 // Prohibit expensive interfaces | |
575 | #define NECP_CLIENT_PARAMETER_FLAG_LISTENER 0x0008 // Client is interested in listening for inbound connections | |
576 | #define NECP_CLIENT_PARAMETER_FLAG_DISCRETIONARY 0x0010 // Client's traffic is discretionary, and eligible for early defuncting | |
577 | #define NECP_CLIENT_PARAMETER_FLAG_ECN_ENABLE 0x0020 // Client is requesting to enable ECN | |
578 | #define NECP_CLIENT_PARAMETER_FLAG_ECN_DISABLE 0x0040 // Client is requesting to disable ECN | |
579 | #define NECP_CLIENT_PARAMETER_FLAG_TFO_ENABLE 0x0080 // Client is requesting to enable TFO | |
cb323159 A |
580 | #define NECP_CLIENT_PARAMETER_FLAG_ONLY_PRIMARY_REQUIRES_TYPE 0x0100 // Interpret NECP_CLIENT_PARAMETER_REQUIRE_IF_TYPE only for primary interface, and allow exceptions for multipath or listeners |
581 | #define NECP_CLIENT_PARAMETER_FLAG_CUSTOM_ETHER 0x0200 // Client expects to open a custom ethernet channel | |
582 | #define NECP_CLIENT_PARAMETER_FLAG_CUSTOM_IP 0x0400 // Client expects to open a custom IP protocol channel | |
583 | #define NECP_CLIENT_PARAMETER_FLAG_INTERPOSE 0x0800 // Client expects to open an interpose filter channel | |
584 | #define NECP_CLIENT_PARAMETER_FLAG_PROHIBIT_CONSTRAINED 0x1000 // Prohibit constrained interfaces | |
585 | #define NECP_CLIENT_PARAMETER_FLAG_FALLBACK_TRAFFIC 0x2000 // Fallback traffic | |
586 | #define NECP_CLIENT_PARAMETER_FLAG_INBOUND 0x4000 // Flow is inbound (passive) | |
0a7de745 A |
587 | |
588 | #define NECP_CLIENT_RESULT_CLIENT_ID 1 // uuid_t | |
589 | #define NECP_CLIENT_RESULT_POLICY_RESULT 2 // u_int32_t | |
590 | #define NECP_CLIENT_RESULT_POLICY_RESULT_PARAMETER 3 // u_int32_t | |
591 | #define NECP_CLIENT_RESULT_FILTER_CONTROL_UNIT 4 // u_int32_t | |
592 | #define NECP_CLIENT_RESULT_INTERFACE_INDEX 5 // u_int32_t | |
593 | #define NECP_CLIENT_RESULT_NETAGENT 6 // struct necp_client_result_netagent | |
594 | #define NECP_CLIENT_RESULT_FLAGS 7 // u_int32_t, see NECP_CLIENT_RESULT_FLAG_* values | |
595 | #define NECP_CLIENT_RESULT_INTERFACE 8 // struct necp_client_result_interface | |
596 | #define NECP_CLIENT_RESULT_INTERFACE_OPTION 9 // struct necp_client_interface_option | |
597 | #define NECP_CLIENT_RESULT_EFFECTIVE_MTU 10 // u_int32_t | |
598 | #define NECP_CLIENT_RESULT_FLOW 11 // TLV array of a single flow's state | |
599 | #define NECP_CLIENT_RESULT_PROTO_CTL_EVENT 12 | |
600 | #define NECP_CLIENT_RESULT_TFO_COOKIE 13 // NECP_TFO_COOKIE_LEN_MAX | |
601 | #define NECP_CLIENT_RESULT_TFO_FLAGS 14 // u_int8_t | |
602 | #define NECP_CLIENT_RESULT_RECOMMENDED_MSS 15 // u_int8_t | |
603 | #define NECP_CLIENT_RESULT_FLOW_ID 16 // uuid_t | |
604 | #define NECP_CLIENT_RESULT_INTERFACE_TIME_DELTA 17 // u_int32_t, seconds since interface up/down | |
cb323159 | 605 | #define NECP_CLIENT_RESULT_REASON 18 // u_int32_t, see NECP_CLIENT_RESULT_REASON_* values |
0a7de745 A |
606 | |
607 | #define NECP_CLIENT_RESULT_NEXUS_INSTANCE 100 // uuid_t | |
608 | #define NECP_CLIENT_RESULT_NEXUS_PORT 101 // u_int16_t | |
609 | #define NECP_CLIENT_RESULT_NEXUS_KEY 102 // uuid_t | |
610 | #define NECP_CLIENT_RESULT_NEXUS_PORT_FLOW_INDEX 103 // u_int32_t | |
611 | #define NECP_CLIENT_RESULT_NEXUS_FLOW_STATS 104 // struct sk_stats_flow * | |
612 | ||
613 | #define NECP_CLIENT_RESULT_LOCAL_ENDPOINT 200 // struct necp_client_endpoint | |
614 | #define NECP_CLIENT_RESULT_REMOTE_ENDPOINT 201 // struct necp_client_endpoint | |
615 | #define NECP_CLIENT_RESULT_DISCOVERED_ENDPOINT 202 // struct necp_client_endpoint, result of browse | |
cb323159 A |
616 | #define NECP_CLIENT_RESULT_RESOLVED_ENDPOINT 203 // struct necp_client_endpoint, result of resolve |
617 | #define NECP_CLIENT_RESULT_LOCAL_ETHER_ADDR 204 // struct ether_addr | |
618 | #define NECP_CLIENT_RESULT_REMOTE_ETHER_ADDR 205 // struct ether_addr | |
0a7de745 A |
619 | #define NECP_CLIENT_RESULT_EFFECTIVE_TRAFFIC_CLASS 210 // u_int32_t |
620 | #define NECP_CLIENT_RESULT_TRAFFIC_MGMT_BG 211 // u_int32_t, 1: background, 0: not background | |
cb323159 | 621 | #define NECP_CLIENT_RESULT_GATEWAY 212 // struct necp_client_endpoint |
0a7de745 A |
622 | |
623 | #define NECP_CLIENT_RESULT_FLAG_IS_LOCAL 0x0001 // Routes to this device | |
624 | #define NECP_CLIENT_RESULT_FLAG_IS_DIRECT 0x0002 // Routes to directly accessible peer | |
625 | #define NECP_CLIENT_RESULT_FLAG_HAS_IPV4 0x0004 // Supports IPv4 | |
626 | #define NECP_CLIENT_RESULT_FLAG_HAS_IPV6 0x0008 // Supports IPv6 | |
627 | #define NECP_CLIENT_RESULT_FLAG_DEFUNCT 0x0010 // Defunct | |
628 | #define NECP_CLIENT_RESULT_FLAG_SATISFIED 0x0020 // Satisfied path | |
629 | #define NECP_CLIENT_RESULT_FLAG_FLOW_ASSIGNED 0x0040 // Assigned, the flow is active | |
630 | #define NECP_CLIENT_RESULT_FLAG_FLOW_VIABLE 0x0080 // Viable, the flow has a valid route | |
631 | #define NECP_CLIENT_RESULT_FLAG_PROBE_CONNECTIVITY 0x0100 // Flow should probe connectivity | |
632 | #define NECP_CLIENT_RESULT_FLAG_ECN_ENABLED 0x0200 // ECN should be used | |
633 | #define NECP_CLIENT_RESULT_FLAG_FAST_OPEN_BLOCKED 0x0400 // Fast open should not be used | |
634 | #define NECP_CLIENT_RESULT_FLAG_LINK_QUALITY_ABORT 0x0800 // Link quality is very bad, recommend close connections | |
635 | #define NECP_CLIENT_RESULT_FLAG_ALLOW_QOS_MARKING 0x1000 // QoS marking is allowed | |
636 | #define NECP_CLIENT_RESULT_FLAG_HAS_NAT64 0x2000 // Has NAT64 prefix | |
637 | #define NECP_CLIENT_RESULT_FLAG_INTERFACE_LOW_POWER 0x4000 // Interface is in low-power mode | |
cb323159 | 638 | #define NECP_CLIENT_RESULT_FLAG_SPECIFIC_LISTENER 0x8000 // Listener should not listen on all interfaces |
d9a64523 A |
639 | |
640 | #define NECP_CLIENT_RESULT_FLAG_FORCE_UPDATE (NECP_CLIENT_RESULT_FLAG_HAS_IPV4 | NECP_CLIENT_RESULT_FLAG_HAS_IPV6 | NECP_CLIENT_RESULT_FLAG_HAS_NAT64 | NECP_CLIENT_RESULT_FLAG_INTERFACE_LOW_POWER) | |
5ba3f43e | 641 | |
0a7de745 A |
642 | #define NECP_CLIENT_RESULT_FAST_OPEN_SND_PROBE 0x01 // DEPRECATED - Fast open send probe |
643 | #define NECP_CLIENT_RESULT_FAST_OPEN_RCV_PROBE 0x02 // DEPRECATED - Fast open receive probe | |
5ba3f43e | 644 | |
0a7de745 A |
645 | #define NECP_CLIENT_RESULT_RECOMMENDED_MSS_NONE 0x01 |
646 | #define NECP_CLIENT_RESULT_RECOMMENDED_MSS_LOW 0x02 | |
647 | #define NECP_CLIENT_RESULT_RECOMMENDED_MSS_MEDIUM 0x04 | |
5ba3f43e | 648 | |
cb323159 A |
649 | #define NECP_CLIENT_RESULT_REASON_EXPENSIVE_PROHIBITED 1 // Expensive networks were prohibited |
650 | #define NECP_CLIENT_RESULT_REASON_CONSTRAINED_PROHIBITED 2 // Constrained networks were prohibited | |
651 | #define NECP_CLIENT_RESULT_REASON_CELLULAR_DENIED 3 // Denied by a cellular route rule | |
652 | #define NECP_CLIENT_RESULT_REASON_WIFI_DENIED 4 // Denied by a wifi route rule | |
653 | ||
5ba3f43e A |
654 | struct necp_interface_signature { |
655 | u_int8_t signature[IFNET_SIGNATURELEN]; | |
656 | u_int8_t signature_len; | |
657 | }; | |
39037602 A |
658 | |
659 | struct necp_interface_details { | |
660 | char name[IFXNAMSIZ]; | |
661 | u_int32_t index; | |
662 | u_int32_t generation; | |
663 | u_int32_t functional_type; | |
664 | u_int32_t delegate_index; | |
665 | u_int32_t flags; // see NECP_INTERFACE_FLAG_* | |
666 | u_int32_t mtu; | |
5ba3f43e A |
667 | struct necp_interface_signature ipv4_signature; |
668 | struct necp_interface_signature ipv6_signature; | |
cb323159 A |
669 | u_int32_t ipv4_netmask; |
670 | u_int32_t ipv4_broadcast; | |
39037602 A |
671 | }; |
672 | ||
0a7de745 A |
673 | #define NECP_INTERFACE_FLAG_EXPENSIVE 0x0001 |
674 | #define NECP_INTERFACE_FLAG_TXSTART 0X0002 | |
675 | #define NECP_INTERFACE_FLAG_NOACKPRI 0x0004 | |
676 | #define NECP_INTERFACE_FLAG_3CARRIERAGG 0x0008 | |
677 | #define NECP_INTERFACE_FLAG_IS_LOW_POWER 0x0010 | |
cb323159 A |
678 | #define NECP_INTERFACE_FLAG_MPK_LOG 0x0020 // Multi-layer Packet Logging |
679 | #define NECP_INTERFACE_FLAG_CONSTRAINED 0x0040 | |
680 | #define NECP_INTERFACE_FLAG_HAS_NETMASK 0x0080 | |
681 | #define NECP_INTERFACE_FLAG_HAS_BROADCAST 0x0100 | |
39037602 A |
682 | |
683 | struct necp_client_parameter_netagent_type { | |
684 | char netagent_domain[32]; | |
685 | char netagent_type[32]; | |
686 | }; | |
687 | ||
688 | struct necp_client_result_netagent { | |
689 | u_int32_t generation; | |
690 | uuid_t netagent_uuid; | |
691 | }; | |
692 | ||
693 | struct necp_client_result_interface { | |
694 | u_int32_t generation; | |
695 | u_int32_t index; | |
696 | }; | |
697 | ||
ea3f0419 A |
698 | #define NECP_USES_INTERFACE_OPTIONS_FOR_BROWSE 1 |
699 | ||
d9a64523 A |
700 | struct necp_client_interface_option { |
701 | u_int32_t interface_index; | |
702 | u_int32_t interface_generation; | |
703 | uuid_t nexus_agent; | |
704 | }; | |
705 | ||
39037602 A |
706 | struct necp_client_endpoint { |
707 | union { | |
708 | struct sockaddr sa; | |
709 | struct sockaddr_in sin; | |
710 | struct sockaddr_in6 sin6; | |
711 | struct { | |
712 | u_int8_t endpoint_length; | |
713 | u_int8_t endpoint_family; // Use AF_UNSPEC to target a name | |
714 | u_int16_t endpoint_port; | |
715 | u_int32_t endpoint_type; // Client-specific type | |
716 | char endpoint_data[0]; // Type-specific endpoint value | |
717 | } endpoint; | |
718 | } u; | |
719 | }; | |
720 | ||
721 | struct necp_client_list { | |
722 | u_int32_t client_count; | |
723 | uuid_t clients[0]; | |
724 | }; | |
3e170ce0 A |
725 | |
726 | struct kev_necp_policies_changed_data { | |
0a7de745 | 727 | u_int32_t changed_count; // Defaults to 0. |
fe8ab488 A |
728 | }; |
729 | ||
0a7de745 A |
730 | #define NECP_CLIENT_FLOW_FLAGS_ALLOW_NEXUS 0x01 // Request a nexus instance upon adding a flow |
731 | #define NECP_CLIENT_FLOW_FLAGS_USE_CLIENT_ID 0x02 // Register the client ID rather than the flow registration ID with network agents | |
cb323159 A |
732 | #define NECP_CLIENT_FLOW_FLAGS_BROWSE 0x04 // Create request with a browse agent |
733 | #define NECP_CLIENT_FLOW_FLAGS_RESOLVE 0x08 // Create request with a resolution agent | |
d9a64523 A |
734 | |
735 | struct necp_client_flow_stats { | |
736 | u_int32_t stats_type; // NECP_CLIENT_STATISTICS_TYPE_* | |
737 | u_int32_t stats_version; // NECP_CLIENT_STATISTICS_TYPE_*_VER | |
738 | u_int32_t stats_size; | |
739 | mach_vm_address_t stats_addr; | |
740 | }; | |
741 | ||
742 | struct necp_client_add_flow { | |
743 | uuid_t agent_uuid; | |
744 | uuid_t registration_id; | |
745 | u_int16_t flags; // NECP_CLIENT_FLOW_FLAGS_* | |
746 | u_int16_t stats_request_count; | |
747 | struct necp_client_flow_stats stats_requests[0]; | |
748 | } __attribute__((__packed__)); | |
749 | ||
813fb2f6 A |
750 | struct necp_agent_use_parameters { |
751 | uuid_t agent_uuid; | |
752 | uint64_t out_use_count; | |
753 | }; | |
754 | ||
5ba3f43e | 755 | struct necp_client_flow_protoctl_event { |
0a7de745 A |
756 | uint32_t protoctl_event_code; |
757 | uint32_t protoctl_event_val; | |
5ba3f43e | 758 | /* TCP seq number is in host byte order */ |
0a7de745 | 759 | uint32_t protoctl_event_tcp_seq_num; |
5ba3f43e A |
760 | }; |
761 | ||
0a7de745 A |
762 | #define NECP_CLIENT_UPDATE_TYPE_PARAMETERS 1 // Parameters, for a new client |
763 | #define NECP_CLIENT_UPDATE_TYPE_RESULT 2 // Result, for a udpated client | |
764 | #define NECP_CLIENT_UPDATE_TYPE_REMOVE 3 // Empty, for a removed client | |
5ba3f43e A |
765 | |
766 | struct necp_client_observer_update { | |
767 | u_int32_t update_type; // NECP_CLIENT_UPDATE_TYPE_* | |
768 | u_int8_t tlv_buffer[0]; // Parameters or result as TLVs, based on type | |
769 | }; | |
770 | ||
cb323159 A |
771 | #define NECP_CLIENT_SIGN_TYPE_RESOLVER_ANSWER 1 |
772 | ||
773 | struct necp_client_signable { | |
774 | uuid_t client_id; | |
775 | u_int32_t sign_type; | |
776 | } __attribute__((__packed__)); | |
777 | ||
778 | struct necp_client_resolver_answer { | |
779 | uuid_t client_id; | |
780 | u_int32_t sign_type; | |
781 | union sockaddr_in_4_6 address_answer; | |
782 | u_int32_t hostname_length; | |
783 | // hostname | |
784 | } __attribute__((__packed__)); | |
785 | ||
786 | #define NECP_FILTER_UNIT_NO_FILTER UINT32_MAX // Reserved filter unit value that prohibits all filters and socket filters | |
787 | ||
788 | /* | |
789 | * The sysctl "net.necp.necp_drop_dest_level" controls the global drop rule policy for | |
790 | * a set of destinations addresses at the given level -- the drop rule is the last one | |
791 | * to be evaluated at this level. | |
792 | */ | |
793 | #define MAX_NECP_DROP_DEST_LEVEL_ADDRS 8 | |
794 | ||
795 | struct necp_drop_dest_entry { | |
796 | u_int32_t level; // priority level | |
797 | u_int32_t order; // session order (read only via sysctl) | |
798 | struct necp_policy_condition_addr cond_addr; | |
799 | }; | |
800 | ||
801 | struct necp_drop_dest_policy { | |
802 | u_int32_t entry_count; | |
803 | struct necp_drop_dest_entry entries[MAX_NECP_DROP_DEST_LEVEL_ADDRS]; | |
804 | }; | |
805 | ||
fe8ab488 A |
806 | #ifdef BSD_KERNEL_PRIVATE |
807 | #include <stdbool.h> | |
808 | #include <sys/socketvar.h> | |
809 | #include <sys/kern_control.h> | |
810 | #include <netinet/ip_var.h> | |
811 | #include <netinet6/ip6_var.h> | |
39037602 A |
812 | #include <net/if_var.h> |
813 | #include <sys/syslog.h> | |
814 | #include <net/network_agent.h> | |
cb323159 A |
815 | #include <net/ethernet.h> |
816 | ||
39037602 | 817 | |
5ba3f43e A |
818 | SYSCTL_DECL(_net_necp); |
819 | ||
0a7de745 A |
820 | #define NECPLOG(level, format, ...) do { \ |
821 | log((level > LOG_NOTICE ? LOG_NOTICE : level), "%s: " format "\n", __FUNCTION__, __VA_ARGS__); \ | |
39037602 A |
822 | } while (0) |
823 | ||
0a7de745 A |
824 | #define NECPLOG0(level, msg) do { \ |
825 | log((level > LOG_NOTICE ? LOG_NOTICE : level), "%s: %s\n", __FUNCTION__, msg); \ | |
39037602 A |
826 | } while (0) |
827 | ||
5ba3f43e A |
828 | enum necp_fd_type_t { |
829 | necp_fd_type_invalid = 0, | |
830 | necp_fd_type_session = 1, | |
831 | necp_fd_type_client = 2, | |
832 | }; | |
833 | ||
834 | union necp_sockaddr_union { | |
0a7de745 A |
835 | struct sockaddr sa; |
836 | struct sockaddr_in sin; | |
837 | struct sockaddr_in6 sin6; | |
5ba3f43e A |
838 | }; |
839 | ||
840 | /* | |
841 | * kstats | |
842 | * The ustats and kstats region are mirrored. So when we allocate with | |
843 | * skmem_cache from kstats region, we also get an ustats object. To tie them | |
844 | * together, kstats has an extra *necp_stats_ustats pointer pointing to the | |
845 | * ustats object | |
846 | */ | |
847 | struct necp_all_kstats { | |
0a7de745 A |
848 | struct necp_all_stats necp_stats_comm; /* kernel private stats snapshot */ |
849 | struct necp_all_stats *necp_stats_ustats; /* points to user-visible stats (in shared ustats region) */ | |
5ba3f43e A |
850 | }; |
851 | ||
39037602 A |
852 | extern errno_t necp_client_init(void); |
853 | extern int necp_application_find_policy_match_internal(proc_t proc, u_int8_t *parameters, u_int32_t parameters_size, | |
0a7de745 | 854 | struct necp_aggregate_result *returned_result, |
cb323159 | 855 | u_int32_t *flags, u_int32_t *reason, u_int required_interface_index, |
0a7de745 A |
856 | const union necp_sockaddr_union *override_local_addr, |
857 | const union necp_sockaddr_union *override_remote_addr, | |
cb323159 A |
858 | struct necp_client_endpoint *returned_v4_gateway, |
859 | struct necp_client_endpoint *returned_v6_gateway, | |
860 | struct rtentry **returned_route, bool ignore_address, | |
ea3f0419 A |
861 | bool has_client, |
862 | uuid_t *returned_override_euuid); | |
39037602 A |
863 | /* |
864 | * TLV utilities | |
865 | * | |
866 | * Note that these functions (other than necp_buffer_find_tlv) do not check the length of the entire buffer, | |
867 | * so the caller must be sure that the entire TLV is within bounds. | |
868 | */ | |
5ba3f43e A |
869 | struct necp_tlv_header { |
870 | u_int8_t type; | |
871 | u_int32_t length; | |
872 | } __attribute__((__packed__)); | |
873 | ||
874 | extern u_int8_t *necp_buffer_write_tlv(u_int8_t *cursor, u_int8_t type, u_int32_t length, const void *value, | |
0a7de745 | 875 | u_int8_t *buffer, u_int32_t buffer_length); |
5ba3f43e | 876 | extern u_int8_t *necp_buffer_write_tlv_if_different(u_int8_t *cursor, u_int8_t type, |
0a7de745 A |
877 | u_int32_t length, const void *value, bool *updated, |
878 | u_int8_t *buffer, u_int32_t buffer_length); | |
39037602 A |
879 | extern u_int8_t necp_buffer_get_tlv_type(u_int8_t *buffer, int tlv_offset); |
880 | extern u_int32_t necp_buffer_get_tlv_length(u_int8_t *buffer, int tlv_offset); | |
881 | extern u_int8_t *necp_buffer_get_tlv_value(u_int8_t *buffer, int tlv_offset, u_int32_t *value_size); | |
cb323159 | 882 | extern int necp_buffer_find_tlv(u_int8_t *buffer, u_int32_t buffer_length, int offset, u_int8_t type, int *err, int next); |
fe8ab488 | 883 | |
0a7de745 A |
884 | #define NECPCTL_DROP_ALL_LEVEL 1 /* Drop all packets if no policy matches above this level */ |
885 | #define NECPCTL_DEBUG 2 /* Log all kernel policy matches */ | |
886 | #define NECPCTL_PASS_LOOPBACK 3 /* Pass all loopback traffic */ | |
887 | #define NECPCTL_PASS_KEEPALIVES 4 /* Pass all kernel-generated keepalive traffic */ | |
888 | #define NECPCTL_SOCKET_POLICY_COUNT 5 /* Count of all socket-level policies */ | |
889 | #define NECPCTL_SOCKET_NON_APP_POLICY_COUNT 6 /* Count of non-per-app socket-level policies */ | |
890 | #define NECPCTL_IP_POLICY_COUNT 7 /* Count of all ip-level policies */ | |
891 | #define NECPCTL_SESSION_COUNT 8 /* Count of NECP sessions */ | |
892 | #define NECPCTL_CLIENT_FD_COUNT 9 /* Count of NECP client fds */ | |
893 | #define NECPCTL_CLIENT_COUNT 10 /* Count of NECP clients */ | |
894 | #define NECPCTL_ARENA_COUNT 11 /* Count of NECP arenas (stats, etc) */ | |
895 | #define NECPCTL_NEXUS_FLOW_COUNT 12 /* Count of NECP nexus flows */ | |
896 | #define NECPCTL_SOCKET_FLOW_COUNT 13 /* Count of NECP socket flows */ | |
897 | #define NECPCTL_IF_FLOW_COUNT 14 /* Count of NECP socket flows */ | |
898 | #define NECPCTL_OBSERVER_FD_COUNT 15 /* Count of NECP observer fds */ | |
899 | #define NECPCTL_OBSERVER_MESSAGE_LIMIT 16 /* Number of of NECP observer messages allowed to be queued */ | |
900 | #define NECPCTL_SYSCTL_ARENA_COUNT 17 /* Count of sysctl arenas */ | |
cb323159 A |
901 | #define NECPCTL_DROP_UNENTITLED_LEVEL 18 /* Drop unentitled process traffic above this level */ |
902 | #define NECPCTL_PASS_INTERPOSE 19 /* Pass interpose */ | |
0a7de745 A |
903 | |
904 | #define NECPCTL_NAMES { \ | |
905 | { 0, 0 }, \ | |
906 | { "drop_all_level", CTLTYPE_INT }, \ | |
907 | { "debug", CTLTYPE_INT }, \ | |
908 | { "pass_loopback", CTLTYPE_INT }, \ | |
cb323159 A |
909 | { "pass_keepalives", CTLTYPE_INT }, \ |
910 | { "pass_interpose", CTLTYPE_INT }, \ | |
fe8ab488 A |
911 | } |
912 | ||
913 | typedef u_int32_t necp_kernel_policy_id; | |
0a7de745 A |
914 | #define NECP_KERNEL_POLICY_ID_NONE 0 |
915 | #define NECP_KERNEL_POLICY_ID_NO_MATCH 1 | |
916 | #define NECP_KERNEL_POLICY_ID_FIRST_VALID_SOCKET 2 | |
917 | #define NECP_KERNEL_POLICY_ID_FIRST_VALID_IP UINT16_MAX | |
fe8ab488 A |
918 | |
919 | typedef u_int32_t necp_app_id; | |
920 | ||
0a7de745 A |
921 | #define NECP_KERNEL_POLICY_RESULT_NONE 0 |
922 | #define NECP_KERNEL_POLICY_RESULT_PASS NECP_POLICY_RESULT_PASS | |
923 | #define NECP_KERNEL_POLICY_RESULT_SKIP NECP_POLICY_RESULT_SKIP | |
924 | #define NECP_KERNEL_POLICY_RESULT_DROP NECP_POLICY_RESULT_DROP | |
925 | #define NECP_KERNEL_POLICY_RESULT_SOCKET_DIVERT NECP_POLICY_RESULT_SOCKET_DIVERT | |
926 | #define NECP_KERNEL_POLICY_RESULT_SOCKET_FILTER NECP_POLICY_RESULT_SOCKET_FILTER | |
927 | #define NECP_KERNEL_POLICY_RESULT_IP_TUNNEL NECP_POLICY_RESULT_IP_TUNNEL | |
928 | #define NECP_KERNEL_POLICY_RESULT_IP_FILTER NECP_POLICY_RESULT_IP_FILTER | |
929 | #define NECP_KERNEL_POLICY_RESULT_TRIGGER NECP_POLICY_RESULT_TRIGGER | |
930 | #define NECP_KERNEL_POLICY_RESULT_TRIGGER_IF_NEEDED NECP_POLICY_RESULT_TRIGGER_IF_NEEDED | |
931 | #define NECP_KERNEL_POLICY_RESULT_TRIGGER_SCOPED NECP_POLICY_RESULT_TRIGGER_SCOPED | |
932 | #define NECP_KERNEL_POLICY_RESULT_NO_TRIGGER_SCOPED NECP_POLICY_RESULT_NO_TRIGGER_SCOPED | |
933 | #define NECP_KERNEL_POLICY_RESULT_SOCKET_SCOPED NECP_POLICY_RESULT_SOCKET_SCOPED | |
934 | #define NECP_KERNEL_POLICY_RESULT_ROUTE_RULES NECP_POLICY_RESULT_ROUTE_RULES | |
935 | #define NECP_KERNEL_POLICY_RESULT_USE_NETAGENT NECP_POLICY_RESULT_USE_NETAGENT | |
936 | #define NECP_KERNEL_POLICY_RESULT_NETAGENT_SCOPED NECP_POLICY_RESULT_NETAGENT_SCOPED | |
937 | #define NECP_KERNEL_POLICY_RESULT_SCOPED_DIRECT NECP_POLICY_RESULT_SCOPED_DIRECT | |
ea3f0419 A |
938 | #define NECP_KERNEL_POLICY_RESULT_ALLOW_UNENTITLED NECP_POLICY_RESULT_ALLOW_UNENTITLED |
939 | ||
940 | #define NECP_KERNEL_POLICY_PASS_NO_SKIP_IPSEC NECP_POLICY_PASS_NO_SKIP_IPSEC | |
fe8ab488 A |
941 | |
942 | typedef struct { | |
943 | u_int32_t identifier; | |
944 | u_int32_t data; | |
945 | } necp_kernel_policy_service; | |
946 | ||
947 | typedef union { | |
0a7de745 A |
948 | u_int tunnel_interface_index; |
949 | u_int scoped_interface_index; | |
950 | u_int32_t flow_divert_control_unit; | |
951 | u_int32_t filter_control_unit; | |
952 | u_int32_t skip_policy_order; | |
953 | u_int32_t route_rule_id; | |
954 | u_int32_t netagent_id; | |
ea3f0419 | 955 | u_int32_t pass_flags; |
0a7de745 | 956 | necp_kernel_policy_service service; |
fe8ab488 A |
957 | } necp_kernel_policy_result_parameter; |
958 | ||
813fb2f6 A |
959 | enum necp_boolean_state { |
960 | necp_boolean_state_unknown = 0, | |
961 | necp_boolean_state_false = 1, | |
962 | necp_boolean_state_true = 2, | |
963 | }; | |
964 | ||
fe8ab488 | 965 | struct necp_kernel_socket_policy { |
0a7de745 A |
966 | LIST_ENTRY(necp_kernel_socket_policy) chain; |
967 | necp_kernel_policy_id id; | |
968 | necp_policy_order order; | |
969 | u_int32_t session_order; | |
970 | int session_pid; | |
971 | ||
972 | u_int32_t condition_mask; | |
973 | u_int32_t condition_negated_mask; | |
cb323159 | 974 | u_int32_t cond_client_flags; |
0a7de745 A |
975 | necp_kernel_policy_id cond_policy_id; |
976 | u_int32_t cond_app_id; // Locally assigned ID value stored | |
977 | u_int32_t cond_real_app_id; // Locally assigned ID value stored | |
978 | char *cond_custom_entitlement; // String | |
979 | u_int8_t cond_custom_entitlement_matched;// Boolean if entitlement matched app | |
980 | u_int32_t cond_account_id; // Locally assigned ID value stored | |
981 | char *cond_domain; // String | |
982 | u_int8_t cond_domain_dot_count; // Number of dots in cond_domain | |
983 | pid_t cond_pid; | |
984 | uid_t cond_uid; | |
985 | ifnet_t cond_bound_interface; // Matches specific binding only | |
986 | struct necp_policy_condition_tc_range cond_traffic_class; // Matches traffic class in range | |
987 | u_int16_t cond_protocol; // Matches IP protcol number | |
988 | union necp_sockaddr_union cond_local_start; // Matches local IP address (or start) | |
989 | union necp_sockaddr_union cond_local_end; // Matches IP address range | |
990 | u_int8_t cond_local_prefix; // Defines subnet | |
991 | union necp_sockaddr_union cond_remote_start; // Matches remote IP address (or start) | |
992 | union necp_sockaddr_union cond_remote_end; // Matches IP address range | |
993 | u_int8_t cond_remote_prefix; // Defines subnet | |
d9a64523 | 994 | struct necp_policy_condition_agent_type cond_agent_type; |
eb6b6ca3 | 995 | char *cond_signing_identifier; // String |
3e170ce0 | 996 | |
0a7de745 A |
997 | necp_kernel_policy_result result; |
998 | necp_kernel_policy_result_parameter result_parameter; | |
fe8ab488 A |
999 | }; |
1000 | ||
1001 | struct necp_kernel_ip_output_policy { | |
0a7de745 A |
1002 | LIST_ENTRY(necp_kernel_ip_output_policy) chain; |
1003 | necp_kernel_policy_id id; | |
1004 | necp_policy_order suborder; | |
1005 | necp_policy_order order; | |
1006 | u_int32_t session_order; | |
1007 | int session_pid; | |
1008 | ||
1009 | u_int32_t condition_mask; | |
1010 | u_int32_t condition_negated_mask; | |
1011 | necp_kernel_policy_id cond_policy_id; | |
1012 | ifnet_t cond_bound_interface; // Matches specific binding only | |
1013 | u_int16_t cond_protocol; // Matches IP protcol number | |
1014 | union necp_sockaddr_union cond_local_start; // Matches local IP address (or start) | |
1015 | union necp_sockaddr_union cond_local_end; // Matches IP address range | |
1016 | u_int8_t cond_local_prefix; // Defines subnet | |
1017 | union necp_sockaddr_union cond_remote_start; // Matches remote IP address (or start) | |
1018 | union necp_sockaddr_union cond_remote_end; // Matches IP address range | |
1019 | u_int8_t cond_remote_prefix; // Defines subnet | |
1020 | u_int32_t cond_last_interface_index; | |
1021 | ||
1022 | necp_kernel_policy_result result; | |
1023 | necp_kernel_policy_result_parameter result_parameter; | |
fe8ab488 A |
1024 | }; |
1025 | ||
0a7de745 A |
1026 | #define MAX_KERNEL_SOCKET_POLICIES 1 |
1027 | #define MAX_KERNEL_IP_OUTPUT_POLICIES 4 | |
fe8ab488 A |
1028 | struct necp_session_policy { |
1029 | LIST_ENTRY(necp_session_policy) chain; | |
0a7de745 A |
1030 | bool applied; // Applied into the kernel table |
1031 | bool pending_deletion; // Waiting to be removed from kernel table | |
1032 | bool pending_update; // Policy has been modified since creation/last application | |
1033 | necp_policy_id local_id; | |
1034 | necp_policy_order order; | |
1035 | u_int8_t *result; | |
1036 | u_int32_t result_size; | |
1037 | u_int8_t *conditions; // Array of conditions, each with a u_int32_t length at start | |
1038 | u_int32_t conditions_size; | |
1039 | u_int8_t *route_rules; // Array of route rules, each with a u_int32_t length at start | |
1040 | u_int32_t route_rules_size; | |
1041 | ||
1042 | uuid_t applied_app_uuid; | |
1043 | uuid_t applied_real_app_uuid; | |
1044 | char *applied_account; | |
1045 | ||
1046 | uuid_t applied_result_uuid; | |
1047 | ||
1048 | u_int32_t applied_route_rules_id; | |
1049 | ||
1050 | necp_kernel_policy_id kernel_socket_policies[MAX_KERNEL_SOCKET_POLICIES]; | |
1051 | necp_kernel_policy_id kernel_ip_output_policies[MAX_KERNEL_IP_OUTPUT_POLICIES]; | |
fe8ab488 A |
1052 | }; |
1053 | ||
1054 | struct necp_aggregate_socket_result { | |
0a7de745 A |
1055 | necp_kernel_policy_result result; |
1056 | necp_kernel_policy_result_parameter result_parameter; | |
1057 | necp_kernel_policy_filter filter_control_unit; | |
1058 | u_int32_t route_rule_id; | |
1059 | int32_t qos_marking_gencount; | |
fe8ab488 A |
1060 | }; |
1061 | ||
1062 | struct necp_inpcb_result { | |
0a7de745 A |
1063 | u_int32_t app_id; |
1064 | necp_kernel_policy_id policy_id; | |
1065 | necp_kernel_policy_id skip_policy_id; | |
1066 | int32_t policy_gencount; | |
1067 | u_int32_t flowhash; | |
1068 | struct necp_aggregate_socket_result results; | |
fe8ab488 A |
1069 | }; |
1070 | ||
39037602 A |
1071 | extern errno_t necp_init(void); |
1072 | ||
1073 | extern errno_t necp_set_socket_attributes(struct socket *so, struct sockopt *sopt); | |
1074 | extern errno_t necp_get_socket_attributes(struct socket *so, struct sockopt *sopt); | |
5ba3f43e | 1075 | extern void necp_inpcb_remove_cb(struct inpcb *inp); |
39037602 A |
1076 | extern void necp_inpcb_dispose(struct inpcb *inp); |
1077 | ||
1078 | extern u_int32_t necp_socket_get_content_filter_control_unit(struct socket *so); | |
fe8ab488 | 1079 | |
39037602 A |
1080 | extern bool necp_socket_should_use_flow_divert(struct inpcb *inp); |
1081 | extern u_int32_t necp_socket_get_flow_divert_control_unit(struct inpcb *inp); | |
fe8ab488 | 1082 | |
39037602 A |
1083 | extern bool necp_socket_should_rescope(struct inpcb *inp); |
1084 | extern u_int necp_socket_get_rescope_if_index(struct inpcb *inp); | |
1085 | extern u_int32_t necp_socket_get_effective_mtu(struct inpcb *inp, u_int32_t current_mtu); | |
fe8ab488 | 1086 | |
cb323159 A |
1087 | extern bool necp_socket_is_allowed_to_recv_on_interface(struct inpcb *inp, ifnet_t interface); |
1088 | ||
1089 | extern bool necp_socket_is_allowed_to_send_recv(struct inpcb *inp, ifnet_t interface, | |
1090 | necp_kernel_policy_id *return_policy_id, | |
0a7de745 A |
1091 | u_int32_t *return_route_rule_id, |
1092 | necp_kernel_policy_id *return_skip_policy_id); | |
39037602 | 1093 | extern bool necp_socket_is_allowed_to_send_recv_v4(struct inpcb *inp, u_int16_t local_port, |
0a7de745 A |
1094 | u_int16_t remote_port, struct in_addr *local_addr, |
1095 | struct in_addr *remote_addr, ifnet_t interface, | |
1096 | necp_kernel_policy_id *return_policy_id, u_int32_t *return_route_rule_id, | |
1097 | necp_kernel_policy_id *return_skip_policy_id); | |
39037602 | 1098 | extern bool necp_socket_is_allowed_to_send_recv_v6(struct inpcb *inp, u_int16_t local_port, |
0a7de745 A |
1099 | u_int16_t remote_port, struct in6_addr *local_addr, |
1100 | struct in6_addr *remote_addr, ifnet_t interface, | |
1101 | necp_kernel_policy_id *return_policy_id, u_int32_t *return_route_rule_id, | |
1102 | necp_kernel_policy_id *return_skip_policy_id); | |
39037602 A |
1103 | extern void necp_socket_update_qos_marking(struct inpcb *inp, struct rtentry *route, struct ifnet *interface, u_int32_t route_rule_id); |
1104 | extern int necp_mark_packet_from_socket(struct mbuf *packet, struct inpcb *inp, necp_kernel_policy_id policy_id, | |
0a7de745 | 1105 | u_int32_t route_rule_id, necp_kernel_policy_id skip_policy_id); |
39037602 | 1106 | extern necp_kernel_policy_id necp_get_policy_id_from_packet(struct mbuf *packet); |
d9a64523 | 1107 | extern necp_kernel_policy_id necp_get_skip_policy_id_from_packet(struct mbuf *packet); |
cb323159 | 1108 | extern bool necp_packet_should_skip_filters(struct mbuf *packet); |
39037602 A |
1109 | extern u_int32_t necp_get_last_interface_index_from_packet(struct mbuf *packet); |
1110 | extern u_int32_t necp_get_route_rule_id_from_packet(struct mbuf *packet); | |
1111 | extern int necp_get_app_uuid_from_packet(struct mbuf *packet, | |
0a7de745 | 1112 | uuid_t app_uuid); |
fe8ab488 | 1113 | |
39037602 | 1114 | extern necp_kernel_policy_id necp_socket_find_policy_match(struct inpcb *inp, struct sockaddr *override_local_addr, |
0a7de745 | 1115 | struct sockaddr *override_remote_addr, u_int32_t override_bound_interface); |
39037602 | 1116 | extern necp_kernel_policy_id necp_ip_output_find_policy_match(struct mbuf *packet, int flags, struct ip_out_args *ipoa, |
cb323159 | 1117 | struct rtentry *rt, |
0a7de745 A |
1118 | necp_kernel_policy_result *result, |
1119 | necp_kernel_policy_result_parameter *result_parameter); | |
39037602 | 1120 | extern necp_kernel_policy_id necp_ip6_output_find_policy_match(struct mbuf *packet, int flags, struct ip6_out_args *ip6oa, |
cb323159 | 1121 | struct rtentry *rt, |
0a7de745 A |
1122 | necp_kernel_policy_result *result, |
1123 | necp_kernel_policy_result_parameter *result_parameter); | |
fe8ab488 | 1124 | |
39037602 A |
1125 | extern int necp_mark_packet_from_ip(struct mbuf *packet, necp_kernel_policy_id policy_id); |
1126 | extern int necp_mark_packet_from_interface(struct mbuf *packet, ifnet_t interface); | |
fe8ab488 | 1127 | |
39037602 A |
1128 | extern ifnet_t necp_get_ifnet_from_result_parameter(necp_kernel_policy_result_parameter *result_parameter); |
1129 | extern bool necp_packet_can_rebind_to_ifnet(struct mbuf *packet, struct ifnet *interface, struct route *new_route, int family); | |
fe8ab488 | 1130 | |
39037602 | 1131 | extern bool necp_packet_is_allowed_over_interface(struct mbuf *packet, struct ifnet *interface); |
fe8ab488 | 1132 | |
39037602 A |
1133 | extern int necp_mark_packet_as_keepalive(struct mbuf *packet, bool is_keepalive); |
1134 | extern bool necp_get_is_keepalive_from_packet(struct mbuf *packet); | |
fe8ab488 | 1135 | |
cb323159 A |
1136 | extern int necp_sign_resolver_answer(uuid_t client_id, u_int8_t *query, u_int32_t query_length, |
1137 | u_int8_t *answer, u_int32_t answer_length, | |
1138 | u_int8_t *tag, u_int32_t *out_tag_length); | |
1139 | ||
1140 | extern bool necp_validate_resolver_answer(uuid_t client_id, u_int8_t *query, u_int32_t query_length, | |
1141 | u_int8_t *answer, u_int32_t answer_length, | |
1142 | u_int8_t *tag, u_int32_t tag_length); | |
1143 | ||
39037602 | 1144 | extern void necp_update_all_clients(void); // Handle general re-evaluate event |
cb323159 | 1145 | extern void necp_update_all_clients_immediately_if_needed(bool should_update_immediately); // Handle general re-evaluate event |
3e170ce0 | 1146 | |
d9a64523 | 1147 | extern void necp_force_update_client(uuid_t client_id, uuid_t remove_netagent_uuid, u_int32_t agent_generation); // Cause a single client to get an update event |
5ba3f43e | 1148 | |
cb323159 | 1149 | extern bool necp_set_client_as_background(proc_t proc, struct fileproc *fp, bool background); // Set all clients for an fp as background or not |
5ba3f43e | 1150 | |
a39ff7e2 A |
1151 | struct necp_fd_data; |
1152 | extern void necp_fd_memstatus(proc_t proc, uint32_t status, struct necp_fd_data *client_fd); // Purge memory of clients for the process | |
1153 | extern void necp_fd_defunct(proc_t proc, struct necp_fd_data *client_fd); // Set all clients for an process as defunct | |
5ba3f43e A |
1154 | |
1155 | extern int necp_client_register_socket_flow(pid_t pid, uuid_t client_id, struct inpcb *inp); | |
1156 | ||
cb323159 A |
1157 | extern int necp_client_register_socket_listener(pid_t pid, uuid_t client_id, struct inpcb *inp); |
1158 | ||
1159 | ||
d9a64523 | 1160 | extern int necp_client_assert_bb_radio_manager(uuid_t client_id, bool assert); |
5ba3f43e A |
1161 | |
1162 | extern int necp_client_assign_from_socket(pid_t pid, uuid_t client_id, struct inpcb *inp); | |
1163 | ||
39037602 | 1164 | extern int necp_assign_client_result(uuid_t netagent_uuid, uuid_t client_id, |
0a7de745 A |
1165 | u_int8_t *assigned_results, size_t assigned_results_length); |
1166 | struct skmem_obj_info; // forward declaration | |
5ba3f43e A |
1167 | extern int necp_stats_ctor(struct skmem_obj_info *oi, struct skmem_obj_info *oim, void *arg, uint32_t skmflag); |
1168 | extern int necp_stats_dtor(void *addr, void *arg); | |
1169 | ||
1170 | /* value to denote invalid flow advisory index */ | |
1171 | struct netagent_session; | |
1172 | extern int | |
1173 | necp_update_flow_protoctl_event(uuid_t netagent_uuid, uuid_t client_id, | |
1174 | uint32_t protoctl_event_code, uint32_t protoctl_event_val, | |
1175 | uint32_t protoctl_event_tcp_seq_num); | |
1176 | ||
0a7de745 | 1177 | #define NECP_FLOWADV_IDX_INVALID UINT32_MAX |
5ba3f43e | 1178 | extern void *necp_create_nexus_assign_message(uuid_t nexus_instance, u_int32_t nexus_port, void *key, uint32_t key_length, |
0a7de745 | 1179 | struct necp_client_endpoint *local_endpoint, struct necp_client_endpoint *remote_endpoint, |
cb323159 | 1180 | struct ether_addr *local_ether_addr, |
0a7de745 | 1181 | u_int32_t flow_adv_index, void *flow_stats, size_t *message_length); |
5ba3f43e A |
1182 | |
1183 | struct necp_client_nexus_parameters { | |
1184 | pid_t pid; | |
1185 | pid_t epid; | |
1186 | uuid_t euuid; | |
1187 | union necp_sockaddr_union local_addr; | |
1188 | union necp_sockaddr_union remote_addr; | |
cb323159 A |
1189 | u_int8_t ip_protocol; |
1190 | u_int8_t transport_protocol; | |
1191 | u_int16_t ethertype; | |
5ba3f43e A |
1192 | u_int32_t traffic_class; |
1193 | necp_policy_id policy_id; | |
1194 | unsigned is_listener:1; | |
cb323159 A |
1195 | unsigned is_interpose:1; |
1196 | unsigned is_custom_ether:1; | |
5ba3f43e | 1197 | unsigned allow_qos_marking:1; |
cb323159 A |
1198 | unsigned override_address_selection:1; |
1199 | unsigned use_stable_address:1; // Used if override_address_selection is set | |
1200 | }; | |
1201 | ||
1202 | struct necp_client_agent_parameters { | |
1203 | union { | |
1204 | struct necp_client_nexus_parameters nexus_request; | |
1205 | u_int8_t close_token[QUIC_STATELESS_RESET_TOKEN_SIZE]; | |
1206 | } u; | |
5ba3f43e | 1207 | }; |
fe8ab488 | 1208 | |
0a7de745 A |
1209 | #define NECP_CLIENT_CBACTION_NONVIABLE 1 |
1210 | #define NECP_CLIENT_CBACTION_VIABLE 2 | |
1211 | #define NECP_CLIENT_CBACTION_INITIAL 3 | |
5ba3f43e | 1212 | |
d9a64523 A |
1213 | struct necp_client_add_flow_default { |
1214 | uuid_t agent_uuid; | |
1215 | uuid_t registration_id; | |
1216 | u_int16_t flags; // NECP_CLIENT_FLOW_FLAGS_* | |
1217 | u_int16_t stats_request_count; | |
1218 | struct necp_client_flow_stats stats_requests[1]; | |
1219 | } __attribute__((__packed__)); | |
5ba3f43e | 1220 | |
d9a64523 | 1221 | typedef void (*necp_client_flow_cb)(void *handle, int action, uint32_t interface_index, uint32_t necp_flags, bool *viable); |
a39ff7e2 | 1222 | |
d9a64523 | 1223 | extern void necp_client_reap_caches(boolean_t purge); |
a39ff7e2 A |
1224 | |
1225 | ||
fe8ab488 | 1226 | #endif /* BSD_KERNEL_PRIVATE */ |
cb323159 A |
1227 | |
1228 | #ifdef KERNEL | |
1229 | #ifdef KERNEL_PRIVATE | |
1230 | extern bool net_domain_contains_hostname(char *hostname_string, char *domain_string); | |
1231 | #endif /* KERNEL_PRIVATE */ | |
1232 | #endif /* KERNEL */ | |
1233 | ||
fe8ab488 | 1234 | #ifndef KERNEL |
39037602 A |
1235 | |
1236 | extern int necp_match_policy(const uint8_t *parameters, size_t parameters_size, struct necp_aggregate_result *returned_result); | |
1237 | ||
1238 | extern int necp_open(int flags); | |
1239 | ||
1240 | extern int necp_client_action(int necp_fd, uint32_t action, uuid_t client_id, | |
0a7de745 | 1241 | size_t client_id_len, uint8_t *buffer, size_t buffer_size); |
39037602 | 1242 | |
5ba3f43e A |
1243 | extern int necp_session_open(int flags); |
1244 | ||
1245 | extern int necp_session_action(int necp_fd, uint32_t action, | |
0a7de745 A |
1246 | uint8_t *in_buffer, size_t in_buffer_length, |
1247 | uint8_t *out_buffer, size_t out_buffer_length); | |
5ba3f43e | 1248 | |
fe8ab488 A |
1249 | #endif /* !KERNEL */ |
1250 | ||
39037602 A |
1251 | #endif /* PRIVATE */ |
1252 | ||
fe8ab488 | 1253 | #endif |