]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/uDNS.h
mDNSResponder-258.18.tar.gz
[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
18 #ifndef __UDNS_H_
19 #define __UDNS_H_
20
21 #include "mDNSEmbeddedAPI.h"
22 #include "DNSCommon.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
28 #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)
29 #define INIT_UCAST_POLL_INTERVAL (3 * mDNSPlatformOneSecond) // this interval is used after send failures on network transitions
30 // which typically heal quickly, so we start agressively and exponentially back off
31 #define MAX_UCAST_POLL_INTERVAL (60 * 60 * mDNSPlatformOneSecond)
32 //#define MAX_UCAST_POLL_INTERVAL (1 * 60 * mDNSPlatformOneSecond)
33 #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.
34 #define RESPONSE_WINDOW (60 * mDNSPlatformOneSecond) // require server responses within one minute of request
35 #define MAX_UCAST_UNANSWERED_QUERIES 2 // the number of unanswered queries from any one uDNS server before trying another server
36 #define DNSSERVER_PENALTY_TIME (60 * mDNSPlatformOneSecond) // number of seconds for which new questions don't pick this server
37
38 #define DEFAULT_UPDATE_LEASE 7200
39
40 #define QuestionIntervalStep 3
41 #define QuestionIntervalStep2 (QuestionIntervalStep*QuestionIntervalStep)
42 #define QuestionIntervalStep3 (QuestionIntervalStep*QuestionIntervalStep*QuestionIntervalStep)
43 #define InitialQuestionInterval ((mDNSPlatformOneSecond + QuestionIntervalStep-1) / QuestionIntervalStep)
44
45 // For Unicast record registrations, we initialize the interval to 1 second. When we send any query for
46 // the record registration e.g., GetZoneData, we always back off by QuestionIntervalStep
47 // so that the first retry does not happen until 3 seconds which should be enough for TCP/TLS to be done.
48 #define INIT_RECORD_REG_INTERVAL (1 * mDNSPlatformOneSecond)
49 #define MAX_RECORD_REG_INTERVAL (15 * 60 * mDNSPlatformOneSecond)
50 #define MERGE_DELAY_TIME (1 * mDNSPlatformOneSecond)
51
52 // If we are refreshing, we do it at least 5 times with a min update frequency of
53 // 5 minutes
54 #define MAX_UPDATE_REFRESH_COUNT 5
55 #define MIN_UPDATE_REFRESH_TIME (5 * 60 * mDNSPlatformOneSecond)
56 // Entry points into unicast-specific routines
57
58 extern void LLQGotZoneData(mDNS *const m, mStatus err, const ZoneData *zoneInfo);
59 extern void startLLQHandshake(mDNS *m, DNSQuestion *q);
60 extern void sendLLQRefresh(mDNS *m, DNSQuestion *q);
61
62 extern void SleepRecordRegistrations(mDNS *m);
63
64 // uDNS_UpdateRecord
65 // following fields must be set, and the update validated, upon entry.
66 // rr->NewRData
67 // rr->newrdlength
68 // rr->UpdateCallback
69
70 extern mStatus uDNS_UpdateRecord(mDNS *m, AuthRecord *rr);
71
72 extern void SetNextQueryTime(mDNS *const m, const DNSQuestion *const q);
73 extern CacheGroup *CacheGroupForName(const mDNS *const m, const mDNSu32 slot, const mDNSu32 namehash, const domainname *const name);
74 extern mStatus mDNS_Register_internal(mDNS *const m, AuthRecord *const rr);
75 extern mStatus mDNS_Deregister_internal(mDNS *const m, AuthRecord *const rr, mDNS_Dereg_type drt);
76 extern mStatus mDNS_StartQuery_internal(mDNS *const m, DNSQuestion *const question);
77 extern mStatus mDNS_StopQuery_internal(mDNS *const m, DNSQuestion *const question);
78 extern mStatus mDNS_StartNATOperation_internal(mDNS *const m, NATTraversalInfo *traversal);
79
80 extern void RecordRegistrationGotZoneData(mDNS *const m, mStatus err, const ZoneData *zoneData);
81 extern mStatus uDNS_DeregisterRecord(mDNS *const m, AuthRecord *const rr);
82 extern const domainname *GetServiceTarget(mDNS *m, AuthRecord *const rr);
83 extern void uDNS_CheckCurrentQuestion(mDNS *const m);
84
85 // integer fields of msg header must be in HOST byte order before calling this routine
86 extern void uDNS_ReceiveMsg(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
87 const mDNSAddr *const srcaddr, const mDNSIPPort srcport);
88
89 extern void uDNS_Tasks(mDNS *const m);
90 extern void UpdateAllSRVRecords(mDNS *m);
91 extern void CheckNATMappings(mDNS *m);
92
93 extern mStatus uDNS_SetupDNSConfig(mDNS *const m);
94
95 // uDNS_SetupSearchDomains by default adds search domains. It also can be called with one or
96 // more values for "action" which does the following:
97 //
98 // -UDNS_START_WAB_QUERY - start Wide Area Bonjour (domain enumeration) queries
99 // -UDNS_START_CF_QUERY - start Configuration query
100
101 #define UDNS_START_WAB_QUERY 0x00000001
102 #define UDNS_START_CF_QUERY 0x00000002
103
104 extern mStatus uDNS_SetupSearchDomains(mDNS *const m, int action);
105
106 typedef enum
107 {
108 uDNS_LLQ_Not = 0, // Normal uDNS answer: Flush any stale records from cache, and respect record TTL
109 uDNS_LLQ_Ignore, // LLQ initial challenge packet: ignore -- has no useful records for us
110 uDNS_LLQ_Entire, // LLQ initial set of answers: Flush any stale records from cache, but assume TTL is 2 x LLQ refresh interval
111 uDNS_LLQ_Events // LLQ event packet: don't flush cache; assume TTL is 2 x LLQ refresh interval
112 } uDNS_LLQType;
113
114 extern uDNS_LLQType uDNS_recvLLQResponse(mDNS *const m, const DNSMessage *const msg, const mDNSu8 *const end, const mDNSAddr *const srcaddr, const mDNSIPPort srcport, DNSQuestion **matchQuestion);
115 extern DomainAuthInfo *GetAuthInfoForName_internal(mDNS *m, const domainname *const name);
116 extern DomainAuthInfo *GetAuthInfoForQuestion(mDNS *m, const DNSQuestion *const q);
117 extern void DisposeTCPConn(struct tcpInfo_t *tcp);
118
119 // NAT traversal
120 extern void uDNS_ReceiveNATPMPPacket(mDNS *m, const mDNSInterfaceID InterfaceID, mDNSu8 *pkt, mDNSu16 len); // Called for each received NAT-PMP packet
121 extern void natTraversalHandleAddressReply(mDNS *const m, mDNSu16 err, mDNSv4Addr ExtAddr);
122 extern void natTraversalHandlePortMapReply(mDNS *const m, NATTraversalInfo *n, const mDNSInterfaceID InterfaceID, mDNSu16 err, mDNSIPPort extport, mDNSu32 lease);
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif // __UDNS_H_