]> git.saurik.com Git - apple/xnu.git/blob - bsd/net/network_agent.h
6fe55b96c47a103033f8b1834861e7e4cc108214
[apple/xnu.git] / bsd / net / network_agent.h
1 /*
2 * Copyright (c) 2014, 2015 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
32 #include <netinet/in.h>
33 #include <sys/socket.h>
34
35 #ifdef BSD_KERNEL_PRIVATE
36 #include <stdbool.h>
37
38 errno_t netagent_init(void);
39 #endif
40 #ifdef PRIVATE
41 /*
42 * Name registered by the Network Agent kernel control
43 */
44 #define NETAGENT_CONTROL_NAME "com.apple.net.netagent"
45
46 struct netagent_message_header {
47 u_int8_t message_type;
48 u_int8_t message_flags;
49 u_int32_t message_id;
50 u_int32_t message_error;
51 u_int32_t message_payload_length;
52 };
53
54 struct netagent_trigger_message {
55 u_int32_t trigger_flags;
56 pid_t trigger_pid;
57 uuid_t trigger_proc_uuid;
58 };
59
60 #define NETAGENT_MESSAGE_TYPE_REGISTER 1 // Pass netagent to set, no return value
61 #define NETAGENT_MESSAGE_TYPE_UNREGISTER 2 // No value, no return value
62 #define NETAGENT_MESSAGE_TYPE_UPDATE 3 // Pass netagent to update, no return value
63 #define NETAGENT_MESSAGE_TYPE_GET 4 // No value, return netagent
64 #define NETAGENT_MESSAGE_TYPE_TRIGGER 5 // Kernel initiated, no reply expected
65 #define NETAGENT_MESSAGE_TYPE_ASSERT 6 // Pass uuid of netagent to assert
66 #define NETAGENT_MESSAGE_TYPE_UNASSERT 7 // Pass uuid of netagent to unassert
67 #define NETAGENT_MESSAGE_TYPE_TRIGGER_ASSERT 8 // Kernel initiated, no reply expected
68 #define NETAGENT_MESSAGE_TYPE_TRIGGER_UNASSERT 9 // Kernel initiated, no reply expected
69
70 #define NETAGENT_MESSAGE_FLAGS_RESPONSE 0x01 // Used for acks, errors, and query responses
71
72 #define NETAGENT_MESSAGE_ERROR_NONE 0
73 #define NETAGENT_MESSAGE_ERROR_INTERNAL 1
74 #define NETAGENT_MESSAGE_ERROR_UNKNOWN_TYPE 2
75 #define NETAGENT_MESSAGE_ERROR_INVALID_DATA 3
76 #define NETAGENT_MESSAGE_ERROR_NOT_REGISTERED 4
77 #define NETAGENT_MESSAGE_ERROR_ALREADY_REGISTERED 5
78 #define NETAGENT_MESSAGE_ERROR_CANNOT_UPDATE 6
79
80 #define NETAGENT_DOMAINSIZE 32
81 #define NETAGENT_TYPESIZE 32
82 #define NETAGENT_DESCSIZE 128
83
84 #define NETAGENT_MAX_DATA_SIZE 1024
85
86 #define NETAGENT_FLAG_REGISTERED 0x0001 // Agent is registered
87 #define NETAGENT_FLAG_ACTIVE 0x0002 // Agent is active
88 #define NETAGENT_FLAG_KERNEL_ACTIVATED 0x0004 // Agent can be activated by kernel activity
89 #define NETAGENT_FLAG_USER_ACTIVATED 0x0008 // Agent can be activated by system call (netagent_trigger)
90 #define NETAGENT_FLAG_VOLUNTARY 0x0010 // Use of agent is optional
91 #define NETAGENT_FLAG_SPECIFIC_USE_ONLY 0x0020 // Agent should only be used and activated when specifically required
92
93 #define NETAGENT_TRIGGER_FLAG_USER 0x0001 // Userspace triggered agent
94 #define NETAGENT_TRIGGER_FLAG_KERNEL 0x0002 // Kernel triggered agent
95
96 #define KEV_NETAGENT_SUBCLASS 9
97 #define KEV_NETAGENT_REGISTERED 1
98 #define KEV_NETAGENT_UNREGISTERED 2
99 #define KEV_NETAGENT_UPDATED 3
100 #define KEV_NETAGENT_UPDATED_INTERFACES 4
101
102 struct kev_netagent_data {
103 uuid_t netagent_uuid;
104 };
105
106 // To be used with kernel control socket
107 struct netagent {
108 uuid_t netagent_uuid;
109 char netagent_domain[NETAGENT_DOMAINSIZE];
110 char netagent_type[NETAGENT_TYPESIZE];
111 char netagent_desc[NETAGENT_DESCSIZE];
112 u_int32_t netagent_flags;
113 u_int32_t netagent_data_size;
114 u_int8_t netagent_data[0];
115 };
116
117 // To be used with SIOCGAGENTDATA
118 struct netagent_req {
119 uuid_t netagent_uuid;
120 char netagent_domain[NETAGENT_DOMAINSIZE];
121 char netagent_type[NETAGENT_TYPESIZE];
122 char netagent_desc[NETAGENT_DESCSIZE];
123 u_int32_t netagent_flags;
124 u_int32_t netagent_data_size;
125 u_int8_t *netagent_data;
126 };
127 #ifdef BSD_KERNEL_PRIVATE
128 int netagent_ioctl(u_long cmd, caddr_t data);
129
130 struct netagent_req32 {
131 uuid_t netagent_uuid;
132 char netagent_domain[NETAGENT_DOMAINSIZE];
133 char netagent_type[NETAGENT_TYPESIZE];
134 char netagent_desc[NETAGENT_DESCSIZE];
135 u_int32_t netagent_flags;
136 u_int32_t netagent_data_size;
137 user32_addr_t netagent_data;
138 };
139 struct netagent_req64 {
140 uuid_t netagent_uuid;
141 char netagent_domain[NETAGENT_DOMAINSIZE];
142 char netagent_type[NETAGENT_TYPESIZE];
143 char netagent_desc[NETAGENT_DESCSIZE];
144 u_int32_t netagent_flags;
145 u_int32_t netagent_data_size;
146 user64_addr_t netagent_data __attribute__((aligned(8)));
147 };
148
149 // Kernel accessors
150 void netagent_post_updated_interfaces(uuid_t uuid); // To be called from interface ioctls
151
152 u_int32_t netagent_get_flags(uuid_t uuid);
153
154 int netagent_kernel_trigger(uuid_t uuid);
155 #endif /* BSD_KERNEL_PRIVATE */
156
157 #endif /* PRIVATE */
158
159 #ifndef KERNEL
160 int netagent_trigger(uuid_t agent_uuid, size_t agent_uuidlen);
161 #endif /* !KERNEL */
162
163 #endif /* _NETAGENT_H_ */