]> git.saurik.com Git - apple/mdnsresponder.git/blob - mDNSCore/uDNS.h
mDNSResponder-1096.100.3.tar.gz
[apple/mdnsresponder.git] / mDNSCore / uDNS.h
1 /*
2 * Copyright (c) 2002-2019 Apple Inc. All rights reserved.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #ifndef __UDNS_H_
18 #define __UDNS_H_
19
20 #include "mDNSEmbeddedAPI.h"
21 #include "DNSCommon.h"
22 #include <sys/types.h>
23 #include "dns_sd.h"
24
25 #if MDNSRESPONDER_SUPPORTS(COMMON, DNS_PUSH)
26 #include "dso.h"
27 #include "dso-transport.h"
28 #endif
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #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)
35 #define INIT_UCAST_POLL_INTERVAL (3 * mDNSPlatformOneSecond) // this interval is used after send failures on network transitions
36 // which typically heal quickly, so we start agressively and exponentially back off
37 #define MAX_UCAST_POLL_INTERVAL (60 * 60 * mDNSPlatformOneSecond)
38 //#define MAX_UCAST_POLL_INTERVAL (1 * 60 * mDNSPlatformOneSecond)
39 #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.
40 #define RESPONSE_WINDOW (60 * mDNSPlatformOneSecond) // require server responses within one minute of request
41 #define MAX_DNSSEC_UNANSWERED_QUERIES 1 // number of unanswered queries from any one uDNS server before turning off DNSSEC Validation
42 #define MAX_UCAST_UNANSWERED_QUERIES 2 // number of unanswered queries from any one uDNS server before trying another server
43 #define DNSSERVER_PENALTY_TIME (60 * mDNSPlatformOneSecond) // number of seconds for which new questions don't pick this server
44
45 // On some interfaces, we want to delay the first retransmission to a minimum of 2 seconds
46 // rather than the default (1 second).
47 #define MIN_UCAST_RETRANS_TIMEOUT (2 * mDNSPlatformOneSecond)
48
49 #define DEFAULT_UPDATE_LEASE 7200
50
51 #define QuestionIntervalStep 3
52 #define QuestionIntervalStep2 (QuestionIntervalStep*QuestionIntervalStep)
53 #define QuestionIntervalStep3 (QuestionIntervalStep*QuestionIntervalStep*QuestionIntervalStep)
54 #define InitialQuestionInterval ((mDNSPlatformOneSecond + QuestionIntervalStep-1) / QuestionIntervalStep)
55 #define MaxQuestionInterval (3600 * mDNSPlatformOneSecond)
56 #define UDNSBackOffMultiplier 2
57 #define MinQuestionInterval (1 * mDNSPlatformOneSecond)
58
59 // For Unicast record registrations, we initialize the interval to 1 second. When we send any query for
60 // the record registration e.g., GetZoneData, we always back off by QuestionIntervalStep
61 // so that the first retry does not happen until 3 seconds which should be enough for TCP/TLS to be done.
62 #define INIT_RECORD_REG_INTERVAL (1 * mDNSPlatformOneSecond)
63 #define MAX_RECORD_REG_INTERVAL (15 * 60 * mDNSPlatformOneSecond)
64 #define MERGE_DELAY_TIME (1 * mDNSPlatformOneSecond)
65
66 // If we are refreshing, we do it at least 5 times with a min update frequency of
67 // 5 minutes
68 #define MAX_UPDATE_REFRESH_COUNT 5
69 #define MIN_UPDATE_REFRESH_TIME (5 * 60 * mDNSPlatformOneSecond)
70
71 // For questions that use kDNSServiceFlagsTimeout and we don't have a matching resolver e.g., no dns servers,
72 // then use the default value of 30 seconds
73 #define DEFAULT_UDNS_TIMEOUT 30 // in seconds
74
75 // For questions that are validating responses (q->ValidatingResponse == 1), use 10 seconds
76 // which accomodates two DNS servers and two queries per DNS server.
77 #define DEFAULT_UDNSSEC_TIMEOUT 10 // in seconds
78
79 // If we are sending queries with EDNS0/DO option and we have no indications that the server
80 // is DNSSEC aware and we have already reached MAX_DNSSEC_RETRANSMISSIONS, we disable
81 // validation (for optional case only) for any questions that uses this server
82 #define MAX_DNSSEC_RETRANSMISSIONS 3
83
84 #if MDNSRESPONDER_SUPPORTS(COMMON, DNS_PUSH)
85 // Push notification structures
86 struct mDNS_DNSPushNotificationServer
87 {
88 dso_connect_state_t *connectInfo; // DSO Connection state information
89 dso_state_t *connection; // DNS Stateful Operations/TCP Connection pointer, might be null.
90 mDNSu32 numberOfQuestions; // Number of questions for this server
91 DNSPushServer_ConnectState connectState; // Current status of connection attempt to this server
92 mDNSs32 lastDisconnect; // Last time we got a disconnect, used to avoid constant reconnects
93 domainname serverName; // The hostname returned by the _dns-push-tls._tcp.<zone> SRV lookup
94 mDNSIPPort port; // The port from the SRV lookup
95 DNSServer *qDNSServer; // DNS server stolen from the question that created this server structure.
96 mDNS *m;
97 DNSPushNotificationServer *next;
98 } ;
99
100 struct mDNS_DNSPushNotificationZone
101 {
102 domainname zoneName;
103 DNSPushNotificationServer *server; // DNS Push Notification Servers for this zone
104 mDNSu32 numberOfQuestions; // Number of questions for this zone
105 DNSPushNotificationZone *next;
106 } ;
107 #endif
108
109 // Entry points into unicast-specific routines
110
111 extern void LLQGotZoneData(mDNS *const m, mStatus err, const ZoneData *zoneInfo);
112 extern void startLLQHandshake(mDNS *m, DNSQuestion *q);
113 extern void sendLLQRefresh(mDNS *m, DNSQuestion *q);
114
115 #if MDNSRESPONDER_SUPPORTS(COMMON, DNS_PUSH)
116 extern void DNSPushNotificationGotZoneData(mDNS *const m, mStatus err, const ZoneData *zoneInfo);
117 extern void DiscoverDNSPushNotificationServer(mDNS *m, DNSQuestion *q);
118 extern DNSPushNotificationServer *GetConnectionToDNSPushNotificationServer(mDNS *m, DNSQuestion *q);
119 extern DNSPushNotificationServer *SubscribeToDNSPushNotificationServer(mDNS *m, DNSQuestion *q);
120 extern void UnSubscribeToDNSPushNotificationServer(mDNS *m, DNSQuestion *q);
121 extern void DNSPushReconcileConnection(mDNS *m, DNSQuestion *q);
122 extern void DNSPushServerDrop(DNSPushNotificationServer *server);
123 #endif
124
125 extern void SleepRecordRegistrations(mDNS *m);
126
127 // uDNS_UpdateRecord
128 // following fields must be set, and the update validated, upon entry.
129 // rr->NewRData
130 // rr->newrdlength
131 // rr->UpdateCallback
132
133 extern mStatus uDNS_UpdateRecord(mDNS *m, AuthRecord *rr);
134
135 extern void SetNextQueryTime(mDNS *const m, const DNSQuestion *const q);
136 extern mStatus mDNS_Register_internal(mDNS *const m, AuthRecord *const rr);
137 extern mStatus mDNS_Deregister_internal(mDNS *const m, AuthRecord *const rr, mDNS_Dereg_type drt);
138 extern mStatus mDNS_StartQuery_internal(mDNS *const m, DNSQuestion *const question);
139 extern mStatus mDNS_StopQuery_internal(mDNS *const m, DNSQuestion *const question);
140 extern mStatus mDNS_StartNATOperation_internal(mDNS *const m, NATTraversalInfo *traversal);
141
142 extern void RecordRegistrationGotZoneData(mDNS *const m, mStatus err, const ZoneData *zoneData);
143 extern mStatus uDNS_DeregisterRecord(mDNS *const m, AuthRecord *const rr);
144 extern const domainname *GetServiceTarget(mDNS *m, AuthRecord *const rr);
145 extern void uDNS_CheckCurrentQuestion(mDNS *const m);
146
147 // integer fields of msg header must be in HOST byte order before calling this routine
148 extern void uDNS_ReceiveMsg(mDNS *const m, DNSMessage *const msg, const mDNSu8 *const end,
149 const mDNSAddr *const srcaddr, const mDNSIPPort srcport);
150
151 extern void uDNS_Tasks(mDNS *const m);
152 extern void UpdateAllSRVRecords(mDNS *m);
153 extern void CheckNATMappings(mDNS *m);
154
155 extern mStatus uDNS_SetupDNSConfig(mDNS *const m);
156
157 // uDNS_SetupWABQueries reads search domains from the platform layer and starts the Wide Area Bonjour
158 // (WAB) domain enumeration queries if necessary.
159
160 #define UDNS_WAB_BROWSE_QUERY 0x00000001 // Browse queries (b, db)
161 #define UDNS_WAB_LBROWSE_QUERY 0x00000002 // Browse queries (lb)
162 #define UDNS_WAB_REG_QUERY 0x00000004 // Registration queries (r and dr)
163
164 extern void uDNS_SetupWABQueries(mDNS *const m);
165 extern void uDNS_StartWABQueries(mDNS *const m, int queryType);
166 extern void uDNS_StopWABQueries(mDNS *const m, int queryType);
167 extern domainname *uDNS_GetNextSearchDomain(mDNSInterfaceID InterfaceID, int *searchIndex, mDNSBool ignoreDotLocal);
168
169 extern void uDNS_RestartQuestionAsTCP(mDNS *m, DNSQuestion *const q, const mDNSAddr *const srcaddr, const mDNSIPPort srcport);
170
171 typedef enum
172 {
173 uDNS_LLQ_Not = 0, // Normal uDNS answer: Flush any stale records from cache, and respect record TTL
174 uDNS_LLQ_Ignore, // LLQ initial challenge packet: ignore -- has no useful records for us
175 uDNS_LLQ_Entire, // LLQ initial set of answers: Flush any stale records from cache, but assume TTL is 2 x LLQ refresh interval
176 uDNS_LLQ_Events // LLQ event packet: don't flush cache; assume TTL is 2 x LLQ refresh interval
177 } uDNS_LLQType;
178
179 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);
180 extern DomainAuthInfo *GetAuthInfoForName_internal(mDNS *m, const domainname *const name);
181 extern DomainAuthInfo *GetAuthInfoForQuestion(mDNS *m, const DNSQuestion *const q);
182 extern void DisposeTCPConn(struct tcpInfo_t *tcp);
183
184 // NAT traversal
185 extern void uDNS_ReceiveNATPacket(mDNS *m, const mDNSInterfaceID InterfaceID, mDNSu8 *pkt, mDNSu16 len); // Called for each received PCP or NAT-PMP packet
186 extern void natTraversalHandleAddressReply(mDNS *const m, mDNSu16 err, mDNSv4Addr ExtAddr);
187 extern void natTraversalHandlePortMapReply(mDNS *const m, NATTraversalInfo *n, const mDNSInterfaceID InterfaceID, mDNSu16 err, mDNSIPPort extport, mDNSu32 lease, NATTProtocol protocol);
188
189 #if MDNSRESPONDER_SUPPORTS(COMMON, DNS_PUSH)
190 // DNS Push Notification
191 extern void SubscribeToDNSPushNotification(mDNS *m, DNSQuestion *q);
192 #endif
193
194 extern CacheRecord* mDNSCoreReceiveCacheCheck(mDNS *const m, const DNSMessage *const response, uDNS_LLQType LLQType,
195 const mDNSu32 slot, CacheGroup *cg, DNSQuestion *unicastQuestion,
196 CacheRecord ***cfp, CacheRecord **NSECCachePtr, mDNSInterfaceID InterfaceID);
197
198 #ifdef __cplusplus
199 }
200 #endif
201
202 #endif // __UDNS_H_