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