1 /* -*- Mode: C; tab-width: 4 -*-
3 * Copyright (c) 2002-2003 Apple Computer, Inc. All rights reserved.
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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 Change History (most recent first):
19 $Log: mDNSMacOSX.h,v $
20 Revision 1.79 2008/07/30 00:55:56 mcguire
21 <rdar://problem/3988320> Should use randomized source ports and transaction IDs to avoid DNS cache poisoning
22 Additional fixes so that we know when a socket has been closed while in a loop reading from it
24 Revision 1.78 2008/07/25 22:34:11 mcguire
25 fix sizecheck issues for 64bit
27 Revision 1.77 2008/07/24 20:23:04 cheshire
28 <rdar://problem/3988320> Should use randomized source ports and transaction IDs to avoid DNS cache poisoning
30 Revision 1.76 2008/07/01 01:40:01 mcguire
31 <rdar://problem/5823010> 64-bit fixes
33 Revision 1.75 2007/12/14 00:45:21 cheshire
34 Add SleepLimit and SleepCookie, for when we need to delay sleep until TLS/TCP record deregistration completes
36 Revision 1.74 2007/11/02 20:18:13 cheshire
37 <rdar://problem/5575583> BTMM: Work around keychain notification bug <rdar://problem/5124399>
39 Revision 1.73 2007/10/17 18:42:06 cheshire
40 Export SetDomainSecrets so its callable from other files
42 Revision 1.72 2007/08/01 16:09:14 cheshire
43 Removed unused NATTraversalInfo substructure from AuthRecord; reduced structure sizecheck values accordingly
45 Revision 1.71 2007/07/27 23:57:23 cheshire
46 Added compile-time structure size checks
48 Revision 1.70 2007/07/11 02:55:50 cheshire
49 <rdar://problem/5303807> Register IPv6-only hostname and don't create port mappings for AutoTunnel services
50 Remove unused DefaultRegDomainChanged/DefaultBrowseDomainChanged
52 Revision 1.69 2007/05/08 00:56:17 cheshire
53 <rdar://problem/4118503> Share single socket instead of creating separate socket for each active interface
55 Revision 1.68 2007/04/24 00:10:15 cheshire
56 Increase WatchDogReportingThreshold to 250ms for customer builds
58 Revision 1.67 2007/04/21 21:47:47 cheshire
59 <rdar://problem/4376383> Daemon: Add watchdog timer
61 Revision 1.66 2007/04/07 01:01:48 cheshire
62 <rdar://problem/5095167> mDNSResponder periodically blocks in SSLRead
64 Revision 1.65 2007/03/07 02:50:50 cheshire
65 <rdar://problem/4574528> Name conflict dialog doesn't appear if Bonjour is persistantly unable to find an available hostname
67 Revision 1.64 2007/03/06 23:29:50 cheshire
68 <rdar://problem/4331696> Need to call IONotificationPortDestroy on shutdown
70 Revision 1.63 2007/02/07 19:32:00 cheshire
71 <rdar://problem/4980353> All mDNSResponder components should contain version strings in SCCS-compatible format
73 Revision 1.62 2007/01/05 08:30:49 cheshire
74 Trim excessive "$Log" checkin history from before 2006
75 (checkin history still available via "cvs log ..." of course)
77 Revision 1.61 2006/08/14 23:24:40 cheshire
78 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
80 Revision 1.60 2006/07/27 03:24:35 cheshire
81 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
82 Further refinement: Declare KQueueEntry parameter "const"
84 Revision 1.59 2006/07/27 02:59:25 cheshire
85 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
86 Further refinements: CFRunLoop thread needs to explicitly wake the kqueue thread
87 after releasing BigMutex, in case actions it took have resulted in new work for the
88 kqueue thread (e.g. NetworkChanged events may result in the kqueue thread having to
89 add new active interfaces to its list, and consequently schedule queries to be sent).
91 Revision 1.58 2006/07/22 06:08:29 cheshire
92 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
95 Revision 1.57 2006/07/22 03:43:26 cheshire
96 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
98 Revision 1.56 2006/07/05 23:37:26 cheshire
99 Remove unused LegacyNATInit/LegacyNATDestroy declarations
101 Revision 1.55 2006/06/29 05:33:30 cheshire
102 <rdar://problem/4607043> mDNSResponder conditional compilation options
104 Revision 1.54 2006/03/19 03:27:49 cheshire
105 <rdar://problem/4118624> Suppress "interface flapping" logic for loopback
107 Revision 1.53 2006/03/19 02:00:09 cheshire
108 <rdar://problem/4073825> Improve logic for delaying packets after repeated interface transitions
110 Revision 1.52 2006/01/05 21:41:49 cheshire
111 <rdar://problem/4108164> Reword "mach_absolute_time went backwards" dialog
122 #include <SystemConfiguration/SystemConfiguration.h>
123 #include <IOKit/pwr_mgt/IOPMLib.h>
124 #include <sys/socket.h>
125 #include <netinet/in.h>
126 #include "mDNSEmbeddedAPI.h" // for domain name structure
128 typedef struct NetworkInterfaceInfoOSX_struct NetworkInterfaceInfoOSX
;
130 typedef void (*KQueueEventCallback
)(int fd
, short filter
, void *context
);
133 KQueueEventCallback KQcallback
;
135 const char const *KQtask
; // For debugging messages
140 mDNSIPPort port
; // MUST BE FIRST FIELD -- UDPSocket_struct begins with a KQSocketSet,
141 // and mDNSCore requires every UDPSocket_struct to begin with a mDNSIPPort port
150 struct UDPSocket_struct
152 KQSocketSet ss
; // First field of KQSocketSet has to be mDNSIPPort -- mDNSCore requires every UDPSocket_struct to begin with mDNSIPPort port
155 struct NetworkInterfaceInfoOSX_struct
157 NetworkInterfaceInfo ifinfo
; // MUST be the first element in this structure
158 NetworkInterfaceInfoOSX
*next
;
159 mDNSu32 Exists
; // 1 = currently exists in getifaddrs list; 0 = doesn't
160 // 2 = exists, but McastTxRx state changed
161 mDNSs32 AppearanceTime
; // Time this interface appeared most recently in getifaddrs list
162 // i.e. the first time an interface is seen, AppearanceTime is set.
163 // If an interface goes away temporarily and then comes back then
164 // AppearanceTime is updated to the time of the most recent appearance.
165 mDNSs32 LastSeen
; // If Exists==0, last time this interface appeared in getifaddrs list
166 mDNSBool Flashing
; // Set if interface appeared for less than 60 seconds and then vanished
167 mDNSBool Occulting
; // Set if interface vanished for less than 60 seconds and then came back
168 char *ifa_name
; // Memory for this is allocated using malloc
169 unsigned int ifa_flags
;
170 struct in_addr ifa_v4addr
;
171 mDNSu32 scope_id
; // interface index / IPv6 scope ID
172 mDNSEthAddr BSSID
; // BSSID of 802.11 base station, if applicable
176 struct mDNS_PlatformSupport_struct
178 NetworkInterfaceInfoOSX
*InterfaceList
;
179 KQSocketSet permanentsockets
;
180 domainlabel userhostlabel
; // The hostlabel as it was set in System Preferences the last time we looked
181 domainlabel usernicelabel
; // The nicelabel as it was set in System Preferences the last time we looked
183 mDNSs32 HostNameConflict
; // Time we experienced conflict on our link-local host name
184 mDNSs32 NetworkChanged
;
186 // KeyChain frequently fails to notify clients of change events. To work around this
187 // we set a timer and periodically poll to detect if any changes have occurred.
188 // Without this Back To My Mac just does't work for a large number of users.
189 // See <rdar://problem/5124399> Not getting Keychain Changed events when enabling BTMM
190 mDNSs32 KeyChainBugTimer
;
191 mDNSs32 KeyChainBugInterval
;
193 SCDynamicStoreRef Store
;
194 CFRunLoopSourceRef StoreRLS
;
195 IONotificationPortRef PowerPortRef
;
196 io_connect_t PowerConnection
;
197 io_object_t PowerNotifier
;
198 mDNSs32 SleepLimit
; // Set when we get kIOMessageSystemWillSleep notification
199 long SleepCookie
; // Cookie we need to pass to IOAllowPowerChange()
200 pthread_mutex_t BigMutex
;
201 mDNSs32 BigMutexStartTime
;
202 int WakeKQueueLoopFD
;
207 extern void NotifyOfElusiveBug(const char *title
, const char *msg
); // Both strings are UTF-8 text
208 extern void SetDomainSecrets(mDNS
*m
);
209 extern void mDNSMacOSXNetworkChanged(mDNS
*const m
);
210 extern int mDNSMacOSXSystemBuildNumber(char *HINFO_SWstring
);
212 extern int KQueueSet(int fd
, u_short flags
, short filter
, const KQueueEntry
*const entryRef
);
214 // When events are processed on the non-kqueue thread (i.e. CFRunLoop notifications like Sleep/Wake,
215 // Interface changes, Keychain changes, etc.) they must use KQueueLock/KQueueUnlock to lock out the kqueue thread
216 extern void KQueueLock(mDNS
*const m
);
217 extern void KQueueUnlock(mDNS
*const m
, const char const *task
);
219 // If any event takes more than WatchDogReportingThreshold milliseconds to be processed, we log a warning message
220 // General event categories are:
221 // o Mach client request initiated / terminated
222 // o UDS client request
223 // o Handling UDP packets received from the network
224 // o Environmental change events:
225 // - network interface changes
227 // - keychain changes
228 // o Name conflict dialog dismissal
229 // o Reception of Unix signal (e.g. SIGINFO)
230 // o Idle task processing
231 // If we find that we're getting warnings for any of these categories, and it's not evident
232 // what's causing the problem, we may need to subdivide some categories into finer-grained
233 // sub-categories (e.g. "Idle task processing" covers a pretty broad range of sub-tasks).
236 #define WatchDogReportingThreshold 50
238 #define WatchDogReportingThreshold 250
241 struct CompileTimeAssertionChecks_mDNSMacOSX
243 // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
244 // other overly-large structures instead of having a pointer to them, can inadvertently
245 // cause structure sizes (and therefore memory usage) to balloon unreasonably.
246 char sizecheck_NetworkInterfaceInfoOSX
[(sizeof(NetworkInterfaceInfoOSX
) <= 4456) ? 1 : -1];
247 char sizecheck_mDNS_PlatformSupport
[(sizeof(mDNS_PlatformSupport
) <= 368) ? 1 : -1];