]> git.saurik.com Git - apple/configd.git/blob - SystemConfiguration.fproj/SCNetworkReachabilityInternal.h
configd-801.1.1.tar.gz
[apple/configd.git] / SystemConfiguration.fproj / SCNetworkReachabilityInternal.h
1 /*
2 * Copyright (c) 2003-2015 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 <SystemConfiguration/SCPrivate.h>
34 #include <dispatch/dispatch.h>
35
36 #include <dns_sd.h>
37 #include <netdb.h>
38 #include <sys/socket.h>
39 #include <net/if.h>
40 #include <xpc/xpc.h>
41
42 #include <network/private.h>
43
44 #pragma mark -
45 #pragma mark SCNetworkReachability
46
47 #define kSCNetworkReachabilityFlagsMask 0x00ffffff // top 8-bits reserved for implementation
48
49
50 typedef enum {
51 NO = 0,
52 YES,
53 UNKNOWN
54 } lazyBoolean;
55
56
57 typedef enum {
58 // by-address SCNetworkReachability targets
59 reachabilityTypeAddress,
60 reachabilityTypeAddressPair,
61 // by-name SCNetworkReachability targets
62 reachabilityTypeName,
63 reachabilityTypePTR
64 } ReachabilityAddressType;
65
66 #define isReachabilityTypeAddress(type) (type < reachabilityTypeName)
67 #define isReachabilityTypeName(type) (type >= reachabilityTypeName)
68
69 typedef struct {
70
71 /* base CFType information */
72 CFRuntimeBase cfBase;
73
74 /* lock */
75 pthread_mutex_t lock;
76
77 /* address type */
78 ReachabilityAddressType type;
79
80 /* target host name */
81 nw_endpoint_t hostnameEndpoint;
82
83 /* local & remote addresses */
84 nw_endpoint_t localAddressEndpoint;
85 nw_endpoint_t remoteAddressEndpoint;
86
87 /* run loop source, callout, context, rl scheduling info */
88 Boolean scheduled;
89 Boolean sentFirstUpdate;
90 CFRunLoopSourceRef rls;
91 SCNetworkReachabilityCallBack rlsFunction;
92 SCNetworkReachabilityContext rlsContext;
93 CFMutableArrayRef rlList;
94
95 dispatch_queue_t dispatchQueue; // SCNetworkReachabilitySetDispatchQueue
96
97 Boolean resolverBypass; // set this flag to bypass resolving the name
98
99 /* logging */
100 char log_prefix[32];
101
102 nw_parameters_t parameters;
103 nw_path_evaluator_t pathEvaluator;
104 nw_path_t lastPath;
105 nw_parameters_t lastPathParameters;
106 nw_resolver_t resolver;
107 nw_resolver_status_t lastResolverStatus;
108 nw_array_t lastResolvedEndpoints;
109 Boolean lastResolvedEndpointHasFlags;
110 SCNetworkReachabilityFlags lastResolvedEndpointFlags;
111 uint lastResolvedEndpointInterfaceIndex;
112
113 } SCNetworkReachabilityPrivate, *SCNetworkReachabilityPrivateRef;
114
115
116 // ------------------------------------------------------------
117
118
119 __BEGIN_DECLS
120
121 CFStringRef
122 _SCNetworkReachabilityCopyTargetDescription (SCNetworkReachabilityRef target);
123
124
125 static __inline__ CFStringRef
126 __SCNetworkReachabilityCopyFlags(SCNetworkReachabilityFlags flags, CFStringRef prefix, Boolean debug)
127 {
128 CFMutableStringRef str = CFStringCreateMutable(NULL, 0);
129
130 if (debug) {
131 if (prefix != NULL) {
132 CFStringAppend(str, prefix);
133 }
134
135 CFStringAppendFormat(str, NULL, CFSTR("0x%08x ("), flags);
136 }
137
138 if (flags == 0) {
139 CFStringAppend(str, CFSTR("Not Reachable"));
140 }
141 if (flags & kSCNetworkReachabilityFlagsReachable) {
142 flags &= ~kSCNetworkReachabilityFlagsReachable;
143 CFStringAppendFormat(str, NULL, CFSTR("Reachable%s"),
144 flags != 0 ? ", " : "");
145 }
146 if (flags & kSCNetworkReachabilityFlagsTransientConnection) {
147 flags &= ~kSCNetworkReachabilityFlagsTransientConnection;
148 CFStringAppendFormat(str, NULL, CFSTR("Transient Connection%s"),
149 flags != 0 ? ", " : "");
150 }
151 if (flags & kSCNetworkReachabilityFlagsConnectionRequired) {
152 flags &= ~kSCNetworkReachabilityFlagsConnectionRequired;
153 CFStringAppendFormat(str, NULL, CFSTR("Connection Required%s"),
154 flags != 0 ? ", " : "");
155 }
156 if (flags & kSCNetworkReachabilityFlagsConnectionOnTraffic) {
157 flags &= ~kSCNetworkReachabilityFlagsConnectionOnTraffic;
158 CFStringAppendFormat(str, NULL, CFSTR("Automatic Connection On Traffic%s"),
159 flags != 0 ? ", " : "");
160 }
161 if (flags & kSCNetworkReachabilityFlagsConnectionOnDemand) {
162 flags &= ~kSCNetworkReachabilityFlagsConnectionOnDemand;
163 CFStringAppendFormat(str, NULL, CFSTR("Automatic Connection On Demand%s"),
164 flags != 0 ? ", " : "");
165 }
166 if (flags & kSCNetworkReachabilityFlagsInterventionRequired) {
167 flags &= ~kSCNetworkReachabilityFlagsInterventionRequired;
168 CFStringAppendFormat(str, NULL, CFSTR("Intervention Required%s"),
169 flags != 0 ? ", " : "");
170 }
171 if (flags & kSCNetworkReachabilityFlagsIsLocalAddress) {
172 flags &= ~kSCNetworkReachabilityFlagsIsLocalAddress;
173 CFStringAppendFormat(str, NULL, CFSTR("Local Address%s"),
174 flags != 0 ? ", " : "");
175 }
176 if (flags & kSCNetworkReachabilityFlagsIsDirect) {
177 flags &= ~kSCNetworkReachabilityFlagsIsDirect;
178 CFStringAppendFormat(str, NULL, CFSTR("Directly Reachable Address%s"),
179 flags != 0 ? ", " : "");
180 }
181 #if TARGET_OS_IPHONE
182 if (flags & kSCNetworkReachabilityFlagsIsWWAN) {
183 flags &= ~kSCNetworkReachabilityFlagsIsWWAN;
184 CFStringAppendFormat(str, NULL, CFSTR("WWAN%s"), flags != 0 ? ", " : "");
185 }
186 #endif // TARGET_OS_IPHONE
187 if (flags != 0) {
188 CFStringAppendFormat(str, NULL, CFSTR("0x%08x"), flags);
189 }
190
191 if (debug) {
192 CFStringAppend(str, CFSTR(")"));
193 }
194
195 return str;
196 }
197
198
199 __END_DECLS
200
201 #endif // _SCNETWORKREACHABILITYINTERNAL_H