]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/DNSCommon.h
mDNSResponder-214.3.tar.gz
[apple/mdnsresponder.git] / mDNSCore / DNSCommon.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: DNSCommon.h,v $
20 svn merge: Revision 1.75 2009/07/21 23:35:01 cheshire
21 <rdar://problem/6434656> Sleep Proxy: Put owner OPT records in multicast announcements to avoid conflicts
22 Added PutRR_OS macros to put a ResourceRecord while taking into account the space needed to add an OWNER option at the end
23
24 Revision 1.73 2009/04/24 00:28:05 cheshire
25 <rdar://problem/3476350> Return negative answers when host knows authoritatively that no answer exists
26 Added definitions for RRTypeAnswersQuestionType/RRAssertsNonexistence/AnyTypeRecordAnswersQuestion
27
28 Revision 1.72 2009/04/01 21:12:56 herscher
29 <rdar://problem/5925472> Current Bonjour code does not compile on Windows
30
31 Revision 1.71 2009/04/01 17:50:10 mcguire
32 cleanup mDNSRandom
33
34 Revision 1.70 2009/03/04 00:40:12 cheshire
35 Updated DNS server error codes to be more consistent with definitions at
36 <http://www.iana.org/assignments/dns-parameters>
37
38 Revision 1.69 2008/11/26 20:57:37 cheshire
39 For consistency with other similar macros, renamed mdnsIsDigit/mdnsIsLetter/mdnsValidHostChar
40 to mDNSIsDigit/mDNSIsLetter/mDNSValidHostChar
41
42 Revision 1.68 2008/11/14 21:56:31 cheshire
43 Moved debugging routine ShowTaskSchedulingError() from daemon.c into DNSCommon.c
44
45 Revision 1.67 2008/11/13 19:05:09 cheshire
46 Added definition of LocateOptRR()
47
48 Revision 1.66 2008/10/22 19:56:54 cheshire
49 Removed unused SameRData() macro -- it duplicates the functionality of IdenticalSameNameRecord()
50
51 Revision 1.65 2008/10/20 15:39:20 cheshire
52 Group "#define PutResourceRecord ..." with related definitions
53
54 Revision 1.64 2008/10/08 01:03:33 cheshire
55 Change GetFirstActiveInterface() so the NetworkInterfaceInfo it returns is not "const"
56
57 Revision 1.63 2008/09/23 02:30:07 cheshire
58 Get rid of PutResourceRecordCappedTTL()
59
60 Revision 1.62 2008/09/23 02:26:09 cheshire
61 Don't need to export putEmptyResourceRecord (it's only used from DNSCommon.c)
62
63 Revision 1.61 2008/08/13 00:47:53 mcguire
64 Handle failures when packet logging
65
66 Revision 1.60 2008/07/24 20:23:03 cheshire
67 <rdar://problem/3988320> Should use randomized source ports and transaction IDs to avoid DNS cache poisoning
68
69 Revision 1.59 2008/03/14 19:58:38 mcguire
70 <rdar://problem/5500969> BTMM: Need ability to identify version of mDNSResponder client
71 Make sure we add the record when sending LLQ refreshes
72
73 Revision 1.58 2008/03/06 21:26:10 cheshire
74 Moved duplicated STRINGIFY macro from individual C files to DNSCommon.h
75
76 Revision 1.57 2007/12/13 20:20:17 cheshire
77 Minor efficiency tweaks -- converted IdenticalResourceRecord, IdenticalSameNameRecord, and
78 SameRData from functions to macros, which allows the code to be inlined (the compiler can't
79 inline a function defined in a different compilation unit) and therefore optimized better.
80
81 Revision 1.56 2007/12/13 00:13:03 cheshire
82 Simplified RDataHashValue to take a single ResourceRecord pointer, instead of separate rdlength and RDataBody
83
84 Revision 1.55 2007/12/13 00:09:28 cheshire
85 For completeness added MX, AFSDB, RT, KX to list of RRTYPES that are considered to have a target domainname in their rdata
86
87 Revision 1.54 2007/10/05 17:56:10 cheshire
88 Move CountLabels and SkipLeadingLabels to DNSCommon.c so they're callable from other files
89
90 Revision 1.53 2007/09/27 17:42:49 cheshire
91 Fix naming: for consistency, "kDNSFlag1_RC" should be "kDNSFlag1_RC_Mask"
92
93 Revision 1.52 2007/09/26 00:49:46 cheshire
94 Improve packet logging to show sent and received packets,
95 transport protocol (UDP/TCP/TLS) and source/destination address:port
96
97 Revision 1.51 2007/09/21 21:12:36 cheshire
98 <rdar://problem/5498009> BTMM: Need to log updates and query packet contents
99
100 Revision 1.50 2007/09/20 01:12:06 cheshire
101 Moved HashSlot(X) from mDNS.c to DNSCommon.h so it's usable in other files
102
103 Revision 1.49 2007/08/30 00:31:20 cheshire
104 Improve "locking failure" debugging messages to show function name using __func__ macro
105
106 Revision 1.48 2007/05/25 00:25:44 cheshire
107 <rdar://problem/5227737> Need to enhance putRData to output all current known types
108
109 Revision 1.47 2007/05/01 21:46:31 cheshire
110 Move GetLLQOptData/GetPktLease from uDNS.c into DNSCommon.c so that dnsextd can use them
111
112 Revision 1.46 2007/04/22 20:18:10 cheshire
113 Add comment about mDNSRandom()
114
115 Revision 1.45 2007/04/22 06:02:02 cheshire
116 <rdar://problem/4615977> Query should immediately return failure when no server
117
118 Revision 1.44 2007/03/28 01:20:05 cheshire
119 <rdar://problem/4883206> Improve/create logging for secure browse
120
121 Revision 1.43 2007/03/20 17:07:15 cheshire
122 Rename "struct uDNS_TCPSocket_struct" to "TCPSocket", "struct uDNS_UDPSocket_struct" to "UDPSocket"
123
124 Revision 1.42 2007/03/10 03:26:44 cheshire
125 <rdar://problem/4961667> uDNS: LLQ refresh response packet causes cached records to be removed from cache
126
127 Revision 1.41 2007/01/18 23:18:17 cheshire
128 Source code tidying: Delete extraneous white space
129
130 Revision 1.40 2007/01/05 08:30:40 cheshire
131 Trim excessive "$Log" checkin history from before 2006
132 (checkin history still available via "cvs log ..." of course)
133
134 Revision 1.39 2007/01/04 21:45:20 cheshire
135 Added mDNS_DropLockBeforeCallback/mDNS_ReclaimLockAfterCallback macros,
136 to do additional lock sanity checking around callback invocations
137
138 Revision 1.38 2006/12/22 20:59:49 cheshire
139 <rdar://problem/4742742> Read *all* DNS keys from keychain,
140 not just key for the system-wide default registration domain
141
142 Revision 1.37 2006/08/14 23:24:22 cheshire
143 Re-licensed mDNSResponder daemon source code under Apache License, Version 2.0
144
145 Revision 1.36 2006/07/05 22:56:07 cheshire
146 <rdar://problem/4472014> Add Private DNS client functionality to mDNSResponder
147 Update mDNSSendDNSMessage() to use uDNS_TCPSocket type instead of "int"
148
149 Revision 1.35 2006/06/29 07:42:14 cheshire
150 <rdar://problem/3922989> Performance: Remove unnecessary SameDomainName() checks
151
152 Revision 1.34 2006/03/18 21:47:56 cheshire
153 <rdar://problem/4073825> Improve logic for delaying packets after repeated interface transitions
154
155 Revision 1.33 2006/03/10 21:51:41 cheshire
156 <rdar://problem/4111464> After record update, old record sometimes remains in cache
157 Split out SameRDataBody() into a separate routine so it can be called from other code
158
159 */
160
161 #ifndef __DNSCOMMON_H_
162 #define __DNSCOMMON_H_
163
164 #include "mDNSEmbeddedAPI.h"
165
166 #ifdef __cplusplus
167 extern "C" {
168 #endif
169
170 //*************************************************************************************************************
171 // Macros
172
173 // Note: The C preprocessor stringify operator ('#') makes a string from its argument, without macro expansion
174 // e.g. If "version" is #define'd to be "4", then STRINGIFY_AWE(version) will return the string "version", not "4"
175 // To expand "version" to its value before making the string, use STRINGIFY(version) instead
176 #define STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s) #s
177 #define STRINGIFY(s) STRINGIFY_ARGUMENT_WITHOUT_EXPANSION(s)
178
179 // ***************************************************************************
180 #if COMPILER_LIKES_PRAGMA_MARK
181 #pragma mark - DNS Protocol Constants
182 #endif
183
184 typedef enum
185 {
186 kDNSFlag0_QR_Mask = 0x80, // Query or response?
187 kDNSFlag0_QR_Query = 0x00,
188 kDNSFlag0_QR_Response = 0x80,
189
190 kDNSFlag0_OP_Mask = 0x78, // Operation type
191 kDNSFlag0_OP_StdQuery = 0x00,
192 kDNSFlag0_OP_Iquery = 0x08,
193 kDNSFlag0_OP_Status = 0x10,
194 kDNSFlag0_OP_Unused3 = 0x18,
195 kDNSFlag0_OP_Notify = 0x20,
196 kDNSFlag0_OP_Update = 0x28,
197
198 kDNSFlag0_QROP_Mask = kDNSFlag0_QR_Mask | kDNSFlag0_OP_Mask,
199
200 kDNSFlag0_AA = 0x04, // Authoritative Answer?
201 kDNSFlag0_TC = 0x02, // Truncated?
202 kDNSFlag0_RD = 0x01, // Recursion Desired?
203 kDNSFlag1_RA = 0x80, // Recursion Available?
204
205 kDNSFlag1_Zero = 0x40, // Reserved; must be zero
206 kDNSFlag1_AD = 0x20, // Authentic Data [RFC 2535]
207 kDNSFlag1_CD = 0x10, // Checking Disabled [RFC 2535]
208
209 kDNSFlag1_RC_Mask = 0x0F, // Response code
210 kDNSFlag1_RC_NoErr = 0x00,
211 kDNSFlag1_RC_FormErr = 0x01,
212 kDNSFlag1_RC_ServFail = 0x02,
213 kDNSFlag1_RC_NXDomain = 0x03,
214 kDNSFlag1_RC_NotImpl = 0x04,
215 kDNSFlag1_RC_Refused = 0x05,
216 kDNSFlag1_RC_YXDomain = 0x06,
217 kDNSFlag1_RC_YXRRSet = 0x07,
218 kDNSFlag1_RC_NXRRSet = 0x08,
219 kDNSFlag1_RC_NotAuth = 0x09,
220 kDNSFlag1_RC_NotZone = 0x0A
221 } DNS_Flags;
222
223 typedef enum
224 {
225 TSIG_ErrBadSig = 16,
226 TSIG_ErrBadKey = 17,
227 TSIG_ErrBadTime = 18
228 } TSIG_ErrorCode;
229
230 // ***************************************************************************
231 #if COMPILER_LIKES_PRAGMA_MARK
232 #pragma mark -
233 #pragma mark - General Utility Functions
234 #endif
235
236 extern NetworkInterfaceInfo *GetFirstActiveInterface(NetworkInterfaceInfo *intf);
237 extern mDNSInterfaceID GetNextActiveInterfaceID(const NetworkInterfaceInfo *intf);
238
239 extern mDNSu32 mDNSRandom(mDNSu32 max); // Returns pseudo-random result from zero to max inclusive
240
241 // ***************************************************************************
242 #if COMPILER_LIKES_PRAGMA_MARK
243 #pragma mark -
244 #pragma mark - Domain Name Utility Functions
245 #endif
246
247 #define mDNSIsDigit(X) ((X) >= '0' && (X) <= '9')
248 #define mDNSIsUpperCase(X) ((X) >= 'A' && (X) <= 'Z')
249 #define mDNSIsLowerCase(X) ((X) >= 'a' && (X) <= 'z')
250 #define mDNSIsLetter(X) (mDNSIsUpperCase(X) || mDNSIsLowerCase(X))
251
252 #define mDNSValidHostChar(X, notfirst, notlast) (mDNSIsLetter(X) || mDNSIsDigit(X) || ((notfirst) && (notlast) && (X) == '-') )
253
254 extern mDNSu16 CompressedDomainNameLength(const domainname *const name, const domainname *parent);
255 extern int CountLabels(const domainname *d);
256 extern const domainname *SkipLeadingLabels(const domainname *d, int skip);
257
258 extern mDNSu32 TruncateUTF8ToLength(mDNSu8 *string, mDNSu32 length, mDNSu32 max);
259 extern mDNSBool LabelContainsSuffix(const domainlabel *const name, const mDNSBool RichText);
260 extern mDNSu32 RemoveLabelSuffix(domainlabel *name, mDNSBool RichText);
261 extern void AppendLabelSuffix(domainlabel *name, mDNSu32 val, mDNSBool RichText);
262 #define ValidateDomainName(N) (DomainNameLength(N) <= MAX_DOMAIN_NAME)
263
264 // ***************************************************************************
265 #if COMPILER_LIKES_PRAGMA_MARK
266 #pragma mark -
267 #pragma mark - Resource Record Utility Functions
268 #endif
269
270 // IdenticalResourceRecord returns true if two resources records have
271 // the same name, type, class, and identical rdata (InterfaceID and TTL may differ)
272
273 // IdenticalSameNameRecord is the same, except it skips the expensive SameDomainName() check,
274 // which is at its most expensive and least useful in cases where we know in advance that the names match
275
276 // Note: The dominant use of IdenticalResourceRecord is from ProcessQuery(), handling known-answer lists. In this case
277 // it's common to have a whole bunch or records with exactly the same name (e.g. "_http._tcp.local") but different RDATA.
278 // The SameDomainName() check is expensive when the names match, and in this case *all* the names match, so we
279 // used to waste a lot of CPU time verifying that the names match, only then to find that the RDATA is different.
280 // We observed mDNSResponder spending 30% of its total CPU time on this single task alone.
281 // By swapping the checks so that we check the RDATA first, we can quickly detect when it's different
282 // (99% of the time) and then bail out before we waste time on the expensive SameDomainName() check.
283
284 #define IdenticalResourceRecord(r1,r2) ( \
285 (r1)->rrtype == (r2)->rrtype && \
286 (r1)->rrclass == (r2)->rrclass && \
287 (r1)->namehash == (r2)->namehash && \
288 (r1)->rdlength == (r2)->rdlength && \
289 (r1)->rdatahash == (r2)->rdatahash && \
290 SameRDataBody((r1), &(r2)->rdata->u) && \
291 SameDomainName((r1)->name, (r2)->name))
292
293 #define IdenticalSameNameRecord(r1,r2) ( \
294 (r1)->rrtype == (r2)->rrtype && \
295 (r1)->rrclass == (r2)->rrclass && \
296 (r1)->rdlength == (r2)->rdlength && \
297 (r1)->rdatahash == (r2)->rdatahash && \
298 SameRDataBody((r1), &(r2)->rdata->u))
299
300 // A given RRType answers a QuestionType if RRType is CNAME, or types match, or QuestionType is ANY,
301 // or the RRType is NSEC and positively asserts the nonexistence of the type being requested
302 #define RRTypeAnswersQuestionType(R,T) ((R)->rrtype == kDNSType_CNAME || (R)->rrtype == (T) || (T) == kDNSQType_ANY || RRAssertsNonexistence((R),(T)))
303 #define RRAssertsNonexistence(R,T) ((R)->rrtype == kDNSType_NSEC && (T) < kDNSQType_ANY && !((R)->rdata->u.nsec.bitmap[(T)>>3] & (128 >> ((T)&7))))
304
305 extern mDNSu32 RDataHashValue(const ResourceRecord *const rr);
306 extern mDNSBool SameRDataBody(const ResourceRecord *const r1, const RDataBody *const r2);
307 extern mDNSBool SameNameRecordAnswersQuestion(const ResourceRecord *const rr, const DNSQuestion *const q);
308 extern mDNSBool ResourceRecordAnswersQuestion(const ResourceRecord *const rr, const DNSQuestion *const q);
309 extern mDNSBool AnyTypeRecordAnswersQuestion (const ResourceRecord *const rr, const DNSQuestion *const q);
310 extern mDNSu16 GetRDLength(const ResourceRecord *const rr, mDNSBool estimate);
311 extern mDNSBool ValidateRData(const mDNSu16 rrtype, const mDNSu16 rdlength, const RData *const rd);
312
313 #define GetRRDomainNameTarget(RR) ( \
314 ((RR)->rrtype == kDNSType_NS || (RR)->rrtype == kDNSType_CNAME || (RR)->rrtype == kDNSType_PTR || (RR)->rrtype == kDNSType_DNAME) ? &(RR)->rdata->u.name : \
315 ((RR)->rrtype == kDNSType_MX || (RR)->rrtype == kDNSType_AFSDB || (RR)->rrtype == kDNSType_RT || (RR)->rrtype == kDNSType_KX ) ? &(RR)->rdata->u.mx.exchange : \
316 ((RR)->rrtype == kDNSType_SRV ) ? &(RR)->rdata->u.srv.target : mDNSNULL )
317
318 #define LocalRecordReady(X) ((X)->resrec.RecordType != kDNSRecordTypeUnique && (X)->resrec.RecordType != kDNSRecordTypeDeregistering)
319
320 // ***************************************************************************
321 #if COMPILER_LIKES_PRAGMA_MARK
322 #pragma mark -
323 #pragma mark - DNS Message Creation Functions
324 #endif
325
326 extern void InitializeDNSMessage(DNSMessageHeader *h, mDNSOpaque16 id, mDNSOpaque16 flags);
327 extern const mDNSu8 *FindCompressionPointer(const mDNSu8 *const base, const mDNSu8 *const end, const mDNSu8 *const domname);
328 extern mDNSu8 *putDomainNameAsLabels(const DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, const domainname *const name);
329 extern mDNSu8 *putRData(const DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, const ResourceRecord *const rr);
330
331 // If we have a single large record to put in the packet, then we allow the packet to be up to 9K bytes,
332 // but in the normal case we try to keep the packets below 1500 to avoid IP fragmentation on standard Ethernet
333
334 #define AllowedRRSpace(msg) (((msg)->h.numAnswers || (msg)->h.numAuthorities || (msg)->h.numAdditionals) ? NormalMaxDNSMessageData : AbsoluteMaxDNSMessageData)
335
336 extern mDNSu8 *PutResourceRecordTTLWithLimit(DNSMessage *const msg, mDNSu8 *ptr, mDNSu16 *count, ResourceRecord *rr, mDNSu32 ttl, const mDNSu8 *limit);
337
338 #define PutResourceRecordTTL(msg, ptr, count, rr, ttl) \
339 PutResourceRecordTTLWithLimit((msg), (ptr), (count), (rr), (ttl), (msg)->data + AllowedRRSpace(msg))
340
341 #define PutResourceRecordTTLJumbo(msg, ptr, count, rr, ttl) \
342 PutResourceRecordTTLWithLimit((msg), (ptr), (count), (rr), (ttl), (msg)->data + AbsoluteMaxDNSMessageData)
343
344 #define PutResourceRecord(MSG, P, C, RR) PutResourceRecordTTL((MSG), (P), (C), (RR), (RR)->rroriginalttl)
345
346 // The PutRR_OS variants assume a local variable 'm', put build the packet at m->omsg,
347 // and assume a local variable 'OwnerRecordSpace' indicating how many bytes (if any) to reserve to add an OWNER option at the end
348 #define PutRR_OS_TTL(ptr, count, rr, ttl) \
349 PutResourceRecordTTLWithLimit(&m->omsg, (ptr), (count), (rr), (ttl), m->omsg.data + AllowedRRSpace(&m->omsg) - OwnerRecordSpace)
350
351 #define PutRR_OS(P, C, RR) PutRR_OS_TTL((P), (C), (RR), (RR)->rroriginalttl)
352
353 extern mDNSu8 *putQuestion(DNSMessage *const msg, mDNSu8 *ptr, const mDNSu8 *const limit, const domainname *const name, mDNSu16 rrtype, mDNSu16 rrclass);
354 extern mDNSu8 *putZone(DNSMessage *const msg, mDNSu8 *ptr, mDNSu8 *limit, const domainname *zone, mDNSOpaque16 zoneClass);
355 extern mDNSu8 *putPrereqNameNotInUse(const domainname *const name, DNSMessage *msg, mDNSu8 *ptr, mDNSu8 *end);
356 extern mDNSu8 *putDeletionRecord(DNSMessage *msg, mDNSu8 *ptr, ResourceRecord *rr);
357 extern mDNSu8 *putDeleteRRSet(DNSMessage *msg, mDNSu8 *ptr, const domainname *name, mDNSu16 rrtype);
358 extern mDNSu8 *putDeleteAllRRSets(DNSMessage *msg, mDNSu8 *ptr, const domainname *name);
359 extern mDNSu8 *putUpdateLease(DNSMessage *msg, mDNSu8 *end, mDNSu32 lease);
360
361 extern mDNSu8 *putHINFO(const mDNS *const m, DNSMessage *const msg, mDNSu8 *end, DomainAuthInfo *authInfo);
362
363 // ***************************************************************************
364 #if COMPILER_LIKES_PRAGMA_MARK
365 #pragma mark -
366 #pragma mark - DNS Message Parsing Functions
367 #endif
368
369 #define HashSlot(X) (DomainNameHashValue(X) % CACHE_HASH_SLOTS)
370 extern mDNSu32 DomainNameHashValue(const domainname *const name);
371 extern void SetNewRData(ResourceRecord *const rr, RData *NewRData, mDNSu16 rdlength);
372 extern const mDNSu8 *skipDomainName(const DNSMessage *const msg, const mDNSu8 *ptr, const mDNSu8 *const end);
373 extern const mDNSu8 *getDomainName(const DNSMessage *const msg, const mDNSu8 *ptr, const mDNSu8 *const end,
374 domainname *const name);
375 extern const mDNSu8 *skipResourceRecord(const DNSMessage *msg, const mDNSu8 *ptr, const mDNSu8 *end);
376 extern const mDNSu8 *GetLargeResourceRecord(mDNS *const m, const DNSMessage * const msg, const mDNSu8 *ptr,
377 const mDNSu8 * end, const mDNSInterfaceID InterfaceID, mDNSu8 RecordType, LargeCacheRecord *largecr);
378 extern const mDNSu8 *skipQuestion(const DNSMessage *msg, const mDNSu8 *ptr, const mDNSu8 *end);
379 extern const mDNSu8 *getQuestion(const DNSMessage *msg, const mDNSu8 *ptr, const mDNSu8 *end, const mDNSInterfaceID InterfaceID,
380 DNSQuestion *question);
381 extern const mDNSu8 *LocateAnswers(const DNSMessage *const msg, const mDNSu8 *const end);
382 extern const mDNSu8 *LocateAuthorities(const DNSMessage *const msg, const mDNSu8 *const end);
383 extern const mDNSu8 *LocateAdditionals(const DNSMessage *const msg, const mDNSu8 *const end);
384 extern const mDNSu8 *LocateOptRR(const DNSMessage *const msg, const mDNSu8 *const end, int minsize);
385 extern const rdataOPT *GetLLQOptData(mDNS *const m, const DNSMessage *const msg, const mDNSu8 *const end);
386 extern mDNSu32 GetPktLease(mDNS *m, DNSMessage *msg, const mDNSu8 *end);
387 extern void DumpPacket(mDNS *const m, mStatus status, mDNSBool sent, char *transport,
388 const mDNSAddr *srcaddr, mDNSIPPort srcport,
389 const mDNSAddr *dstaddr, mDNSIPPort dstport, const DNSMessage *const msg, const mDNSu8 *const end);
390
391 // ***************************************************************************
392 #if COMPILER_LIKES_PRAGMA_MARK
393 #pragma mark -
394 #pragma mark - Packet Sending Functions
395 #endif
396
397 extern mStatus mDNSSendDNSMessage(mDNS *const m, DNSMessage *const msg, mDNSu8 *end,
398 mDNSInterfaceID InterfaceID, UDPSocket *src, const mDNSAddr *dst, mDNSIPPort dstport, TCPSocket *sock, DomainAuthInfo *authInfo);
399
400 // ***************************************************************************
401 #if COMPILER_LIKES_PRAGMA_MARK
402 #pragma mark -
403 #pragma mark - RR List Management & Task Management
404 #endif
405
406 extern void ShowTaskSchedulingError(mDNS *const m);
407 extern void mDNS_Lock_(mDNS *const m);
408 extern void mDNS_Unlock_(mDNS *const m);
409
410 #if defined(_WIN32)
411 #define __func__ __FUNCTION__
412 #endif
413
414 #define mDNS_Lock(X) do { \
415 if ((X)->mDNS_busy != (X)->mDNS_reentrancy) LogMsg("%s: mDNS_Lock locking failure! mDNS_busy (%ld) != mDNS_reentrancy (%ld)", __func__, (X)->mDNS_busy, (X)->mDNS_reentrancy); \
416 mDNS_Lock_(X); } while (0)
417
418 #define mDNS_Unlock(X) do { mDNS_Unlock_(X); \
419 if ((X)->mDNS_busy != (X)->mDNS_reentrancy) LogMsg("%s: mDNS_Unlock locking failure! mDNS_busy (%ld) != mDNS_reentrancy (%ld)", __func__, (X)->mDNS_busy, (X)->mDNS_reentrancy); \
420 } while (0)
421
422 #define mDNS_DropLockBeforeCallback() do { m->mDNS_reentrancy++; \
423 if (m->mDNS_busy != m->mDNS_reentrancy) LogMsg("%s: Locking Failure! mDNS_busy (%ld) != mDNS_reentrancy (%ld)", __func__, m->mDNS_busy, m->mDNS_reentrancy); \
424 } while (0)
425
426 #define mDNS_ReclaimLockAfterCallback() do { \
427 if (m->mDNS_busy != m->mDNS_reentrancy) LogMsg("%s: Unlocking Failure! mDNS_busy (%ld) != mDNS_reentrancy (%ld)", __func__, m->mDNS_busy, m->mDNS_reentrancy); \
428 m->mDNS_reentrancy--; } while (0)
429
430 #ifdef __cplusplus
431 }
432 #endif
433
434 #endif // __DNSCOMMON_H_