]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSMacOSX/mDNSMacOSX.h
mDNSResponder-176.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.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
23
24 Revision 1.78 2008/07/25 22:34:11 mcguire
25 fix sizecheck issues for 64bit
26
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
29
30 Revision 1.76 2008/07/01 01:40:01 mcguire
31 <rdar://problem/5823010> 64-bit fixes
32
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
35
36 Revision 1.74 2007/11/02 20:18:13 cheshire
37 <rdar://problem/5575583> BTMM: Work around keychain notification bug <rdar://problem/5124399>
38
39 Revision 1.73 2007/10/17 18:42:06 cheshire
40 Export SetDomainSecrets so its callable from other files
41
42 Revision 1.72 2007/08/01 16:09:14 cheshire
43 Removed unused NATTraversalInfo substructure from AuthRecord; reduced structure sizecheck values accordingly
44
45 Revision 1.71 2007/07/27 23:57:23 cheshire
46 Added compile-time structure size checks
47
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
51
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
54
55 Revision 1.68 2007/04/24 00:10:15 cheshire
56 Increase WatchDogReportingThreshold to 250ms for customer builds
57
58 Revision 1.67 2007/04/21 21:47:47 cheshire
59 <rdar://problem/4376383> Daemon: Add watchdog timer
60
61 Revision 1.66 2007/04/07 01:01:48 cheshire
62 <rdar://problem/5095167> mDNSResponder periodically blocks in SSLRead
63
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
66
67 Revision 1.64 2007/03/06 23:29:50 cheshire
68 <rdar://problem/4331696> Need to call IONotificationPortDestroy on shutdown
69
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
72
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)
76
77 Revision 1.61 2006/08/14 23:24:40 cheshire
78 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
79
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"
83
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).
90
91 Revision 1.58 2006/07/22 06:08:29 cheshire
92 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
93 Further changes
94
95 Revision 1.57 2006/07/22 03:43:26 cheshire
96 <rdar://problem/4049048> Convert mDNSResponder to use kqueue
97
98 Revision 1.56 2006/07/05 23:37:26 cheshire
99 Remove unused LegacyNATInit/LegacyNATDestroy declarations
100
101 Revision 1.55 2006/06/29 05:33:30 cheshire
102 <rdar://problem/4607043> mDNSResponder conditional compilation options
103
104 Revision 1.54 2006/03/19 03:27:49 cheshire
105 <rdar://problem/4118624> Suppress "interface flapping" logic for loopback
106
107 Revision 1.53 2006/03/19 02:00:09 cheshire
108 <rdar://problem/4073825> Improve logic for delaying packets after repeated interface transitions
109
110 Revision 1.52 2006/01/05 21:41:49 cheshire
111 <rdar://problem/4108164> Reword "mach_absolute_time went backwards" dialog
112
113 */
114
115 #ifndef __mDNSOSX_h
116 #define __mDNSOSX_h
117
118 #ifdef __cplusplus
119 extern "C" {
120 #endif
121
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
127
128 typedef struct NetworkInterfaceInfoOSX_struct NetworkInterfaceInfoOSX;
129
130 typedef void (*KQueueEventCallback)(int fd, short filter, void *context);
131 typedef struct
132 {
133 KQueueEventCallback KQcallback;
134 void *KQcontext;
135 const char const *KQtask; // For debugging messages
136 } KQueueEntry;
137
138 typedef struct
139 {
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
142 mDNS *m;
143 int sktv4;
144 KQueueEntry kqsv4;
145 int sktv6;
146 KQueueEntry kqsv6;
147 int *closeFlag;
148 } KQSocketSet;
149
150 struct UDPSocket_struct
151 {
152 KQSocketSet ss; // First field of KQSocketSet has to be mDNSIPPort -- mDNSCore requires every UDPSocket_struct to begin with mDNSIPPort port
153 };
154
155 struct NetworkInterfaceInfoOSX_struct
156 {
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
173 u_short sa_family;
174 };
175
176 struct mDNS_PlatformSupport_struct
177 {
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
182 mDNSs32 NotifyUser;
183 mDNSs32 HostNameConflict; // Time we experienced conflict on our link-local host name
184 mDNSs32 NetworkChanged;
185
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;
192
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;
203 };
204
205 extern int KQueueFD;
206
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);
211
212 extern int KQueueSet(int fd, u_short flags, short filter, const KQueueEntry *const entryRef);
213
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);
218
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
226 // - sleep/wake
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).
234
235 #if LogAllOperations
236 #define WatchDogReportingThreshold 50
237 #else
238 #define WatchDogReportingThreshold 250
239 #endif
240
241 struct CompileTimeAssertionChecks_mDNSMacOSX
242 {
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];
248 };
249
250 #ifdef __cplusplus
251 }
252 #endif
253
254 #endif