]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/uDNS.h
bf7918d36729069ff470817a84e84cd84d6dadce
[apple/mdnsresponder.git] / mDNSCore / uDNS.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: uDNS.h,v $
20 Revision 1.79 2007/09/20 01:13:19 cheshire
21 Export CacheGroupForName so it's callable from other files
22
23 Revision 1.78 2007/09/14 21:26:09 cheshire
24 <rdar://problem/5482627> BTMM: Need to manually avoid port conflicts when using UPnP gateways
25
26 Revision 1.77 2007/09/12 23:03:08 cheshire
27 <rdar://problem/5476978> DNSServiceNATPortMappingCreate callback not giving correct interface index
28
29 Revision 1.76 2007/09/12 19:22:19 cheshire
30 Variable renaming in preparation for upcoming fixes e.g. priv/pub renamed to intport/extport
31 Made NAT Traversal packet handlers take typed data instead of anonymous "mDNSu8 *" byte pointers
32
33 Revision 1.75 2007/08/28 23:53:21 cheshire
34 Rename serviceRegistrationCallback -> ServiceRegistrationZoneDataComplete
35
36 Revision 1.74 2007/08/24 00:15:20 cheshire
37 Renamed GetAuthInfoForName() to GetAuthInfoForName_internal() to make it clear that it may only be called with the lock held
38
39 Revision 1.73 2007/08/01 03:09:22 cheshire
40 <rdar://problem/5344587> BTMM: Create NAT port mapping for autotunnel port
41
42 Revision 1.72 2007/08/01 00:04:13 cheshire
43 <rdar://problem/5261696> Crash in tcpKQSocketCallback
44 Half-open TCP connections were not being cancelled properly
45
46 Revision 1.71 2007/07/30 23:31:26 cheshire
47 Code for respecting TTL received in uDNS responses should exclude LLQ-type responses
48
49 Revision 1.70 2007/07/27 20:52:29 cheshire
50 Made uDNS_recvLLQResponse() return tri-state result: LLQ_Not, LLQ_First, or LLQ_Events
51
52 Revision 1.69 2007/07/27 19:30:40 cheshire
53 Changed mDNSQuestionCallback parameter from mDNSBool to QC_result,
54 to properly reflect tri-state nature of the possible responses
55
56 Revision 1.68 2007/07/27 18:38:56 cheshire
57 Rename "uDNS_CheckQuery" to more informative "uDNS_CheckCurrentQuestion"
58
59 Revision 1.67 2007/07/20 23:11:12 cheshire
60 Fix code layout
61
62 Revision 1.66 2007/07/16 23:54:48 cheshire
63 <rdar://problem/5338850> Crash when removing or changing DNS keys
64
65 Revision 1.65 2007/07/16 20:14:22 vazquez
66 <rdar://problem/3867231> LegacyNATTraversal: Need complete rewrite
67
68 Revision 1.64 2007/07/11 02:53:36 cheshire
69 <rdar://problem/5303807> Register IPv6-only hostname and don't create port mappings for AutoTunnel services
70 Add ServiceRecordSet parameter in GetServiceTarget
71
72 Revision 1.63 2007/06/29 00:09:24 vazquez
73 <rdar://problem/5301908> Clean up NAT state machine (necessary for 6 other fixes)
74
75 Revision 1.62 2007/05/14 23:53:00 cheshire
76 Export mDNS_StartQuery_internal and mDNS_StopQuery_internal so they can be called from uDNS.c
77
78 Revision 1.61 2007/05/07 20:43:45 cheshire
79 <rdar://problem/4241419> Reduce the number of queries and announcements
80
81 Revision 1.60 2007/05/04 21:46:10 cheshire
82 Get rid of uDNS_Close (synonym for uDNS_Sleep)
83
84 Revision 1.59 2007/05/03 22:40:38 cheshire
85 <rdar://problem/4669229> mDNSResponder ignores bogus null target in SRV record
86
87 Revision 1.58 2007/05/02 22:21:33 cheshire
88 <rdar://problem/5167331> RegisterRecord and RegisterService need to cancel StartGetZoneData
89
90 Revision 1.57 2007/04/27 19:28:02 cheshire
91 Any code that calls StartGetZoneData needs to keep a handle to the structure, so
92 it can cancel it if necessary. (First noticed as a crash in Apple Remote Desktop
93 -- it would start a query and then quickly cancel it, and then when
94 StartGetZoneData completed, it had a dangling pointer and crashed.)
95
96 Revision 1.56 2007/04/25 02:14:38 cheshire
97 <rdar://problem/4246187> uDNS: Identical client queries should reference a single shared core query
98 Additional fixes to make LLQs work properly
99
100 Revision 1.55 2007/04/22 06:02:03 cheshire
101 <rdar://problem/4615977> Query should immediately return failure when no server
102
103 Revision 1.54 2007/04/04 21:48:53 cheshire
104 <rdar://problem/4720694> Combine unicast authoritative answer list with multicast list
105
106 Revision 1.53 2007/03/28 15:56:37 cheshire
107 <rdar://problem/5085774> Add listing of NAT port mapping and GetAddrInfo requests in SIGINFO output
108
109 Revision 1.52 2007/02/28 01:44:26 cheshire
110 <rdar://problem/5027863> Byte order bugs in uDNS.c, uds_daemon.c, dnssd_clientstub.c
111
112 Revision 1.51 2007/01/27 03:34:27 cheshire
113 Made GetZoneData use standard queries (and cached results);
114 eliminated GetZoneData_Callback() packet response handler
115
116 Revision 1.50 2007/01/19 21:17:32 cheshire
117 StartLLQPolling needs to call SetNextQueryTime() to cause query to be done in a timely fashion
118
119 Revision 1.49 2007/01/17 21:35:31 cheshire
120 For clarity, rename zoneData_t field "isPrivate" to "zonePrivate"
121
122 Revision 1.48 2007/01/10 22:51:57 cheshire
123 <rdar://problem/4917539> Add support for one-shot private queries as well as long-lived private queries
124
125 Revision 1.47 2007/01/05 08:30:43 cheshire
126 Trim excessive "$Log" checkin history from before 2006
127 (checkin history still available via "cvs log ..." of course)
128
129 Revision 1.46 2007/01/04 01:41:47 cheshire
130 Use _dns-update-tls/_dns-query-tls/_dns-llq-tls instead of creating a new "_tls" subdomain
131
132 Revision 1.45 2006/12/22 20:59:49 cheshire
133 <rdar://problem/4742742> Read *all* DNS keys from keychain,
134 not just key for the system-wide default registration domain
135
136 Revision 1.44 2006/12/20 04:07:35 cheshire
137 Remove uDNS_info substructure from AuthRecord_struct
138
139 Revision 1.43 2006/12/16 01:58:32 cheshire
140 <rdar://problem/4720673> uDNS: Need to start caching unicast records
141
142 Revision 1.42 2006/11/30 23:07:56 herscher
143 <rdar://problem/4765644> uDNS: Sync up with Lighthouse changes for Private DNS
144
145 Revision 1.41 2006/11/18 05:01:30 cheshire
146 Preliminary support for unifying the uDNS and mDNS code,
147 including caching of uDNS answers
148
149 Revision 1.40 2006/11/10 07:44:04 herscher
150 <rdar://problem/4825493> Fix Daemon locking failures while toggling BTMM
151
152 Revision 1.39 2006/10/20 05:35:05 herscher
153 <rdar://problem/4720713> uDNS: Merge unicast active question list with multicast list.
154
155 Revision 1.38 2006/09/26 01:54:02 herscher
156 <rdar://problem/4245016> NAT Port Mapping API (for both NAT-PMP and UPnP Gateway Protocol)
157
158 Revision 1.37 2006/09/15 21:20:15 cheshire
159 Remove uDNS_info substructure from mDNS_struct
160
161 Revision 1.36 2006/08/14 23:24:23 cheshire
162 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
163
164 Revision 1.35 2006/07/30 05:45:36 cheshire
165 <rdar://problem/4304215> Eliminate MIN_UCAST_PERIODIC_EXEC
166
167 Revision 1.34 2006/07/15 02:01:29 cheshire
168 <rdar://problem/4472014> Add Private DNS client functionality to mDNSResponder
169 Fix broken "empty string" browsing
170
171 Revision 1.33 2006/07/05 22:53:28 cheshire
172 <rdar://problem/4472014> Add Private DNS client functionality to mDNSResponder
173
174 */
175
176 #ifndef __UDNS_H_
177 #define __UDNS_H_
178
179 #include "mDNSEmbeddedAPI.h"
180 #include "DNSCommon.h"
181
182 #ifdef __cplusplus
183 extern "C" {
184 #endif
185
186 #define RESTART_GOODBYE_DELAY (6 * mDNSPlatformOneSecond) // delay after restarting LLQ before nuking previous known answers (avoids flutter if we restart before we have networking up)
187 #define INIT_UCAST_POLL_INTERVAL (3 * mDNSPlatformOneSecond) // this interval is used after send failures on network transitions
188 // which typically heal quickly, so we start agressively and exponentially back off
189 #define MAX_UCAST_POLL_INTERVAL (60 * 60 * mDNSPlatformOneSecond)
190 //#define MAX_UCAST_POLL_INTERVAL (1 * 60 * mDNSPlatformOneSecond)
191 #define LLQ_POLL_INTERVAL (15 * 60 * mDNSPlatformOneSecond) // Polling interval for zones w/ an advertised LLQ port (ie not static zones) if LLQ fails due to NAT, etc.
192 #define RESPONSE_WINDOW (60 * mDNSPlatformOneSecond) // require server responses within one minute of request
193
194 #define DEFAULT_UPDATE_LEASE 7200
195
196 #define QuestionIntervalStep 3
197 #define QuestionIntervalStep2 (QuestionIntervalStep*QuestionIntervalStep)
198 #define QuestionIntervalStep3 (QuestionIntervalStep*QuestionIntervalStep*QuestionIntervalStep)
199 #define InitialQuestionInterval ((mDNSPlatformOneSecond + QuestionIntervalStep-1) / QuestionIntervalStep)
200
201 // Entry points into unicast-specific routines
202
203 extern void startLLQHandshakeCallback(mDNS *const m, mStatus err, const ZoneData *zoneInfo);
204
205 extern void uDNS_StopLongLivedQuery(mDNS *const m, DNSQuestion *const question);
206
207 extern void uDNS_Sleep(mDNS *const m);
208 extern void uDNS_Wake(mDNS *const m);
209
210 // uDNS_UpdateRecord
211 // following fields must be set, and the update validated, upon entry.
212 // rr->NewRData
213 // rr->newrdlength
214 // rr->UpdateCallback
215
216 extern mStatus uDNS_AddRecordToService(mDNS *const m, ServiceRecordSet *sr, ExtraResourceRecord *extra);
217 extern mStatus uDNS_UpdateRecord(mDNS *m, AuthRecord *rr);
218
219 extern void SetNextQueryTime(mDNS *const m, const DNSQuestion *const q);
220 extern CacheGroup *CacheGroupForName(const mDNS *const m, const mDNSu32 slot, const mDNSu32 namehash, const domainname *const name);
221 extern mStatus mDNS_Register_internal(mDNS *const m, AuthRecord *const rr);
222 // mDNS_Dereg_normal is used for most calls to mDNS_Deregister_internal
223 // mDNS_Dereg_conflict is used to indicate that this record is being forcibly deregistered because of a conflict
224 // mDNS_Dereg_repeat is used when cleaning up, for records that may have already been forcibly deregistered
225 typedef enum { mDNS_Dereg_normal, mDNS_Dereg_conflict, mDNS_Dereg_repeat } mDNS_Dereg_type;
226 extern mStatus mDNS_Deregister_internal(mDNS *const m, AuthRecord *const rr, mDNS_Dereg_type drt);
227 extern mStatus mDNS_StartQuery_internal(mDNS *const m, DNSQuestion *const question);
228 extern mStatus mDNS_StopQuery_internal(mDNS *const m, DNSQuestion *const question);
229 extern mStatus mDNS_StartNATOperation_internal(mDNS *const m, NATTraversalInfo *traversal);
230
231 extern void RecordRegistrationCallback(mDNS *const m, mStatus err, const ZoneData *zoneData);
232 extern void GetZoneData_QuestionCallback(mDNS *const m, DNSQuestion *question, const ResourceRecord *const answer, QC_result AddRecord);
233 extern mStatus uDNS_DeregisterRecord(mDNS *const m, AuthRecord *const rr);
234
235 extern void ServiceRegistrationZoneDataComplete(mDNS *const m, mStatus err, const ZoneData *result);
236 extern const domainname *GetServiceTarget(mDNS *m, ServiceRecordSet *srs);
237 extern mStatus uDNS_DeregisterService(mDNS *const m, ServiceRecordSet *srs);
238
239 extern void uDNS_CheckCurrentQuestion(mDNS *const m);
240
241 // integer fields of msg header must be in HOST byte order before calling this routine
242 extern void uDNS_ReceiveMsg(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
243 const mDNSAddr *const srcaddr, const mDNSIPPort srcport);
244
245 // returns time of next scheduled event
246 extern void uDNS_Execute(mDNS *const m);
247
248 extern mStatus uDNS_SetupDNSConfig(mDNS *const m);
249 extern mStatus uDNS_RegisterSearchDomains(mDNS *const m);
250
251 typedef enum
252 {
253 uDNS_LLQ_Not = 0, // Normal uDNS answer: Flush any stale records from cache, and respect record TTL
254 uDNS_LLQ_Poll, // LLQ Poll: Flush any stale records from cache, but assume TTL is 2 x poll interval
255 uDNS_LLQ_Setup, // LLQ Initial answer packet: Flush any stale records from cache; assume TTL is 2 x LLQ refresh interval
256 uDNS_LLQ_Events // LLQ event packet: don't flush cache; assume TTL is 2 x LLQ refresh interval
257 } uDNS_LLQType;
258
259 extern uDNS_LLQType uDNS_recvLLQResponse(mDNS *const m, const DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr, const mDNSIPPort srcport);
260 extern DomainAuthInfo *GetAuthInfoForName_internal(mDNS *m, const domainname *const name);
261 extern void DisposeTCPConn(struct tcpInfo_t *tcp);
262
263 // NAT traversal
264 extern void uDNS_ReceiveNATPMPPacket(mDNS *m, const mDNSInterfaceID InterfaceID, mDNSu8 *pkt, mDNSu16 len); // Called for each received NAT-PMP packet
265 extern void natTraversalHandleAddressReply(mDNS *const m, mDNSu16 err, mDNSv4Addr ExtAddr);
266 extern void natTraversalHandlePortMapReply(mDNS *const m, NATTraversalInfo *n, const mDNSInterfaceID InterfaceID, mDNSu16 err, mDNSIPPort extport, mDNSu32 lease);
267
268 #ifdef __cplusplus
269 }
270 #endif
271
272 #endif // __UDNS_H_