]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/mDNSMacOSX.h
mDNSResponder-214.3.tar.gz
[apple/mdnsresponder.git] / mDNSMacOSX / mDNSMacOSX.h
1 /* -*- Mode: C; tab-width: 4 -*-
2 *
3 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16
17 Change History (most recent first):
18
19 $Log: mDNSMacOSX.h,v $
20 Revision 1.104 2009/06/25 23:36:56 cheshire
21 To facilitate testing, added command-line switch "-OfferSleepProxyService"
22 to re-enable the previously-supported mode of operation where we offer
23 sleep proxy service on desktop Macs that are set to never sleep.
24
25 Revision 1.103 2009/04/11 00:20:13 jessic2
26 <rdar://problem/4426780> Daemon: Should be able to turn on LogOperation dynamically
27
28 Revision 1.102 2009/04/06 22:14:02 cheshire
29 Need to include IOKit/pwr_mgt/IOPM.h to build for AppleTV
30
31 Revision 1.101 2009/04/02 22:21:17 mcguire
32 <rdar://problem/6577409> Adopt IOPM APIs
33
34 Revision 1.100 2009/02/12 20:57:26 cheshire
35 Renamed 'LogAllOperation' switch to 'LogClientOperations'; added new 'LogSleepProxyActions' switch
36
37 Revision 1.99 2009/02/11 02:31:05 cheshire
38 Move SystemWakeForNetworkAccessEnabled into mDNS structure so it's accessible to mDNSCore routines
39
40 Revision 1.98 2009/02/07 02:52:19 cheshire
41 <rdar://problem/6084043> Sleep Proxy: Need to adopt IOPMConnection
42
43 Revision 1.97 2009/02/02 22:13:01 cheshire
44 Added SystemWakeForNetworkAccessEnabled setting
45
46 Revision 1.96 2009/01/17 04:13:57 cheshire
47 Added version symbols for Cheetah and Puma
48
49 Revision 1.95 2009/01/16 02:32:55 cheshire
50 Added SysEventNotifier and SysEventKQueue in mDNS_PlatformSupport_struct
51
52 Revision 1.94 2009/01/15 22:24:53 cheshire
53 Removed unused ifa_name field from NetworkInterfaceInfoOSX_struct
54
55 Revision 1.93 2008/12/10 19:30:01 cheshire
56 Added symbolic names for the various OS X versions
57
58 Revision 1.92 2008/10/31 23:49:38 mkrochma
59 Increased sizecheck limit
60
61 Revision 1.91 2008/10/31 22:48:27 cheshire
62 Added SCPreferencesRef to mDNS_PlatformSupport_struct
63
64 Revision 1.90 2008/10/30 01:04:35 cheshire
65 Added WakeAtUTC and SleepTime fields to mDNS_PlatformSupport_struct
66
67 Revision 1.89 2008/10/29 18:38:33 mcguire
68 Increase sizecheck limits to account for CFRunLoop added to mDNS_PlatformSupport_struct in 64bit builds
69
70 Revision 1.88 2008/10/28 20:33:56 cheshire
71 Added CFRunLoopRef in mDNS_PlatformSupport_struct, to hold reference to our main thread's CFRunLoop
72
73 Revision 1.87 2008/10/28 18:32:09 cheshire
74 Added CFSocketRef and CFRunLoopSourceRef in NetworkInterfaceInfoOSX_struct
75
76 Revision 1.86 2008/10/22 23:23:53 cheshire
77 Moved definition of OSXVers from daemon.c into mDNSMacOSX.c
78
79 Revision 1.85 2008/10/21 00:12:00 cheshire
80 Added BPF-related fields in NetworkInterfaceInfoOSX_struct
81
82 Revision 1.84 2008/10/14 20:20:44 cheshire
83 Increase sizecheck limits to account for DNSQuestions added to NetworkInterfaceInfo_struct
84
85 Revision 1.83 2008/10/07 21:41:57 mcguire
86 Increase sizecheck limits to account for DNSQuestion added to NetworkInterfaceInfo_struct in 64bit builds
87
88 Revision 1.82 2008/10/07 15:56:24 cheshire
89 Increase sizecheck limits to account for DNSQuestion added to NetworkInterfaceInfo_struct
90
91 Revision 1.81 2008/10/03 00:26:25 cheshire
92 Export DictionaryIsEnabled() so it's callable from other files
93
94 Revision 1.80 2008/10/02 22:47:01 cheshire
95 <rdar://problem/6134215> Sleep Proxy: Mac with Internet Sharing should also offer Sleep Proxy service
96 Added SCPreferencesRef so we can track whether Internet Sharing is on or off
97
98 Revision 1.79 2008/07/30 00:55:56 mcguire
99 <rdar://problem/3988320> Should use randomized source ports and transaction IDs to avoid DNS cache poisoning
100 Additional fixes so that we know when a socket has been closed while in a loop reading from it
101
102 Revision 1.78 2008/07/25 22:34:11 mcguire
103 fix sizecheck issues for 64bit
104
105 Revision 1.77 2008/07/24 20:23:04 cheshire
106 <rdar://problem/3988320> Should use randomized source ports and transaction IDs to avoid DNS cache poisoning
107
108 Revision 1.76 2008/07/01 01:40:01 mcguire
109 <rdar://problem/5823010> 64-bit fixes
110
111 Revision 1.75 2007/12/14 00:45:21 cheshire
112 Add SleepLimit and SleepCookie, for when we need to delay sleep until TLS/TCP record deregistration completes
113
114 Revision 1.74 2007/11/02 20:18:13 cheshire
115 <rdar://problem/5575583> BTMM: Work around keychain notification bug <rdar://problem/5124399>
116
117 Revision 1.73 2007/10/17 18:42:06 cheshire
118 Export SetDomainSecrets so its callable from other files
119
120 Revision 1.72 2007/08/01 16:09:14 cheshire
121 Removed unused NATTraversalInfo substructure from AuthRecord; reduced structure sizecheck values accordingly
122
123 Revision 1.71 2007/07/27 23:57:23 cheshire
124 Added compile-time structure size checks
125
126 Revision 1.70 2007/07/11 02:55:50 cheshire
127 <rdar://problem/5303807> Register IPv6-only hostname and don't create port mappings for AutoTunnel services
128 Remove unused DefaultRegDomainChanged/DefaultBrowseDomainChanged
129
130 Revision 1.69 2007/05/08 00:56:17 cheshire
131 <rdar://problem/4118503> Share single socket instead of creating separate socket for each active interface
132
133 Revision 1.68 2007/04/24 00:10:15 cheshire
134 Increase WatchDogReportingThreshold to 250ms for customer builds
135
136 Revision 1.67 2007/04/21 21:47:47 cheshire
137 <rdar://problem/4376383> Daemon: Add watchdog timer
138
139 Revision 1.66 2007/04/07 01:01:48 cheshire
140 <rdar://problem/5095167> mDNSResponder periodically blocks in SSLRead
141
142 Revision 1.65 2007/03/07 02:50:50 cheshire
143 <rdar://problem/4574528> Name conflict dialog doesn't appear if Bonjour is persistantly unable to find an available hostname
144
145 Revision 1.64 2007/03/06 23:29:50 cheshire
146 <rdar://problem/4331696> Need to call IONotificationPortDestroy on shutdown
147
148 Revision 1.63 2007/02/07 19:32:00 cheshire
149 <rdar://problem/4980353> All mDNSResponder components should contain version strings in SCCS-compatible format
150
151 Revision 1.62 2007/01/05 08:30:49 cheshire
152 Trim excessive "$Log" checkin history from before 2006
153 (checkin history still available via "cvs log ..." of course)
154
155 Revision 1.61 2006/08/14 23:24:40 cheshire
156 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
157
158 Revision 1.60 2006/07/27 03:24:35 cheshire
159 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
160 Further refinement: Declare KQueueEntry parameter "const"
161
162 Revision 1.59 2006/07/27 02:59:25 cheshire
163 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
164 Further refinements: CFRunLoop thread needs to explicitly wake the kqueue thread
165 after releasing BigMutex, in case actions it took have resulted in new work for the
166 kqueue thread (e.g. NetworkChanged events may result in the kqueue thread having to
167 add new active interfaces to its list, and consequently schedule queries to be sent).
168
169 Revision 1.58 2006/07/22 06:08:29 cheshire
170 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
171 Further changes
172
173 Revision 1.57 2006/07/22 03:43:26 cheshire
174 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
175
176 Revision 1.56 2006/07/05 23:37:26 cheshire
177 Remove unused LegacyNATInit/LegacyNATDestroy declarations
178
179 Revision 1.55 2006/06/29 05:33:30 cheshire
180 <rdar://problem/4607043> mDNSResponder conditional compilation options
181
182 Revision 1.54 2006/03/19 03:27:49 cheshire
183 <rdar://problem/4118624> Suppress "interface flapping" logic for loopback
184
185 Revision 1.53 2006/03/19 02:00:09 cheshire
186 <rdar://problem/4073825> Improve logic for delaying packets after repeated interface transitions
187
188 Revision 1.52 2006/01/05 21:41:49 cheshire
189 <rdar://problem/4108164> Reword "mach_absolute_time went backwards" dialog
190
191 */
192
193 #ifndef __mDNSOSX_h
194 #define __mDNSOSX_h
195
196 #ifdef __cplusplus
197 extern "C" {
198 #endif
199
200 #include <SystemConfiguration/SystemConfiguration.h>
201 #include <IOKit/pwr_mgt/IOPM.h>
202 #include <IOKit/pwr_mgt/IOPMLib.h>
203 #include <IOKit/pwr_mgt/IOPMLibPrivate.h>
204 #include <sys/socket.h>
205 #include <netinet/in.h>
206 #include "mDNSEmbeddedAPI.h" // for domain name structure
207
208 typedef struct NetworkInterfaceInfoOSX_struct NetworkInterfaceInfoOSX;
209
210 typedef void (*KQueueEventCallback)(int fd, short filter, void *context);
211 typedef struct
212 {
213 KQueueEventCallback KQcallback;
214 void *KQcontext;
215 const char const *KQtask; // For debugging messages
216 } KQueueEntry;
217
218 typedef struct
219 {
220 mDNSIPPort port; // MUST BE FIRST FIELD -- UDPSocket_struct begins with a KQSocketSet,
221 // and mDNSCore requires every UDPSocket_struct to begin with a mDNSIPPort port
222 mDNS *m;
223 int sktv4;
224 KQueueEntry kqsv4;
225 int sktv6;
226 KQueueEntry kqsv6;
227 int *closeFlag;
228 } KQSocketSet;
229
230 struct UDPSocket_struct
231 {
232 KQSocketSet ss; // First field of KQSocketSet has to be mDNSIPPort -- mDNSCore requires every UDPSocket_struct to begin with mDNSIPPort port
233 };
234
235 struct NetworkInterfaceInfoOSX_struct
236 {
237 NetworkInterfaceInfo ifinfo; // MUST be the first element in this structure
238 NetworkInterfaceInfoOSX *next;
239 mDNS *m;
240 mDNSu8 Exists; // 1 = currently exists in getifaddrs list; 0 = doesn't
241 // 2 = exists, but McastTxRx state changed
242 mDNSu8 Flashing; // Set if interface appeared for less than 60 seconds and then vanished
243 mDNSu8 Occulting; // Set if interface vanished for less than 60 seconds and then came back
244 mDNSs32 AppearanceTime; // Time this interface appeared most recently in getifaddrs list
245 // i.e. the first time an interface is seen, AppearanceTime is set.
246 // If an interface goes away temporarily and then comes back then
247 // AppearanceTime is updated to the time of the most recent appearance.
248 mDNSs32 LastSeen; // If Exists==0, last time this interface appeared in getifaddrs list
249 unsigned int ifa_flags;
250 struct in_addr ifa_v4addr;
251 mDNSu32 scope_id; // interface index / IPv6 scope ID
252 mDNSEthAddr BSSID; // BSSID of 802.11 base station, if applicable
253 u_short sa_family;
254 int BPF_fd; // -1 uninitialized; -2 requested BPF; -3 failed
255 u_int BPF_len;
256 CFSocketRef BPF_cfs;
257 CFRunLoopSourceRef BPF_rls;
258 NetworkInterfaceInfoOSX *Registered; // non-NULL means registered with mDNS Core
259 };
260
261 struct mDNS_PlatformSupport_struct
262 {
263 NetworkInterfaceInfoOSX *InterfaceList;
264 KQSocketSet permanentsockets;
265 domainlabel userhostlabel; // The hostlabel as it was set in System Preferences the last time we looked
266 domainlabel usernicelabel; // The nicelabel as it was set in System Preferences the last time we looked
267 mDNSs32 NotifyUser;
268 mDNSs32 HostNameConflict; // Time we experienced conflict on our link-local host name
269 mDNSs32 NetworkChanged;
270
271 // KeyChain frequently fails to notify clients of change events. To work around this
272 // we set a timer and periodically poll to detect if any changes have occurred.
273 // Without this Back To My Mac just does't work for a large number of users.
274 // See <rdar://problem/5124399> Not getting Keychain Changed events when enabling BTMM
275 mDNSs32 KeyChainBugTimer;
276 mDNSs32 KeyChainBugInterval;
277
278 CFRunLoopRef CFRunLoop;
279 SCDynamicStoreRef Store;
280 CFRunLoopSourceRef StoreRLS;
281 CFRunLoopSourceRef PMRLS;
282 int SysEventNotifier;
283 KQueueEntry SysEventKQueue;
284 IONotificationPortRef PowerPortRef;
285 io_connect_t PowerConnection;
286 io_object_t PowerNotifier;
287 #ifdef kIOPMAcknowledgmentOptionSystemCapabilityRequirements
288 IOPMConnection IOPMConnection;
289 #endif
290 SCPreferencesRef SCPrefs;
291 long SleepCookie; // Cookie we need to pass to IOAllowPowerChange()
292 long WakeAtUTC;
293 mDNSs32 RequestReSleep;
294 pthread_mutex_t BigMutex;
295 mDNSs32 BigMutexStartTime;
296 int WakeKQueueLoopFD;
297 };
298
299 extern int OfferSleepProxyService;
300 extern int OSXVers;
301 #define OSXVers_Base 4
302 #define OSXVers_10_0_Cheetah 4
303 #define OSXVers_10_1_Puma 5
304 #define OSXVers_10_2_Jaguar 6
305 #define OSXVers_10_3_Panther 7
306 #define OSXVers_10_4_Tiger 8
307 #define OSXVers_10_5_Leopard 9
308 #define OSXVers_10_6_SnowLeopard 10
309
310 extern int KQueueFD;
311
312 extern void NotifyOfElusiveBug(const char *title, const char *msg); // Both strings are UTF-8 text
313 extern void SetDomainSecrets(mDNS *m);
314 extern void mDNSMacOSXNetworkChanged(mDNS *const m);
315 extern int mDNSMacOSXSystemBuildNumber(char *HINFO_SWstring);
316 extern NetworkInterfaceInfoOSX *IfindexToInterfaceInfoOSX(const mDNS *const m, mDNSInterfaceID ifindex);
317
318 extern int KQueueSet(int fd, u_short flags, short filter, const KQueueEntry *const entryRef);
319
320 // When events are processed on the non-kqueue thread (i.e. CFRunLoop notifications like Sleep/Wake,
321 // Interface changes, Keychain changes, etc.) they must use KQueueLock/KQueueUnlock to lock out the kqueue thread
322 extern void KQueueLock(mDNS *const m);
323 extern void KQueueUnlock(mDNS *const m, const char const *task);
324
325 extern mDNSBool DictionaryIsEnabled(CFDictionaryRef dict);
326
327 // If any event takes more than WatchDogReportingThreshold milliseconds to be processed, we log a warning message
328 // General event categories are:
329 // o Mach client request initiated / terminated
330 // o UDS client request
331 // o Handling UDP packets received from the network
332 // o Environmental change events:
333 // - network interface changes
334 // - sleep/wake
335 // - keychain changes
336 // o Name conflict dialog dismissal
337 // o Reception of Unix signal (e.g. SIGINFO)
338 // o Idle task processing
339 // If we find that we're getting warnings for any of these categories, and it's not evident
340 // what's causing the problem, we may need to subdivide some categories into finer-grained
341 // sub-categories (e.g. "Idle task processing" covers a pretty broad range of sub-tasks).
342
343 extern int WatchDogReportingThreshold;
344
345 struct CompileTimeAssertionChecks_mDNSMacOSX
346 {
347 // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
348 // other overly-large structures instead of having a pointer to them, can inadvertently
349 // cause structure sizes (and therefore memory usage) to balloon unreasonably.
350 char sizecheck_NetworkInterfaceInfoOSX[(sizeof(NetworkInterfaceInfoOSX) <= 7000) ? 1 : -1];
351 char sizecheck_mDNS_PlatformSupport [(sizeof(mDNS_PlatformSupport) <= 476) ? 1 : -1];
352 };
353
354 #ifdef __cplusplus
355 }
356 #endif
357
358 #endif