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.74 2007/11/02 20:18:13 cheshire
21 <rdar://problem/5575583> BTMM: Work around keychain notification bug <rdar://problem/5124399>
23 Revision 1.73 2007/10/17 18:42:06 cheshire
24 Export SetDomainSecrets so its callable from other files
26 Revision 1.72 2007/08/01 16:09:14 cheshire
27 Removed unused NATTraversalInfo substructure from AuthRecord; reduced structure sizecheck values accordingly
29 Revision 1.71 2007/07/27 23:57:23 cheshire
30 Added compile-time structure size checks
32 Revision 1.70 2007/07/11 02:55:50 cheshire
33 <rdar://problem/5303807> Register IPv6-only hostname and don't create port mappings for AutoTunnel services
34 Remove unused DefaultRegDomainChanged/DefaultBrowseDomainChanged
36 Revision 1.69 2007/05/08 00:56:17 cheshire
37 <rdar://problem/4118503> Share single socket instead of creating separate socket for each active interface
39 Revision 1.68 2007/04/24 00:10:15 cheshire
40 Increase WatchDogReportingThreshold to 250ms for customer builds
42 Revision 1.67 2007/04/21 21:47:47 cheshire
43 <rdar://problem/4376383> Daemon: Add watchdog timer
45 Revision 1.66 2007/04/07 01:01:48 cheshire
46 <rdar://problem/5095167> mDNSResponder periodically blocks in SSLRead
48 Revision 1.65 2007/03/07 02:50:50 cheshire
49 <rdar://problem/4574528> Name conflict dialog doesn't appear if Bonjour is persistantly unable to find an available hostname
51 Revision 1.64 2007/03/06 23:29:50 cheshire
52 <rdar://problem/4331696> Need to call IONotificationPortDestroy on shutdown
54 Revision 1.63 2007/02/07 19:32:00 cheshire
55 <rdar://problem/4980353> All mDNSResponder components should contain version strings in SCCS-compatible format
57 Revision 1.62 2007/01/05 08:30:49 cheshire
58 Trim excessive "$Log" checkin history from before 2006
59 (checkin history still available via "cvs log ..." of course)
61 Revision 1.61 2006/08/14 23:24:40 cheshire
62 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
64 Revision 1.60 2006/07/27 03:24:35 cheshire
65 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
66 Further refinement: Declare KQueueEntry parameter "const"
68 Revision 1.59 2006/07/27 02:59:25 cheshire
69 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
70 Further refinements: CFRunLoop thread needs to explicitly wake the kqueue thread
71 after releasing BigMutex, in case actions it took have resulted in new work for the
72 kqueue thread (e.g. NetworkChanged events may result in the kqueue thread having to
73 add new active interfaces to its list, and consequently schedule queries to be sent).
75 Revision 1.58 2006/07/22 06:08:29 cheshire
76 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
79 Revision 1.57 2006/07/22 03:43:26 cheshire
80 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
82 Revision 1.56 2006/07/05 23:37:26 cheshire
83 Remove unused LegacyNATInit/LegacyNATDestroy declarations
85 Revision 1.55 2006/06/29 05:33:30 cheshire
86 <rdar://problem/4607043> mDNSResponder conditional compilation options
88 Revision 1.54 2006/03/19 03:27:49 cheshire
89 <rdar://problem/4118624> Suppress "interface flapping" logic for loopback
91 Revision 1.53 2006/03/19 02:00:09 cheshire
92 <rdar://problem/4073825> Improve logic for delaying packets after repeated interface transitions
94 Revision 1.52 2006/01/05 21:41:49 cheshire
95 <rdar://problem/4108164> Reword "mach_absolute_time went backwards" dialog
106 #include <SystemConfiguration/SystemConfiguration.h>
107 #include <IOKit/pwr_mgt/IOPMLib.h>
108 #include <sys/socket.h>
109 #include <netinet/in.h>
110 #include "mDNSEmbeddedAPI.h" // for domain name structure
112 typedef struct NetworkInterfaceInfoOSX_struct NetworkInterfaceInfoOSX
;
114 typedef void (*KQueueEventCallback
)(int fd
, short filter
, void *context
);
117 KQueueEventCallback KQcallback
;
119 const char const *KQtask
; // For debugging messages
131 struct NetworkInterfaceInfoOSX_struct
133 NetworkInterfaceInfo ifinfo
; // MUST be the first element in this structure
134 NetworkInterfaceInfoOSX
*next
;
135 mDNSu32 Exists
; // 1 = currently exists in getifaddrs list; 0 = doesn't
136 // 2 = exists, but McastTxRx state changed
137 mDNSs32 AppearanceTime
; // Time this interface appeared most recently in getifaddrs list
138 // i.e. the first time an interface is seen, AppearanceTime is set.
139 // If an interface goes away temporarily and then comes back then
140 // AppearanceTime is updated to the time of the most recent appearance.
141 mDNSs32 LastSeen
; // If Exists==0, last time this interface appeared in getifaddrs list
142 mDNSBool Flashing
; // Set if interface appeared for less than 60 seconds and then vanished
143 mDNSBool Occulting
; // Set if interface vanished for less than 60 seconds and then came back
144 char *ifa_name
; // Memory for this is allocated using malloc
145 unsigned int ifa_flags
;
146 struct in_addr ifa_v4addr
;
147 mDNSu32 scope_id
; // interface index / IPv6 scope ID
148 mDNSEthAddr BSSID
; // BSSID of 802.11 base station, if applicable
152 struct mDNS_PlatformSupport_struct
154 NetworkInterfaceInfoOSX
*InterfaceList
;
155 KQSocketSet permanentsockets
;
156 domainlabel userhostlabel
; // The hostlabel as it was set in System Preferences the last time we looked
157 domainlabel usernicelabel
; // The nicelabel as it was set in System Preferences the last time we looked
159 mDNSs32 HostNameConflict
; // Time we experienced conflict on our link-local host name
160 mDNSs32 NetworkChanged
;
162 // KeyChain frequently fails to notify clients of change events. To work around this
163 // we set a timer and periodically poll to detect if any changes have occurred.
164 // Without this Back To My Mac just does't work for a large number of users.
165 // See <rdar://problem/5124399> Not getting Keychain Changed events when enabling BTMM
166 mDNSs32 KeyChainBugTimer
;
167 mDNSs32 KeyChainBugInterval
;
169 SCDynamicStoreRef Store
;
170 CFRunLoopSourceRef StoreRLS
;
171 IONotificationPortRef PowerPortRef
;
172 io_connect_t PowerConnection
;
173 io_object_t PowerNotifier
;
174 pthread_mutex_t BigMutex
;
175 mDNSs32 BigMutexStartTime
;
176 int WakeKQueueLoopFD
;
181 extern void NotifyOfElusiveBug(const char *title
, const char *msg
); // Both strings are UTF-8 text
182 extern void SetDomainSecrets(mDNS
*m
);
183 extern void mDNSMacOSXNetworkChanged(mDNS
*const m
);
184 extern int mDNSMacOSXSystemBuildNumber(char *HINFO_SWstring
);
186 extern int KQueueSet(int fd
, u_short flags
, short filter
, const KQueueEntry
*const entryRef
);
188 // When events are processed on the non-kqueue thread (i.e. CFRunLoop notifications like Sleep/Wake,
189 // Interface changes, Keychain changes, etc.) they must use KQueueLock/KQueueUnlock to lock out the kqueue thread
190 extern void KQueueLock(mDNS
*const m
);
191 extern void KQueueUnlock(mDNS
*const m
, const char const *task
);
193 // If any event takes more than WatchDogReportingThreshold milliseconds to be processed, we log a warning message
194 // General event categories are:
195 // o Mach client request initiated / terminated
196 // o UDS client request
197 // o Handling UDP packets received from the network
198 // o Environmental change events:
199 // - network interface changes
201 // - keychain changes
202 // o Name conflict dialog dismissal
203 // o Reception of Unix signal (e.g. SIGINFO)
204 // o Idle task processing
205 // If we find that we're getting warnings for any of these categories, and it's not evident
206 // what's causing the problem, we may need to subdivide some categories into finer-grained
207 // sub-categories (e.g. "Idle task processing" covers a pretty broad range of sub-tasks).
210 #define WatchDogReportingThreshold 50
212 #define WatchDogReportingThreshold 250
215 struct CompileTimeAssertionChecks_mDNSMacOSX
217 // Check our structures are reasonable sizes. Including overly-large buffers, or embedding
218 // other overly-large structures instead of having a pointer to them, can inadvertently
219 // cause structure sizes (and therefore memory usage) to balloon unreasonably.
220 char sizecheck_NetworkInterfaceInfoOSX
[(sizeof(NetworkInterfaceInfoOSX
) <= 4100) ? 1 : -1];
221 char sizecheck_mDNS_PlatformSupport
[(sizeof(mDNS_PlatformSupport
) <= 260) ? 1 : -1];