]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkReachabilityInternal.h
configd-453.19.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkReachabilityInternal.h
1 /*
2 * Copyright (c) 2003-2012 Apple Inc. All rights reserved.
3 *
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
12 *
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23
24 #ifndef _SCNETWORKREACHABILITYINTERNAL_H
25 #define _SCNETWORKREACHABILITYINTERNAL_H
26
27 #include <Availability.h>
28 #include <TargetConditionals.h>
29 #include <sys/cdefs.h>
30 #include <CoreFoundation/CoreFoundation.h>
31 #include <CoreFoundation/CFRuntime.h>
32 #include <SystemConfiguration/SystemConfiguration.h>
33 #include <dispatch/dispatch.h>
34
35 #include <dns_sd.h>
36 #include <netdb.h>
37 #include <sys/socket.h>
38 #include <net/if.h>
39
40 #if ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1080) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 50000)) && !TARGET_IPHONE_SIMULATOR
41 #define HAVE_REACHABILITY_SERVER
42 #include <xpc/xpc.h>
43 #endif // ((__MAC_OS_X_VERSION_MIN_REQUIRED >= 1080) || (__IPHONE_OS_VERSION_MIN_REQUIRED >= 50000)) && !TARGET_IPHONE_SIMULATOR
44
45
46 #pragma mark -
47 #pragma mark SCNetworkReachability
48
49
50 #define kSCNetworkReachabilityFlagsFirstResolvePending (1<<31)
51
52
53 typedef enum { NO = 0, YES, UNKNOWN } lazyBoolean;
54
55
56 typedef enum {
57 reachabilityTypeAddress,
58 reachabilityTypeAddressPair,
59 reachabilityTypeName
60 } ReachabilityAddressType;
61
62
63 typedef struct {
64 uint64_t cycle;
65 SCNetworkReachabilityFlags flags;
66 unsigned int if_index;
67 char if_name[IFNAMSIZ];
68 Boolean sleeping;
69 } ReachabilityInfo;
70
71
72 typedef struct {
73
74 /* base CFType information */
75 CFRuntimeBase cfBase;
76
77 /* lock */
78 pthread_mutex_t lock;
79
80 /* address type */
81 ReachabilityAddressType type;
82
83 /* target host name */
84 const char *name;
85 const char *serv;
86 struct addrinfo hints;
87 Boolean needResolve;
88 CFArrayRef resolvedAddress; /* CFArray[CFData] */
89 int resolvedAddressError;
90
91 /* [scoped routing] interface constraints */
92 unsigned int if_index;
93 char if_name[IFNAMSIZ];
94
95 /* local & remote addresses */
96 struct sockaddr *localAddress;
97 struct sockaddr *remoteAddress;
98
99 /* current reachability flags */
100 uint64_t cycle;
101 ReachabilityInfo info;
102 ReachabilityInfo last_notify;
103
104 /* run loop source, callout, context, rl scheduling info */
105 Boolean scheduled;
106 CFRunLoopSourceRef rls;
107 SCNetworkReachabilityCallBack rlsFunction;
108 SCNetworkReachabilityContext rlsContext;
109 CFMutableArrayRef rlList;
110
111 dispatch_group_t dispatchGroup;
112 dispatch_queue_t dispatchQueue; // SCNetworkReachabilitySetDispatchQueue
113
114 /* [async] DNS query info */
115 Boolean haveDNS;
116 mach_port_t dnsMP; // != MACH_PORT_NULL (if active)
117 CFMachPortRef dnsPort; // for CFRunLoop queries
118 CFRunLoopSourceRef dnsRLS; // for CFRunLoop queries
119 dispatch_source_t dnsSource; // for dispatch queries
120 struct timeval dnsQueryStart;
121 struct timeval dnsQueryEnd;
122 dispatch_source_t dnsRetry; // != NULL if DNS retry request queued
123 int dnsRetryCount; // number of retry attempts
124
125 /* [async] processing info */
126 struct timeval last_dns;
127 struct timeval last_network;
128 #if !TARGET_OS_IPHONE
129 struct timeval last_power;
130 #endif // !TARGET_OS_IPHONE
131 struct timeval last_push;
132
133 /* on demand info */
134 Boolean onDemandBypass;
135 CFStringRef onDemandName;
136 CFStringRef onDemandRemoteAddress;
137 SCNetworkReachabilityRef onDemandServer;
138 CFStringRef onDemandServiceID;
139
140
141 Boolean llqActive;
142 Boolean llqBypass;
143 DNSServiceRef llqTarget;
144 dispatch_source_t llqTimer; // != NULL while waiting for first callback
145
146 #ifdef HAVE_REACHABILITY_SERVER
147 /* SCNetworkReachability server "client" info */
148 Boolean serverActive;
149 Boolean serverBypass;
150 Boolean serverScheduled;
151 ReachabilityInfo serverInfo;
152
153 /* SCNetworkReachability server "server" info */
154 CFDataRef serverDigest;
155 dispatch_group_t serverGroup;
156 Boolean serverInfoValid;
157 unsigned int serverQueryActive; // 0 == no query active, else # waiting on group
158 dispatch_queue_t serverQueue;
159 unsigned int serverReferences; // how many [client] targets
160 CFMutableDictionaryRef serverWatchers; // [client_id/target_id] watchers
161 #endif // HAVE_REACHABILITY_SERVER
162 Boolean resolverBypass; // set this flag to bypass resolving the name
163
164 /* logging */
165 char log_prefix[32];
166
167 } SCNetworkReachabilityPrivate, *SCNetworkReachabilityPrivateRef;
168
169
170 #ifdef HAVE_REACHABILITY_SERVER
171
172 // ------------------------------------------------------------
173
174 #pragma mark -
175 #pragma mark [XPC] Reachability Server
176
177
178 #define REACH_SERVER_VERSION 20110323
179 #define REACH_SERVICE_NAME "com.apple.SystemConfiguration.SCNetworkReachability"
180
181 // ------------------------------------------------------------
182
183
184 #pragma mark -
185 #pragma mark [XPC] Reachability Server (client->server request)
186
187
188 #define REACH_CLIENT_PROC_NAME "proc_name" // string
189 #define REACH_CLIENT_TARGET_ID "target_id" // uint64
190
191 #define REACH_REQUEST "request_op" // int64
192
193 enum {
194 REACH_REQUEST_CREATE = 0x0001,
195 REACH_REQUEST_REMOVE,
196 REACH_REQUEST_SCHEDULE,
197 REACH_REQUEST_STATUS,
198 REACH_REQUEST_UNSCHEDULE,
199 REACH_REQUEST_SNAPSHOT = 0x0101,
200 };
201
202 #define REACH_TARGET_NAME "name" // string
203 #define REACH_TARGET_SERV "serv" // string
204 #define REACH_TARGET_HINTS "hints" // data (struct addrinfo)
205 #define REACH_TARGET_IF_INDEX "if_index" // int64
206 #define REACH_TARGET_IF_NAME "if_name" // string
207 #define REACH_TARGET_LOCAL_ADDR "localAddress" // data (struct sockaddr)
208 #define REACH_TARGET_REMOTE_ADDR "remoteAddress" // data (struct sockaddr)
209 #define REACH_TARGET_ONDEMAND_BYPASS "onDemandBypass" // bool
210 #define REACH_TARGET_RESOLVER_BYPASS "resolverBypass" // bool
211
212
213 #define REACH_REQUEST_REPLY "reply" // int64
214 #define REACH_REQUEST_REPLY_DETAIL "reply_detail" // string
215
216 enum {
217 REACH_REQUEST_REPLY_OK = 0x0000,
218 REACH_REQUEST_REPLY_FAILED,
219 REACH_REQUEST_REPLY_UNKNOWN,
220 };
221
222
223 // ------------------------------------------------------------
224
225
226 #pragma mark -
227 #pragma mark [XPC] Reachability Server (server->client request)
228
229
230 #define MESSAGE_NOTIFY "notify_op" // int64
231
232 enum {
233 MESSAGE_REACHABILITY_STATUS = 0x1001,
234 };
235
236 #define REACH_STATUS_CYCLE "cycle" // uint64
237 #define REACH_STATUS_FLAGS "flags" // uint64
238 #define REACH_STATUS_IF_INDEX "if_index" // uint64
239 #define REACH_STATUS_IF_NAME "if_name" // data (char if_name[IFNAMSIZ])
240 #define REACH_STATUS_RESOLVED_ADDRESS "resolvedAddress" // array[data]
241 #define REACH_STATUS_RESOLVED_ADDRESS_ERROR "resolvedAddressError" // int64
242 #define REACH_STATUS_SLEEPING "sleeping" // bool
243
244
245 // ------------------------------------------------------------
246
247 #endif // HAVE_REACHABILITY_SERVER
248
249
250 __BEGIN_DECLS
251
252 CFStringRef
253 _SCNetworkReachabilityCopyTargetDescription (SCNetworkReachabilityRef target);
254
255 CFStringRef
256 _SCNetworkReachabilityCopyTargetFlags (SCNetworkReachabilityRef target);
257
258 #ifdef HAVE_REACHABILITY_SERVER
259
260 dispatch_queue_t
261 __SCNetworkReachability_concurrent_queue (void);
262
263 void
264 __SCNetworkReachabilityPerformNoLock (SCNetworkReachabilityRef target);
265
266 #pragma mark -
267 #pragma mark [XPC] Reachability Server (client APIs)
268
269 Boolean
270 _SCNetworkReachabilityServer_snapshot (void);
271
272 Boolean
273 __SCNetworkReachabilityServer_targetAdd (SCNetworkReachabilityRef target);
274
275 void
276 __SCNetworkReachabilityServer_targetRemove (SCNetworkReachabilityRef target);
277
278 Boolean
279 __SCNetworkReachabilityServer_targetSchedule (SCNetworkReachabilityRef target);
280
281 Boolean
282 __SCNetworkReachabilityServer_targetStatus (SCNetworkReachabilityRef target);
283
284 Boolean
285 __SCNetworkReachabilityServer_targetUnschedule (SCNetworkReachabilityRef target);
286
287 Boolean
288 __SC_checkResolverReachabilityInternal (SCDynamicStoreRef *storeP,
289 SCNetworkReachabilityFlags *flags,
290 Boolean *haveDNS,
291 const char *nodename,
292 const char *servname,
293 uint32_t *resolver_if_index,
294 int *dns_config_index);
295
296 #endif // HAVE_REACHABILITY_SERVER
297
298 __END_DECLS
299
300 #endif // _SCNETWORKREACHABILITYINTERNAL_H