]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * Copyright (c) 2014-2016 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _NETAGENT_H_ | |
30 | #define _NETAGENT_H_ | |
31 | #include <net/net_kev.h> | |
32 | ||
33 | #ifdef PRIVATE | |
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 | |
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 | ||
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 | ||
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 | |
74 | #define NETAGENT_MESSAGE_TYPE_GET 4 // No value, return netagent | |
75 | #define NETAGENT_MESSAGE_TYPE_TRIGGER 5 // Kernel initiated, no reply expected | |
76 | #define NETAGENT_MESSAGE_TYPE_ASSERT 6 // Deprecated | |
77 | #define NETAGENT_MESSAGE_TYPE_UNASSERT 7 // Deprecated | |
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 | |
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 | |
91 | ||
92 | #define NETAGENT_MESSAGE_FLAGS_RESPONSE 0x01 // Used for acks, errors, and query responses | |
93 | ||
94 | #define NETAGENT_MESSAGE_ERROR_NONE 0 | |
95 | #define NETAGENT_MESSAGE_ERROR_INTERNAL 1 | |
96 | #define NETAGENT_MESSAGE_ERROR_UNKNOWN_TYPE 2 | |
97 | #define NETAGENT_MESSAGE_ERROR_INVALID_DATA 3 | |
98 | #define NETAGENT_MESSAGE_ERROR_NOT_REGISTERED 4 | |
99 | #define NETAGENT_MESSAGE_ERROR_ALREADY_REGISTERED 5 | |
100 | #define NETAGENT_MESSAGE_ERROR_CANNOT_UPDATE 6 | |
101 | #define NETAGENT_MESSAGE_ERROR_CANNOT_ASSIGN 7 | |
102 | ||
103 | #define NETAGENT_DOMAINSIZE 32 | |
104 | #define NETAGENT_TYPESIZE 32 | |
105 | #define NETAGENT_DESCSIZE 128 | |
106 | ||
107 | #define NETAGENT_MAX_DATA_SIZE 4096 | |
108 | ||
109 | #define NETAGENT_FLAG_REGISTERED 0x0001 // Agent is registered | |
110 | #define NETAGENT_FLAG_ACTIVE 0x0002 // Agent is active | |
111 | #define NETAGENT_FLAG_KERNEL_ACTIVATED 0x0004 // Agent can be activated by kernel activity | |
112 | #define NETAGENT_FLAG_USER_ACTIVATED 0x0008 // Agent can be activated by system call (netagent_trigger) | |
113 | #define NETAGENT_FLAG_VOLUNTARY 0x0010 // Use of agent is optional | |
114 | #define NETAGENT_FLAG_SPECIFIC_USE_ONLY 0x0020 // Agent should only be used and activated when specifically required | |
115 | #define NETAGENT_FLAG_NETWORK_PROVIDER 0x0040 // Agent provides network access | |
116 | #define NETAGENT_FLAG_NEXUS_PROVIDER 0x0080 // Agent provides a skywalk nexus | |
117 | ||
118 | #define NETAGENT_NEXUS_MAX_REQUEST_TYPES 16 | |
119 | #define NETAGENT_NEXUS_MAX_RESOLUTION_TYPE_PAIRS 16 | |
120 | ||
121 | #define NETAGENT_NEXUS_FRAME_TYPE_UNKNOWN 0 | |
122 | #define NETAGENT_NEXUS_FRAME_TYPE_LINK 1 | |
123 | #define NETAGENT_NEXUS_FRAME_TYPE_INTERNET 2 | |
124 | #define NETAGENT_NEXUS_FRAME_TYPE_TRANSPORT 3 | |
125 | #define NETAGENT_NEXUS_FRAME_TYPE_APPLICATION 4 | |
126 | ||
127 | struct netagent_nexus { | |
128 | u_int32_t frame_type; | |
129 | u_int32_t endpoint_assignment_type; | |
130 | u_int32_t endpoint_request_types[NETAGENT_NEXUS_MAX_REQUEST_TYPES]; | |
131 | u_int32_t endpoint_resolution_type_pairs[NETAGENT_NEXUS_MAX_RESOLUTION_TYPE_PAIRS * 2]; | |
132 | }; | |
133 | ||
134 | #define NETAGENT_TRIGGER_FLAG_USER 0x0001 // Userspace triggered agent | |
135 | #define NETAGENT_TRIGGER_FLAG_KERNEL 0x0002 // Kernel triggered agent | |
136 | ||
137 | struct kev_netagent_data { | |
138 | uuid_t netagent_uuid; | |
139 | }; | |
140 | ||
141 | // To be used with kernel control socket | |
142 | struct netagent { | |
143 | uuid_t netagent_uuid; | |
144 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
145 | char netagent_type[NETAGENT_TYPESIZE]; | |
146 | char netagent_desc[NETAGENT_DESCSIZE]; | |
147 | u_int32_t netagent_flags; | |
148 | u_int32_t netagent_data_size; | |
149 | u_int8_t netagent_data[0]; | |
150 | }; | |
151 | ||
152 | // To be used with SIOCGAGENTDATA | |
153 | struct netagent_req { | |
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; | |
161 | }; | |
162 | ||
163 | // To be used with SIOCGAGENTLIST | |
164 | struct netagentlist_req { | |
165 | u_int32_t data_size; | |
166 | u_int8_t *data; | |
167 | }; | |
168 | #ifdef BSD_KERNEL_PRIVATE | |
169 | int netagent_ioctl(u_long cmd, caddr_t data); | |
170 | ||
171 | struct netagent_req32 { | |
172 | uuid_t netagent_uuid; | |
173 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
174 | char netagent_type[NETAGENT_TYPESIZE]; | |
175 | char netagent_desc[NETAGENT_DESCSIZE]; | |
176 | u_int32_t netagent_flags; | |
177 | u_int32_t netagent_data_size; | |
178 | user32_addr_t netagent_data; | |
179 | }; | |
180 | struct netagent_req64 { | |
181 | uuid_t netagent_uuid; | |
182 | char netagent_domain[NETAGENT_DOMAINSIZE]; | |
183 | char netagent_type[NETAGENT_TYPESIZE]; | |
184 | char netagent_desc[NETAGENT_DESCSIZE]; | |
185 | u_int32_t netagent_flags; | |
186 | u_int32_t netagent_data_size; | |
187 | user64_addr_t netagent_data __attribute__((aligned(8))); | |
188 | }; | |
189 | struct netagentlist_req32 { | |
190 | u_int32_t data_size; | |
191 | user32_addr_t data; | |
192 | }; | |
193 | struct netagentlist_req64 { | |
194 | u_int32_t data_size; | |
195 | user64_addr_t data __attribute__((aligned(8))); | |
196 | }; | |
197 | ||
198 | // Kernel accessors | |
199 | extern void netagent_post_updated_interfaces(uuid_t uuid); // To be called from interface ioctls | |
200 | ||
201 | extern u_int32_t netagent_get_flags(uuid_t uuid); | |
202 | ||
203 | extern u_int32_t netagent_get_generation(uuid_t uuid); | |
204 | ||
205 | extern bool netagent_get_agent_domain_and_type(uuid_t uuid, char *domain, char *type); | |
206 | ||
207 | extern int netagent_kernel_trigger(uuid_t uuid); | |
208 | ||
209 | extern int netagent_client_message(uuid_t agent_uuid, uuid_t necp_client_uuid, u_int8_t message_type); | |
210 | ||
211 | extern int netagent_copyout(uuid_t uuid, user_addr_t user_addr, u_int32_t user_size); | |
212 | #endif /* BSD_KERNEL_PRIVATE */ | |
213 | ||
214 | #ifndef KERNEL | |
215 | extern int netagent_trigger(uuid_t agent_uuid, size_t agent_uuidlen); | |
216 | #endif /* !KERNEL */ | |
217 | ||
218 | #endif /* PRIVATE */ | |
219 | ||
220 | #endif /* _NETAGENT_H_ */ |