]>
Commit | Line | Data |
---|---|---|
3e170ce0 | 1 | /* |
5ba3f43e | 2 | * Copyright (c) 2014-2017 Apple Inc. All rights reserved. |
3e170ce0 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 | ||
29 | #ifndef _NETAGENT_H_ | |
30 | #define _NETAGENT_H_ | |
39037602 A |
31 | #include <net/net_kev.h> |
32 | ||
33 | #ifdef PRIVATE | |
3e170ce0 A |
34 | |
35 | #include <netinet/in.h> | |
36 | #include <sys/socket.h> | |
37 | ||
38 | #ifdef BSD_KERNEL_PRIVATE | |
39 | #include <stdbool.h> | |
40 | ||
41 | errno_t netagent_init(void); | |
42 | #endif | |
3e170ce0 A |
43 | /* |
44 | * Name registered by the Network Agent kernel control | |
45 | */ | |
46 | #define NETAGENT_CONTROL_NAME "com.apple.net.netagent" | |
47 | ||
48 | struct netagent_message_header { | |
49 | u_int8_t message_type; | |
50 | u_int8_t message_flags; | |
51 | u_int32_t message_id; | |
52 | u_int32_t message_error; | |
53 | u_int32_t message_payload_length; | |
54 | }; | |
55 | ||
56 | struct netagent_trigger_message { | |
57 | u_int32_t trigger_flags; | |
58 | pid_t trigger_pid; | |
59 | uuid_t trigger_proc_uuid; | |
60 | }; | |
61 | ||
39037602 A |
62 | struct netagent_client_message { |
63 | uuid_t client_id; | |
64 | }; | |
65 | ||
66 | struct netagent_assign_nexus_message { | |
67 | uuid_t assign_client_id; | |
68 | u_int8_t assign_necp_results[0]; | |
69 | }; | |
70 | ||
3e170ce0 A |
71 | #define NETAGENT_MESSAGE_TYPE_REGISTER 1 // Pass netagent to set, no return value |
72 | #define NETAGENT_MESSAGE_TYPE_UNREGISTER 2 // No value, no return value | |
73 | #define NETAGENT_MESSAGE_TYPE_UPDATE 3 // Pass netagent to update, no return value | |
39037602 | 74 | #define NETAGENT_MESSAGE_TYPE_GET 4 // No value, return netagent |
3e170ce0 | 75 | #define NETAGENT_MESSAGE_TYPE_TRIGGER 5 // Kernel initiated, no reply expected |
39037602 A |
76 | #define NETAGENT_MESSAGE_TYPE_ASSERT 6 // Deprecated |
77 | #define NETAGENT_MESSAGE_TYPE_UNASSERT 7 // Deprecated | |
3e170ce0 A |
78 | #define NETAGENT_MESSAGE_TYPE_TRIGGER_ASSERT 8 // Kernel initiated, no reply expected |
79 | #define NETAGENT_MESSAGE_TYPE_TRIGGER_UNASSERT 9 // Kernel initiated, no reply expected | |
39037602 A |
80 | #define NETAGENT_MESSAGE_TYPE_REQUEST_NEXUS 10 // Kernel initiated, struct netagent_client_message |
81 | #define NETAGENT_MESSAGE_TYPE_ASSIGN_NEXUS 11 // Pass struct netagent_assign_nexus_message | |
82 | #define NETAGENT_MESSAGE_TYPE_CLOSE_NEXUS 12 // Kernel initiated, struct netagent_client_message | |
83 | #define NETAGENT_MESSAGE_TYPE_CLIENT_TRIGGER 13 // Kernel initiated, struct netagent_client_message | |
84 | #define NETAGENT_MESSAGE_TYPE_CLIENT_ASSERT 14 // Kernel initiated, struct netagent_client_message | |
85 | #define NETAGENT_MESSAGE_TYPE_CLIENT_UNASSERT 15 // Kernel initiated, struct netagent_client_message | |
86 | ||
87 | #define NETAGENT_OPTION_TYPE_REGISTER NETAGENT_MESSAGE_TYPE_REGISTER // Pass netagent to set, no return value | |
88 | #define NETAGENT_OPTION_TYPE_UNREGISTER NETAGENT_MESSAGE_TYPE_UNREGISTER // No value, no return value | |
89 | #define NETAGENT_OPTION_TYPE_UPDATE NETAGENT_MESSAGE_TYPE_UPDATE // Pass netagent to update, no return value | |
90 | #define NETAGENT_OPTION_TYPE_ASSIGN_NEXUS NETAGENT_MESSAGE_TYPE_ASSIGN_NEXUS // Pass struct netagent_assign_nexus_message | |
813fb2f6 | 91 | #define NETAGENT_OPTION_TYPE_USE_COUNT 16 // Pass use count to set, get current use count |
5ba3f43e | 92 | #define NETAGENT_MESSAGE_TYPE_ABORT_NEXUS 17 // Kernel private |
3e170ce0 A |
93 | |
94 | #define NETAGENT_MESSAGE_FLAGS_RESPONSE 0x01 // Used for acks, errors, and query responses | |
95 | ||
96 | #define NETAGENT_MESSAGE_ERROR_NONE 0 | |
97 | #define NETAGENT_MESSAGE_ERROR_INTERNAL 1 | |
98 | #define NETAGENT_MESSAGE_ERROR_UNKNOWN_TYPE 2 | |
99 | #define NETAGENT_MESSAGE_ERROR_INVALID_DATA 3 | |
100 | #define NETAGENT_MESSAGE_ERROR_NOT_REGISTERED 4 | |
101 | #define NETAGENT_MESSAGE_ERROR_ALREADY_REGISTERED 5 | |
102 | #define NETAGENT_MESSAGE_ERROR_CANNOT_UPDATE 6 | |
39037602 | 103 | #define NETAGENT_MESSAGE_ERROR_CANNOT_ASSIGN 7 |
3e170ce0 A |
104 | |
105 | #define NETAGENT_DOMAINSIZE 32 | |
106 | #define NETAGENT_TYPESIZE 32 | |
107 | #define NETAGENT_DESCSIZE 128 | |
108 | ||
39037602 | 109 | #define NETAGENT_MAX_DATA_SIZE 4096 |
3e170ce0 A |
110 | |
111 | #define NETAGENT_FLAG_REGISTERED 0x0001 // Agent is registered | |
112 | #define NETAGENT_FLAG_ACTIVE 0x0002 // Agent is active | |
113 | #define NETAGENT_FLAG_KERNEL_ACTIVATED 0x0004 // Agent can be activated by kernel activity | |
114 | #define NETAGENT_FLAG_USER_ACTIVATED 0x0008 // Agent can be activated by system call (netagent_trigger) | |
115 | #define NETAGENT_FLAG_VOLUNTARY 0x0010 // Use of agent is optional | |
116 | #define NETAGENT_FLAG_SPECIFIC_USE_ONLY 0x0020 // Agent should only be used and activated when specifically required | |
39037602 A |
117 | #define NETAGENT_FLAG_NETWORK_PROVIDER 0x0040 // Agent provides network access |
118 | #define NETAGENT_FLAG_NEXUS_PROVIDER 0x0080 // Agent provides a skywalk nexus | |
5ba3f43e | 119 | #define NETAGENT_FLAG_SUPPORTS_BROWSE 0x0100 // Assertions will cause agent to fill in browse endpoints |
39037602 A |
120 | |
121 | #define NETAGENT_NEXUS_MAX_REQUEST_TYPES 16 | |
122 | #define NETAGENT_NEXUS_MAX_RESOLUTION_TYPE_PAIRS 16 | |
123 | ||
124 | #define NETAGENT_NEXUS_FRAME_TYPE_UNKNOWN 0 | |
125 | #define NETAGENT_NEXUS_FRAME_TYPE_LINK 1 | |
126 | #define NETAGENT_NEXUS_FRAME_TYPE_INTERNET 2 | |
127 | #define NETAGENT_NEXUS_FRAME_TYPE_TRANSPORT 3 | |
128 | #define NETAGENT_NEXUS_FRAME_TYPE_APPLICATION 4 | |
129 | ||
5ba3f43e A |
130 | #define NETAGENT_NEXUS_ENDPOINT_TYPE_ADDRESS 1 |
131 | #define NETAGENT_NEXUS_ENDPOINT_TYPE_HOST 2 | |
132 | #define NETAGENT_NEXUS_ENDPOINT_TYPE_BONJOUR 3 | |
133 | ||
134 | #define NETAGENT_NEXUS_FLAG_SUPPORTS_USER_PACKET_POOL 0x1 | |
135 | #define NETAGENT_NEXUS_FLAG_ASSERT_UNSUPPORTED 0x2 // No calls to assert the agent are required | |
136 | ||
39037602 A |
137 | struct netagent_nexus { |
138 | u_int32_t frame_type; | |
139 | u_int32_t endpoint_assignment_type; | |
140 | u_int32_t endpoint_request_types[NETAGENT_NEXUS_MAX_REQUEST_TYPES]; | |
141 | u_int32_t endpoint_resolution_type_pairs[NETAGENT_NEXUS_MAX_RESOLUTION_TYPE_PAIRS * 2]; | |
5ba3f43e | 142 | u_int32_t nexus_flags; |
39037602 | 143 | }; |
3e170ce0 A |
144 | |
145 | #define NETAGENT_TRIGGER_FLAG_USER 0x0001 // Userspace triggered agent | |
146 | #define NETAGENT_TRIGGER_FLAG_KERNEL 0x0002 // Kernel triggered agent | |
147 | ||
3e170ce0 A |
148 | struct kev_netagent_data { |
149 | uuid_t netagent_uuid; | |
150 | }; | |
151 | ||
152 | // To be used with kernel control socket | |
153 | struct netagent { | |
154 | uuid_t netagent_uuid; | |
155 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
156 | char netagent_type[NETAGENT_TYPESIZE]; | |
157 | char netagent_desc[NETAGENT_DESCSIZE]; | |
158 | u_int32_t netagent_flags; | |
159 | u_int32_t netagent_data_size; | |
160 | u_int8_t netagent_data[0]; | |
161 | }; | |
162 | ||
163 | // To be used with SIOCGAGENTDATA | |
164 | struct netagent_req { | |
165 | uuid_t netagent_uuid; | |
166 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
167 | char netagent_type[NETAGENT_TYPESIZE]; | |
168 | char netagent_desc[NETAGENT_DESCSIZE]; | |
169 | u_int32_t netagent_flags; | |
170 | u_int32_t netagent_data_size; | |
171 | u_int8_t *netagent_data; | |
172 | }; | |
39037602 A |
173 | |
174 | // To be used with SIOCGAGENTLIST | |
175 | struct netagentlist_req { | |
176 | u_int32_t data_size; | |
177 | u_int8_t *data; | |
178 | }; | |
3e170ce0 A |
179 | #ifdef BSD_KERNEL_PRIVATE |
180 | int netagent_ioctl(u_long cmd, caddr_t data); | |
181 | ||
182 | struct netagent_req32 { | |
183 | uuid_t netagent_uuid; | |
184 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
185 | char netagent_type[NETAGENT_TYPESIZE]; | |
186 | char netagent_desc[NETAGENT_DESCSIZE]; | |
187 | u_int32_t netagent_flags; | |
188 | u_int32_t netagent_data_size; | |
189 | user32_addr_t netagent_data; | |
190 | }; | |
191 | struct netagent_req64 { | |
192 | uuid_t netagent_uuid; | |
193 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
194 | char netagent_type[NETAGENT_TYPESIZE]; | |
195 | char netagent_desc[NETAGENT_DESCSIZE]; | |
196 | u_int32_t netagent_flags; | |
197 | u_int32_t netagent_data_size; | |
198 | user64_addr_t netagent_data __attribute__((aligned(8))); | |
199 | }; | |
39037602 A |
200 | struct netagentlist_req32 { |
201 | u_int32_t data_size; | |
202 | user32_addr_t data; | |
203 | }; | |
204 | struct netagentlist_req64 { | |
205 | u_int32_t data_size; | |
206 | user64_addr_t data __attribute__((aligned(8))); | |
207 | }; | |
3e170ce0 | 208 | |
5ba3f43e A |
209 | struct necp_client_nexus_parameters; |
210 | ||
3e170ce0 | 211 | // Kernel accessors |
39037602 | 212 | extern void netagent_post_updated_interfaces(uuid_t uuid); // To be called from interface ioctls |
3e170ce0 | 213 | |
39037602 | 214 | extern u_int32_t netagent_get_flags(uuid_t uuid); |
3e170ce0 | 215 | |
39037602 | 216 | extern u_int32_t netagent_get_generation(uuid_t uuid); |
3e170ce0 | 217 | |
39037602 A |
218 | extern bool netagent_get_agent_domain_and_type(uuid_t uuid, char *domain, char *type); |
219 | ||
220 | extern int netagent_kernel_trigger(uuid_t uuid); | |
221 | ||
5ba3f43e A |
222 | extern int netagent_client_message(uuid_t agent_uuid, uuid_t necp_client_uuid, pid_t pid, u_int8_t message_type); |
223 | ||
224 | extern int netagent_client_message_with_params(uuid_t agent_uuid, | |
225 | uuid_t necp_client_uuid, | |
226 | pid_t pid, | |
227 | u_int8_t message_type, | |
228 | struct necp_client_nexus_parameters *parameters, | |
229 | void **assigned_results, | |
230 | size_t *assigned_results_length); | |
39037602 A |
231 | |
232 | extern int netagent_copyout(uuid_t uuid, user_addr_t user_addr, u_int32_t user_size); | |
813fb2f6 | 233 | |
5ba3f43e A |
234 | |
235 | // Kernel agent management | |
236 | ||
237 | typedef void * netagent_session_t; | |
238 | ||
239 | struct netagent_nexus_agent { | |
240 | struct netagent agent; | |
241 | struct netagent_nexus nexus_data; | |
242 | }; | |
243 | ||
244 | #define NETAGENT_EVENT_TRIGGER NETAGENT_MESSAGE_TYPE_CLIENT_TRIGGER | |
245 | #define NETAGENT_EVENT_ASSERT NETAGENT_MESSAGE_TYPE_CLIENT_ASSERT | |
246 | #define NETAGENT_EVENT_UNASSERT NETAGENT_MESSAGE_TYPE_CLIENT_UNASSERT | |
247 | #define NETAGENT_EVENT_NEXUS_FLOW_INSERT NETAGENT_MESSAGE_TYPE_REQUEST_NEXUS | |
248 | #define NETAGENT_EVENT_NEXUS_FLOW_REMOVE NETAGENT_MESSAGE_TYPE_CLOSE_NEXUS | |
249 | #define NETAGENT_EVENT_NEXUS_FLOW_ABORT NETAGENT_MESSAGE_TYPE_ABORT_NEXUS | |
250 | ||
251 | typedef errno_t (*netagent_event_f)(u_int8_t event, uuid_t necp_client_uuid, pid_t pid, void *context, struct necp_client_nexus_parameters *parameters, void **assigned_results, size_t *assigned_results_length); | |
252 | ||
253 | extern netagent_session_t netagent_create(netagent_event_f event_handler, void *handle); | |
254 | ||
255 | extern void netagent_destroy(netagent_session_t session); | |
256 | ||
257 | extern errno_t netagent_register(netagent_session_t session, struct netagent *agent); | |
258 | ||
259 | extern errno_t netagent_update(netagent_session_t session, struct netagent *agent); | |
260 | ||
261 | extern errno_t netagent_unregister(netagent_session_t session); | |
262 | ||
263 | extern errno_t netagent_assign_nexus(netagent_session_t _session, | |
264 | uuid_t necp_client_uuid, | |
265 | void *assign_message, | |
266 | size_t assigned_results_length); // Length of assigned_results_length | |
267 | ||
268 | extern errno_t netagent_update_flow_protoctl_event(netagent_session_t _session, | |
269 | uuid_t client_id, | |
270 | uint32_t protoctl_event_code, | |
271 | uint32_t protoctl_event_val, | |
272 | uint32_t protoctl_event_tcp_seq_number); | |
273 | ||
813fb2f6 | 274 | extern int netagent_use(uuid_t agent_uuid, uint64_t *out_use_count); |
5ba3f43e | 275 | |
39037602 | 276 | #endif /* BSD_KERNEL_PRIVATE */ |
3e170ce0 A |
277 | |
278 | #ifndef KERNEL | |
39037602 | 279 | extern int netagent_trigger(uuid_t agent_uuid, size_t agent_uuidlen); |
3e170ce0 A |
280 | #endif /* !KERNEL */ |
281 | ||
39037602 A |
282 | #endif /* PRIVATE */ |
283 | ||
3e170ce0 | 284 | #endif /* _NETAGENT_H_ */ |