1ae8c6e27Sflorian /*
2ae8c6e27Sflorian  * iterator/iter_utils.h - iterative resolver module utility functions.
3ae8c6e27Sflorian  *
4ae8c6e27Sflorian  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5ae8c6e27Sflorian  *
6ae8c6e27Sflorian  * This software is open source.
7ae8c6e27Sflorian  *
8ae8c6e27Sflorian  * Redistribution and use in source and binary forms, with or without
9ae8c6e27Sflorian  * modification, are permitted provided that the following conditions
10ae8c6e27Sflorian  * are met:
11ae8c6e27Sflorian  *
12ae8c6e27Sflorian  * Redistributions of source code must retain the above copyright notice,
13ae8c6e27Sflorian  * this list of conditions and the following disclaimer.
14ae8c6e27Sflorian  *
15ae8c6e27Sflorian  * Redistributions in binary form must reproduce the above copyright notice,
16ae8c6e27Sflorian  * this list of conditions and the following disclaimer in the documentation
17ae8c6e27Sflorian  * and/or other materials provided with the distribution.
18ae8c6e27Sflorian  *
19ae8c6e27Sflorian  * Neither the name of the NLNET LABS nor the names of its contributors may
20ae8c6e27Sflorian  * be used to endorse or promote products derived from this software without
21ae8c6e27Sflorian  * specific prior written permission.
22ae8c6e27Sflorian  *
23ae8c6e27Sflorian  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24ae8c6e27Sflorian  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25ae8c6e27Sflorian  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26ae8c6e27Sflorian  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27ae8c6e27Sflorian  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28ae8c6e27Sflorian  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29ae8c6e27Sflorian  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30ae8c6e27Sflorian  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31ae8c6e27Sflorian  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32ae8c6e27Sflorian  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33ae8c6e27Sflorian  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34ae8c6e27Sflorian  */
35ae8c6e27Sflorian 
36ae8c6e27Sflorian /**
37ae8c6e27Sflorian  * \file
38ae8c6e27Sflorian  *
39ae8c6e27Sflorian  * This file contains functions to assist the iterator module.
40ae8c6e27Sflorian  * Configuration options. Forward zones.
41ae8c6e27Sflorian  */
42ae8c6e27Sflorian 
43ae8c6e27Sflorian #ifndef ITERATOR_ITER_UTILS_H
44ae8c6e27Sflorian #define ITERATOR_ITER_UTILS_H
45ae8c6e27Sflorian #include "iterator/iter_resptype.h"
46ae8c6e27Sflorian struct sldns_buffer;
47ae8c6e27Sflorian struct iter_env;
48ae8c6e27Sflorian struct iter_hints;
49ae8c6e27Sflorian struct iter_forwards;
50ae8c6e27Sflorian struct config_file;
51ae8c6e27Sflorian struct module_env;
52ae8c6e27Sflorian struct delegpt_addr;
53ae8c6e27Sflorian struct delegpt;
54ae8c6e27Sflorian struct regional;
55ae8c6e27Sflorian struct msg_parse;
56ae8c6e27Sflorian struct ub_randstate;
57ae8c6e27Sflorian struct query_info;
58ae8c6e27Sflorian struct reply_info;
59ae8c6e27Sflorian struct module_qstate;
60ae8c6e27Sflorian struct sock_list;
61ae8c6e27Sflorian struct ub_packed_rrset_key;
62411c5950Sflorian struct module_stack;
63411c5950Sflorian struct outside_network;
64ae8c6e27Sflorian 
65ab256815Sflorian /* max number of lookups in the cache for target nameserver names.
66ab256815Sflorian  * This stops, for large delegations, N*N lookups in the cache. */
67ab256815Sflorian #define ITERATOR_NAME_CACHELOOKUP_MAX	3
68ab256815Sflorian /* max number of lookups in the cache for parentside glue for nameserver names
69ab256815Sflorian  * This stops, for larger delegations, N*N lookups in the cache.
70ab256815Sflorian  * It is a little larger than the nonpside max, so it allows a couple extra
71ab256815Sflorian  * lookups of parent side glue. */
72ab256815Sflorian #define ITERATOR_NAME_CACHELOOKUP_MAX_PSIDE	5
73ab256815Sflorian 
74ae8c6e27Sflorian /**
75ae8c6e27Sflorian  * Process config options and set iterator module state.
76ae8c6e27Sflorian  * Sets default values if no config is found.
77ae8c6e27Sflorian  * @param iter_env: iterator module state.
78ae8c6e27Sflorian  * @param cfg: config options.
79ae8c6e27Sflorian  * @return 0 on error.
80ae8c6e27Sflorian  */
81ae8c6e27Sflorian int iter_apply_cfg(struct iter_env* iter_env, struct config_file* cfg);
82ae8c6e27Sflorian 
83ae8c6e27Sflorian /**
84ae8c6e27Sflorian  * Select a valid, nice target to send query to.
85ae8c6e27Sflorian  * Sorting and removing unsuitable targets is combined.
86ae8c6e27Sflorian  *
87ae8c6e27Sflorian  * @param iter_env: iterator module global state, with ip6 enabled and
88ae8c6e27Sflorian  *	do-not-query-addresses.
89ae8c6e27Sflorian  * @param env: environment with infra cache (lameness, rtt info).
90ae8c6e27Sflorian  * @param dp: delegation point with result list.
91ae8c6e27Sflorian  * @param name: zone name (for lameness check).
92ae8c6e27Sflorian  * @param namelen: length of name.
93ae8c6e27Sflorian  * @param qtype: query type that we want to send.
94ae8c6e27Sflorian  * @param dnssec_lame: set to 1, if a known dnssec-lame server is selected
95ae8c6e27Sflorian  *	these are not preferred, but are used as a last resort.
96ae8c6e27Sflorian  * @param chase_to_rd: set to 1 if a known recursion lame server is selected
97ae8c6e27Sflorian  * 	these are not preferred, but are used as a last resort.
98ae8c6e27Sflorian  * @param open_target: number of currently outstanding target queries.
99ae8c6e27Sflorian  * 	If we wait for these, perhaps more server addresses become available.
100ae8c6e27Sflorian  * @param blacklist: the IP blacklist to use.
101ae8c6e27Sflorian  * @param prefetch: if not 0, prefetch is in use for this query.
102ae8c6e27Sflorian  * 	This means the query can have different timing, because prefetch is
103ae8c6e27Sflorian  * 	not waited upon by the downstream client, and thus a good time to
104ae8c6e27Sflorian  * 	perform exploration of other targets.
105ae8c6e27Sflorian  * @return best target or NULL if no target.
106ae8c6e27Sflorian  *	if not null, that target is removed from the result list in the dp.
107ae8c6e27Sflorian  */
108ae8c6e27Sflorian struct delegpt_addr* iter_server_selection(struct iter_env* iter_env,
109ae8c6e27Sflorian 	struct module_env* env, struct delegpt* dp, uint8_t* name,
110ae8c6e27Sflorian 	size_t namelen, uint16_t qtype, int* dnssec_lame,
111ae8c6e27Sflorian 	int* chase_to_rd, int open_target, struct sock_list* blacklist,
112ae8c6e27Sflorian 	time_t prefetch);
113ae8c6e27Sflorian 
114ae8c6e27Sflorian /**
115ae8c6e27Sflorian  * Allocate dns_msg from parsed msg, in regional.
116ae8c6e27Sflorian  * @param pkt: packet.
117ae8c6e27Sflorian  * @param msg: parsed message (cleaned and ready for regional allocation).
118ae8c6e27Sflorian  * @param regional: regional to use for allocation.
119ae8c6e27Sflorian  * @return newly allocated dns_msg, or NULL on memory error.
120ae8c6e27Sflorian  */
121ae8c6e27Sflorian struct dns_msg* dns_alloc_msg(struct sldns_buffer* pkt, struct msg_parse* msg,
122ae8c6e27Sflorian 	struct regional* regional);
123ae8c6e27Sflorian 
124ae8c6e27Sflorian /**
125ae8c6e27Sflorian  * Copy a dns_msg to this regional.
126ae8c6e27Sflorian  * @param from: dns message, also in regional.
127ae8c6e27Sflorian  * @param regional: regional to use for allocation.
128ae8c6e27Sflorian  * @return newly allocated dns_msg, or NULL on memory error.
129ae8c6e27Sflorian  */
130ae8c6e27Sflorian struct dns_msg* dns_copy_msg(struct dns_msg* from, struct regional* regional);
131ae8c6e27Sflorian 
132ae8c6e27Sflorian /**
133ae8c6e27Sflorian  * Allocate a dns_msg with malloc/alloc structure and store in dns cache.
134ae8c6e27Sflorian  * @param env: environment, with alloc structure and dns cache.
135ae8c6e27Sflorian  * @param qinf: query info, the query for which answer is stored.
136ae8c6e27Sflorian  * @param rep: reply in dns_msg from dns_alloc_msg for example.
137ae8c6e27Sflorian  * @param is_referral: If true, then the given message to be stored is a
138ae8c6e27Sflorian  *	referral. The cache implementation may use this as a hint.
139ae8c6e27Sflorian  * @param leeway: prefetch TTL leeway to expire old rrsets quicker.
140ae8c6e27Sflorian  * @param pside: true if dp is parentside, thus message is 'fresh' and NS
141ae8c6e27Sflorian  * 	can be prefetch-updates.
142ae8c6e27Sflorian  * @param region: to copy modified (cache is better) rrs back to.
143ae8c6e27Sflorian  * @param flags: with BIT_CD for dns64 AAAA translated queries.
1446d08cb1bSflorian  * @param qstarttime: time of query start.
145411c5950Sflorian  * return void, because we are not interested in alloc errors,
146ae8c6e27Sflorian  * 	the iterator and validator can operate on the results in their
147ae8c6e27Sflorian  * 	scratch space (the qstate.region) and are not dependent on the cache.
148ae8c6e27Sflorian  * 	It is useful to log the alloc failure (for the server operator),
149ae8c6e27Sflorian  * 	but the query resolution can continue without cache storage.
150ae8c6e27Sflorian  */
151ae8c6e27Sflorian void iter_dns_store(struct module_env* env, struct query_info* qinf,
152ae8c6e27Sflorian 	struct reply_info* rep, int is_referral, time_t leeway, int pside,
1536d08cb1bSflorian 	struct regional* region, uint16_t flags, time_t qstarttime);
154ae8c6e27Sflorian 
155ae8c6e27Sflorian /**
156ae8c6e27Sflorian  * Select randomly with n/m probability.
157ae8c6e27Sflorian  * For shuffle NS records for address fetching.
158ae8c6e27Sflorian  * @param rnd: random table
159ae8c6e27Sflorian  * @param n: probability.
160ae8c6e27Sflorian  * @param m: divisor for probability.
161ae8c6e27Sflorian  * @return true with n/m probability.
162ae8c6e27Sflorian  */
163ae8c6e27Sflorian int iter_ns_probability(struct ub_randstate* rnd, int n, int m);
164ae8c6e27Sflorian 
165ae8c6e27Sflorian /**
166ae8c6e27Sflorian  * Mark targets that result in a dependency cycle as done, so they
167ae8c6e27Sflorian  * will not get selected as targets.
168ae8c6e27Sflorian  * @param qstate: query state.
169ae8c6e27Sflorian  * @param dp: delegpt to mark ns in.
170ae8c6e27Sflorian  */
171ae8c6e27Sflorian void iter_mark_cycle_targets(struct module_qstate* qstate, struct delegpt* dp);
172ae8c6e27Sflorian 
173ae8c6e27Sflorian /**
174ae8c6e27Sflorian  * Mark targets that result in a dependency cycle as done, so they
175ae8c6e27Sflorian  * will not get selected as targets.  For the parent-side lookups.
176ae8c6e27Sflorian  * @param qstate: query state.
177ae8c6e27Sflorian  * @param dp: delegpt to mark ns in.
178ae8c6e27Sflorian  */
179ae8c6e27Sflorian void iter_mark_pside_cycle_targets(struct module_qstate* qstate,
180ae8c6e27Sflorian 	struct delegpt* dp);
181ae8c6e27Sflorian 
182ae8c6e27Sflorian /**
183ae8c6e27Sflorian  * See if delegation is useful or offers immediately no targets for
184ae8c6e27Sflorian  * further recursion.
185ae8c6e27Sflorian  * @param qinfo: query name and type
186ae8c6e27Sflorian  * @param qflags: query flags with RD flag
187ae8c6e27Sflorian  * @param dp: delegpt to check.
1887a05b9dfSflorian  * @param supports_ipv4: if we support ipv4 for lookups to the target.
1897a05b9dfSflorian  * 	if not, then the IPv4 addresses are useless.
1907a05b9dfSflorian  * @param supports_ipv6: if we support ipv6 for lookups to the target.
1917a05b9dfSflorian  * 	if not, then the IPv6 addresses are useless.
192d500c338Sflorian  * @param use_nat64: if we support NAT64 for lookups to the target.
193d500c338Sflorian  *	if yes, IPv4 addresses are useful even if we don't support IPv4.
194ae8c6e27Sflorian  * @return true if dp is useless.
195ae8c6e27Sflorian  */
196ae8c6e27Sflorian int iter_dp_is_useless(struct query_info* qinfo, uint16_t qflags,
197d500c338Sflorian 	struct delegpt* dp, int supports_ipv4, int supports_ipv6,
198d500c338Sflorian 	int use_nat64);
199ae8c6e27Sflorian 
200ae8c6e27Sflorian /**
201ae8c6e27Sflorian  * See if qname has DNSSEC needs.  This is true if there is a trust anchor above
202ae8c6e27Sflorian  * it.  Whether there is an insecure delegation to the data is unknown.
203ae8c6e27Sflorian  * @param env: environment with anchors.
204ae8c6e27Sflorian  * @param qinfo: query name and class.
205ae8c6e27Sflorian  * @return true if trust anchor above qname, false if no anchor or insecure
206ae8c6e27Sflorian  * point above qname.
207ae8c6e27Sflorian  */
208ae8c6e27Sflorian int iter_qname_indicates_dnssec(struct module_env* env,
209ae8c6e27Sflorian 	struct query_info *qinfo);
210ae8c6e27Sflorian 
211ae8c6e27Sflorian /**
212ae8c6e27Sflorian  * See if delegation is expected to have DNSSEC information (RRSIGs) in
213ae8c6e27Sflorian  * its answers, or not. Inspects delegation point (name), trust anchors,
214ae8c6e27Sflorian  * and delegation message (DS RRset) to determine this.
215ae8c6e27Sflorian  * @param env: module env with trust anchors.
216ae8c6e27Sflorian  * @param dp: delegation point.
217ae8c6e27Sflorian  * @param msg: delegation message, with DS if a secure referral.
218ae8c6e27Sflorian  * @param dclass: class of query.
219ae8c6e27Sflorian  * @return 1 if dnssec is expected, 0 if not or insecure point above qname.
220ae8c6e27Sflorian  */
221ae8c6e27Sflorian int iter_indicates_dnssec(struct module_env* env, struct delegpt* dp,
222ae8c6e27Sflorian 	struct dns_msg* msg, uint16_t dclass);
223ae8c6e27Sflorian 
224ae8c6e27Sflorian /**
225ae8c6e27Sflorian  * See if a message contains DNSSEC.
226ae8c6e27Sflorian  * This is examined by looking for RRSIGs. With DNSSEC a valid answer,
227ae8c6e27Sflorian  * nxdomain, nodata, referral or cname reply has RRSIGs in answer or auth
228ae8c6e27Sflorian  * sections, sigs on answer data, SOA, DS, or NSEC/NSEC3 records.
229ae8c6e27Sflorian  * @param msg: message to examine.
230ae8c6e27Sflorian  * @return true if DNSSEC information was found.
231ae8c6e27Sflorian  */
232ae8c6e27Sflorian int iter_msg_has_dnssec(struct dns_msg* msg);
233ae8c6e27Sflorian 
234ae8c6e27Sflorian /**
235ae8c6e27Sflorian  * See if a message is known to be from a certain zone.
236ae8c6e27Sflorian  * This looks for SOA or NS rrsets, for answers.
237ae8c6e27Sflorian  * For referrals, when one label is delegated, the zone is detected.
238ae8c6e27Sflorian  * Does not look at signatures.
239ae8c6e27Sflorian  * @param msg: the message to inspect.
240ae8c6e27Sflorian  * @param dp: delegation point with zone name to look for.
241ae8c6e27Sflorian  * @param type: type of message.
242ae8c6e27Sflorian  * @param dclass: class of query.
243ae8c6e27Sflorian  * @return true if message is certain to be from zone in dp->name.
244ae8c6e27Sflorian  *	false if not sure (empty msg), or not from the zone.
245ae8c6e27Sflorian  */
246ae8c6e27Sflorian int iter_msg_from_zone(struct dns_msg* msg, struct delegpt* dp,
247ae8c6e27Sflorian 	enum response_type type, uint16_t dclass);
248ae8c6e27Sflorian 
249ae8c6e27Sflorian /**
250ae8c6e27Sflorian  * Check if two replies are equal
251ae8c6e27Sflorian  * For fallback procedures
252ae8c6e27Sflorian  * @param p: reply one. The reply has rrset data pointers in region.
253ae8c6e27Sflorian  * 	Does not check rrset-IDs
254ae8c6e27Sflorian  * @param q: reply two
255ae8c6e27Sflorian  * @param region: scratch buffer.
256ae8c6e27Sflorian  * @return if one and two are equal.
257ae8c6e27Sflorian  */
258ae8c6e27Sflorian int reply_equal(struct reply_info* p, struct reply_info* q, struct regional* region);
259ae8c6e27Sflorian 
260ae8c6e27Sflorian /**
261ae8c6e27Sflorian  * Remove unused bits from the reply if possible.
262ae8c6e27Sflorian  * So that caps-for-id (0x20) fallback is more likely to be successful.
263ae8c6e27Sflorian  * This removes like, the additional section, and NS record in the authority
264ae8c6e27Sflorian  * section if those records are gratuitous (not for a referral).
265ae8c6e27Sflorian  * @param rep: the reply to strip stuff out of.
266ae8c6e27Sflorian  */
267ae8c6e27Sflorian void caps_strip_reply(struct reply_info* rep);
268ae8c6e27Sflorian 
269ae8c6e27Sflorian /**
270ae8c6e27Sflorian  * see if reply has a 'useful' rcode for capsforid comparison, so
271ae8c6e27Sflorian  * not SERVFAIL or REFUSED, and thus NOERROR or NXDOMAIN.
272ae8c6e27Sflorian  * @param rep: reply to check.
273ae8c6e27Sflorian  * @return true if the rcode is a bad type of message.
274ae8c6e27Sflorian  */
275ae8c6e27Sflorian int caps_failed_rcode(struct reply_info* rep);
276ae8c6e27Sflorian 
277ae8c6e27Sflorian /**
278ae8c6e27Sflorian  * Store parent-side rrset in separate rrset cache entries for later
279ae8c6e27Sflorian  * last-resort * lookups in case the child-side versions of this information
280ae8c6e27Sflorian  * fails.
281ae8c6e27Sflorian  * @param env: environment with cache, time, ...
282ae8c6e27Sflorian  * @param rrset: the rrset to store (copied).
283ae8c6e27Sflorian  * Failure to store is logged, but otherwise ignored.
284ae8c6e27Sflorian  */
285ae8c6e27Sflorian void iter_store_parentside_rrset(struct module_env* env,
286ae8c6e27Sflorian 	struct ub_packed_rrset_key* rrset);
287ae8c6e27Sflorian 
288ae8c6e27Sflorian /**
289ae8c6e27Sflorian  * Store parent-side NS records from a referral message
290ae8c6e27Sflorian  * @param env: environment with cache, time, ...
291ae8c6e27Sflorian  * @param rep: response with NS rrset.
292ae8c6e27Sflorian  * Failure to store is logged, but otherwise ignored.
293ae8c6e27Sflorian  */
294ae8c6e27Sflorian void iter_store_parentside_NS(struct module_env* env, struct reply_info* rep);
295ae8c6e27Sflorian 
296ae8c6e27Sflorian /**
297ae8c6e27Sflorian  * Store parent-side negative element, the parentside rrset does not exist,
298ae8c6e27Sflorian  * creates an rrset with empty rdata in the rrset cache with PARENTSIDE flag.
299ae8c6e27Sflorian  * @param env: environment with cache, time, ...
300ae8c6e27Sflorian  * @param qinfo: the identity of the rrset that is missing.
301ae8c6e27Sflorian  * @param rep: delegation response or answer response, to glean TTL from.
302ae8c6e27Sflorian  * (malloc) failure is logged but otherwise ignored.
303ae8c6e27Sflorian  */
304ae8c6e27Sflorian void iter_store_parentside_neg(struct module_env* env,
305ae8c6e27Sflorian 	struct query_info* qinfo, struct reply_info* rep);
306ae8c6e27Sflorian 
307ae8c6e27Sflorian /**
308ae8c6e27Sflorian  * Add parent NS record if that exists in the cache.  This is both new
309ae8c6e27Sflorian  * information and acts like a timeout throttle on retries.
310ae8c6e27Sflorian  * @param env: query env with rrset cache and time.
311ae8c6e27Sflorian  * @param dp: delegation point to store result in.  Also this dp is used to
312ae8c6e27Sflorian  *	see which NS name is needed.
313ae8c6e27Sflorian  * @param region: region to alloc result in.
314ae8c6e27Sflorian  * @param qinfo: pertinent information, the qclass.
315ae8c6e27Sflorian  * @return false on malloc failure.
316ae8c6e27Sflorian  *	if true, the routine worked and if such cached information
317ae8c6e27Sflorian  *	existed dp->has_parent_side_NS is set true.
318ae8c6e27Sflorian  */
319ae8c6e27Sflorian int iter_lookup_parent_NS_from_cache(struct module_env* env,
320ae8c6e27Sflorian 	struct delegpt* dp, struct regional* region, struct query_info* qinfo);
321ae8c6e27Sflorian 
322ae8c6e27Sflorian /**
323ae8c6e27Sflorian  * Add parent-side glue if that exists in the cache.  This is both new
324ae8c6e27Sflorian  * information and acts like a timeout throttle on retries to fetch them.
325ae8c6e27Sflorian  * @param env: query env with rrset cache and time.
326ae8c6e27Sflorian  * @param dp: delegation point to store result in.  Also this dp is used to
327ae8c6e27Sflorian  *	see which NS name is needed.
328ae8c6e27Sflorian  * @param region: region to alloc result in.
329ae8c6e27Sflorian  * @param qinfo: pertinent information, the qclass.
330ae8c6e27Sflorian  * @return: true, it worked, no malloc failures, and new addresses (lame)
331ae8c6e27Sflorian  *	have been added, giving extra options as query targets.
332ae8c6e27Sflorian  */
333ae8c6e27Sflorian int iter_lookup_parent_glue_from_cache(struct module_env* env,
334ae8c6e27Sflorian 	struct delegpt* dp, struct regional* region, struct query_info* qinfo);
335ae8c6e27Sflorian 
336ae8c6e27Sflorian /**
337ae8c6e27Sflorian  * Lookup next root-hint or root-forward entry.
338ae8c6e27Sflorian  * @param hints: the hints.
339ae8c6e27Sflorian  * @param fwd: the forwards.
340ae8c6e27Sflorian  * @param c: the class to start searching at. 0 means find first one.
341ae8c6e27Sflorian  * @return false if no classes found, true if found and returned in c.
342ae8c6e27Sflorian  */
343ae8c6e27Sflorian int iter_get_next_root(struct iter_hints* hints, struct iter_forwards* fwd,
344ae8c6e27Sflorian 	uint16_t* c);
345ae8c6e27Sflorian 
346ae8c6e27Sflorian /**
347ae8c6e27Sflorian  * Remove DS records that are inappropriate before they are cached.
348ae8c6e27Sflorian  * @param msg: the response to scrub.
349ae8c6e27Sflorian  * @param ns: RRSET that is the NS record for the referral.
350ae8c6e27Sflorian  * 	if NULL, then all DS records are removed from the authority section.
351ae8c6e27Sflorian  * @param z: zone name that the response is from.
352ae8c6e27Sflorian  */
353ae8c6e27Sflorian void iter_scrub_ds(struct dns_msg* msg, struct ub_packed_rrset_key* ns,
354ae8c6e27Sflorian 	uint8_t* z);
355ae8c6e27Sflorian 
356ae8c6e27Sflorian /**
3579b465e50Sflorian  * Prepare an NXDOMAIN message to be used for a subdomain answer by removing all
3589b465e50Sflorian  * RRs from the ANSWER section.
3599b465e50Sflorian  * @param msg: the response to scrub.
3609b465e50Sflorian  */
3619b465e50Sflorian void iter_scrub_nxdomain(struct dns_msg* msg);
3629b465e50Sflorian 
3639b465e50Sflorian /**
364ae8c6e27Sflorian  * Remove query attempts from all available ips. For 0x20.
365ae8c6e27Sflorian  * @param dp: delegpt.
366ae8c6e27Sflorian  * @param d: decrease.
367a1a7ba80Sflorian  * @param outbound_msg_retry: number of retries of outgoing queries
368ae8c6e27Sflorian  */
369a1a7ba80Sflorian void iter_dec_attempts(struct delegpt* dp, int d, int outbound_msg_retry);
370ae8c6e27Sflorian 
371ae8c6e27Sflorian /**
372ae8c6e27Sflorian  * Add retry counts from older delegpt to newer delegpt.
373ae8c6e27Sflorian  * Does not waste time on timeout'd (or other failing) addresses.
374ae8c6e27Sflorian  * @param dp: new delegationpoint.
375ae8c6e27Sflorian  * @param old: old delegationpoint.
376a1a7ba80Sflorian  * @param outbound_msg_retry: number of retries of outgoing queries
377ae8c6e27Sflorian  */
378a1a7ba80Sflorian void iter_merge_retry_counts(struct delegpt* dp, struct delegpt* old,
379a1a7ba80Sflorian 	int outbound_msg_retry);
380ae8c6e27Sflorian 
381ae8c6e27Sflorian /**
382ae8c6e27Sflorian  * See if a DS response (type ANSWER) is too low: a nodata answer with
383ae8c6e27Sflorian  * a SOA record in the authority section at-or-below the qchase.qname.
384ae8c6e27Sflorian  * Also returns true if we are not sure (i.e. empty message, CNAME nosig).
385ae8c6e27Sflorian  * @param msg: the response.
386ae8c6e27Sflorian  * @param dp: the dp name is used to check if the RRSIG gives a clue that
387ae8c6e27Sflorian  * 	it was originated from the correct nameserver.
388ae8c6e27Sflorian  * @return true if too low.
389ae8c6e27Sflorian  */
390ae8c6e27Sflorian int iter_ds_toolow(struct dns_msg* msg, struct delegpt* dp);
391ae8c6e27Sflorian 
392ae8c6e27Sflorian /**
393ae8c6e27Sflorian  * See if delegpt can go down a step to the qname or not
394ae8c6e27Sflorian  * @param qinfo: the query name looked up.
395ae8c6e27Sflorian  * @param dp: checked if the name can go lower to the qname
396ae8c6e27Sflorian  * @return true if can go down, false if that would not be possible.
397ae8c6e27Sflorian  * the current response seems to be the one and only, best possible, response.
398ae8c6e27Sflorian  */
399ae8c6e27Sflorian int iter_dp_cangodown(struct query_info* qinfo, struct delegpt* dp);
400ae8c6e27Sflorian 
401ae8c6e27Sflorian /**
402ae8c6e27Sflorian  * Lookup if no_cache is set in stub or fwd.
403ae8c6e27Sflorian  * @param qstate: query state with env with hints and fwds.
404ae8c6e27Sflorian  * @param qinf: query name to lookup for.
405411c5950Sflorian  * @param retdpname: returns NULL or the deepest enclosing name of fwd or stub.
406411c5950Sflorian  * 	This is the name under which the closest lookup is going to happen.
407411c5950Sflorian  * 	Used for NXDOMAIN checks, above that it is an nxdomain from a
408411c5950Sflorian  * 	different server and zone. You can pass NULL to not get it.
409411c5950Sflorian  * @param retdpnamelen: returns the length of the dpname.
410*096314feSflorian  * @param dpname_storage: this is where the dpname buf is stored, if any.
411*096314feSflorian  * 	So that caller can manage the buffer.
412*096314feSflorian  * @param dpname_storage_len: size of dpname_storage buffer.
413ae8c6e27Sflorian  * @return true if no_cache is set in stub or fwd.
414ae8c6e27Sflorian  */
415ae8c6e27Sflorian int iter_stub_fwd_no_cache(struct module_qstate *qstate,
416*096314feSflorian 	struct query_info *qinf, uint8_t** retdpname, size_t* retdpnamelen,
417*096314feSflorian 	uint8_t* dpname_storage, size_t dpname_storage_len);
418411c5950Sflorian 
419411c5950Sflorian /**
420411c5950Sflorian  * Set support for IP4 and IP6 depending on outgoing interfaces
421411c5950Sflorian  * in the outside network.  If none, no support, so no use to lookup
422411c5950Sflorian  * the AAAA and then attempt to use it if there is no outgoing-interface
423411c5950Sflorian  * for it.
424411c5950Sflorian  * @param mods: modstack to find iterator module in.
425411c5950Sflorian  * @param env: module env, find iterator module (if one) in there.
426411c5950Sflorian  * @param outnet: outside network structure.
427411c5950Sflorian  */
428411c5950Sflorian void iterator_set_ip46_support(struct module_stack* mods,
429411c5950Sflorian 	struct module_env* env, struct outside_network* outnet);
430ae8c6e27Sflorian 
431ae8c6e27Sflorian #endif /* ITERATOR_ITER_UTILS_H */
432