xref: /openbsd-src/usr.sbin/unbound/iterator/iterator.h (revision 98bc733b08604094f4138174a0ee0bb9faaca4bd)
1933707f3Ssthen /*
2933707f3Ssthen  * iterator/iterator.h - iterative resolver DNS query response module
3933707f3Ssthen  *
4933707f3Ssthen  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5933707f3Ssthen  *
6933707f3Ssthen  * This software is open source.
7933707f3Ssthen  *
8933707f3Ssthen  * Redistribution and use in source and binary forms, with or without
9933707f3Ssthen  * modification, are permitted provided that the following conditions
10933707f3Ssthen  * are met:
11933707f3Ssthen  *
12933707f3Ssthen  * Redistributions of source code must retain the above copyright notice,
13933707f3Ssthen  * this list of conditions and the following disclaimer.
14933707f3Ssthen  *
15933707f3Ssthen  * Redistributions in binary form must reproduce the above copyright notice,
16933707f3Ssthen  * this list of conditions and the following disclaimer in the documentation
17933707f3Ssthen  * and/or other materials provided with the distribution.
18933707f3Ssthen  *
19933707f3Ssthen  * Neither the name of the NLNET LABS nor the names of its contributors may
20933707f3Ssthen  * be used to endorse or promote products derived from this software without
21933707f3Ssthen  * specific prior written permission.
22933707f3Ssthen  *
23933707f3Ssthen  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
245d76a658Ssthen  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
255d76a658Ssthen  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
265d76a658Ssthen  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
275d76a658Ssthen  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
285d76a658Ssthen  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
295d76a658Ssthen  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
305d76a658Ssthen  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
315d76a658Ssthen  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
325d76a658Ssthen  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
335d76a658Ssthen  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34933707f3Ssthen  */
35933707f3Ssthen 
36933707f3Ssthen /**
37933707f3Ssthen  * \file
38933707f3Ssthen  *
39bdfc4d55Sflorian  * This file contains a module that performs recursive iterative DNS query
40933707f3Ssthen  * processing.
41933707f3Ssthen  */
42933707f3Ssthen 
43933707f3Ssthen #ifndef ITERATOR_ITERATOR_H
44933707f3Ssthen #define ITERATOR_ITERATOR_H
45933707f3Ssthen #include "services/outbound_list.h"
46933707f3Ssthen #include "util/data/msgreply.h"
47933707f3Ssthen #include "util/module.h"
48933707f3Ssthen struct delegpt;
49933707f3Ssthen struct iter_hints;
50933707f3Ssthen struct iter_forwards;
51933707f3Ssthen struct iter_donotq;
52933707f3Ssthen struct iter_prep_list;
53933707f3Ssthen struct iter_priv;
5477079be7Ssthen struct rbtree_type;
55933707f3Ssthen 
56ae1dea89Sflorian /** max number of targets spawned for a query and its subqueries */
57a961b961Ssthen #define MAX_TARGET_COUNT	64
58*98bc733bSsthen /** max number of upstream queries for a query and its subqueries, it is
59*98bc733bSsthen  * never reset. */
60*98bc733bSsthen #define MAX_GLOBAL_QUOTA	128
6106a13c09Ssthen /** max number of target lookups per qstate, per delegation point */
6206a13c09Ssthen #define MAX_DP_TARGET_COUNT	16
6306a13c09Ssthen /** max number of nxdomains allowed for target lookups for a query and
6406a13c09Ssthen  * its subqueries */
6506a13c09Ssthen #define MAX_TARGET_NX		5
66d1e2768aSsthen /** max number of nxdomains allowed for target lookups for a query and
67d1e2768aSsthen  * its subqueries when fallback has kicked in */
68d1e2768aSsthen #define MAX_TARGET_NX_FALLBACK	(MAX_TARGET_NX*2)
69933707f3Ssthen /** max number of referrals. Makes sure resolver does not run away */
70933707f3Ssthen #define MAX_REFERRAL_COUNT	130
712ee382b6Ssthen /** max number of queries for which to perform dnsseclameness detection,
72bdfc4d55Sflorian  * (rrsigs missing detection) after that, just pick up that response */
732ee382b6Ssthen #define DNSSEC_LAME_DETECT_COUNT 4
742ee382b6Ssthen /**
752ee382b6Ssthen  * max number of QNAME minimisation iterations. Limits number of queries for
762ee382b6Ssthen  * QNAMEs with a lot of labels.
772ee382b6Ssthen */
782ee382b6Ssthen #define MAX_MINIMISE_COUNT	10
79c9ade66cSsthen /* max number of time-outs for minimised query. Prevents resolving failures
80c9ade66cSsthen  * when the QNAME minimisation QTYPE is blocked. */
81c9ade66cSsthen #define MAX_MINIMISE_TIMEOUT_COUNT 3
822ee382b6Ssthen /**
832ee382b6Ssthen  * number of labels from QNAME that are always send individually when using
842ee382b6Ssthen  * QNAME minimisation, even when the number of labels of the QNAME is bigger
85e21c60efSsthen  * than MAX_MINIMISE_COUNT */
862ee382b6Ssthen #define MINIMISE_ONE_LAB	4
872ee382b6Ssthen #define MINIMISE_MULTIPLE_LABS	(MAX_MINIMISE_COUNT - MINIMISE_ONE_LAB)
88933707f3Ssthen /** at what query-sent-count to stop target fetch policy */
89933707f3Ssthen #define TARGET_FETCH_STOP	3
90933707f3Ssthen /** how nice is a server without further information, in msec
91933707f3Ssthen  * Equals rtt initial timeout value.
92933707f3Ssthen  */
933150e5f6Ssthen extern int UNKNOWN_SERVER_NICENESS;
94933707f3Ssthen /** maximum timeout before a host is deemed unsuitable, in msec.
95933707f3Ssthen  * After host_ttl this will be timed out and the host will be tried again.
96d1e2768aSsthen  * Equals RTT_MAX_TIMEOUT, and thus when RTT_MAX_TIMEOUT is overwritten by
97d1e2768aSsthen  * config infra_cache_max_rtt, it will be overwritten as well. */
98d1e2768aSsthen extern int USEFUL_SERVER_TOP_TIMEOUT;
99d1e2768aSsthen /** penalty to validation failed blacklisted IPs
100d1e2768aSsthen  * Equals USEFUL_SERVER_TOP_TIMEOUT*4, and thus when RTT_MAX_TIMEOUT is
101d1e2768aSsthen  * overwritten by config infra_cache_max_rtt, it will be overwritten as well. */
102d1e2768aSsthen extern int BLACKLIST_PENALTY;
103933707f3Ssthen /** RTT band, within this amount from the best, servers are chosen randomly.
104933707f3Ssthen  * Chosen so that the UNKNOWN_SERVER_NICENESS falls within the band of a
105933707f3Ssthen  * fast server, this causes server exploration as a side benefit. msec. */
106933707f3Ssthen #define RTT_BAND 400
107d896b962Ssthen /** Number of retries for empty nodata packets before it is accepted. */
108d896b962Ssthen #define EMPTY_NODATA_RETRY_COUNT 2
109933707f3Ssthen 
110933707f3Ssthen /**
111933707f3Ssthen  * Global state for the iterator.
112933707f3Ssthen  */
113933707f3Ssthen struct iter_env {
114933707f3Ssthen 	/** A flag to indicate whether or not we have an IPv6 route */
115933707f3Ssthen 	int supports_ipv6;
116933707f3Ssthen 
117933707f3Ssthen 	/** A flag to indicate whether or not we have an IPv4 route */
118933707f3Ssthen 	int supports_ipv4;
119933707f3Ssthen 
1208b7325afSsthen 	/** A flag to locally apply NAT64 to make IPv4 addrs into IPv6 */
1218b7325afSsthen 	int use_nat64;
1228b7325afSsthen 
1238b7325afSsthen 	/** NAT64 prefix address, cf. dns64_env->prefix_addr */
1248b7325afSsthen 	struct sockaddr_storage nat64_prefix_addr;
1258b7325afSsthen 
1268b7325afSsthen 	/** sizeof(sockaddr_in6) */
1278b7325afSsthen 	socklen_t nat64_prefix_addrlen;
1288b7325afSsthen 
1298b7325afSsthen 	/** CIDR mask length of NAT64 prefix */
1308b7325afSsthen 	int nat64_prefix_net;
1318b7325afSsthen 
132933707f3Ssthen 	/** A set of inetaddrs that should never be queried. */
133933707f3Ssthen 	struct iter_donotq* donotq;
134933707f3Ssthen 
135933707f3Ssthen 	/** private address space and private domains */
136933707f3Ssthen 	struct iter_priv* priv;
137933707f3Ssthen 
138a58bff56Ssthen 	/** whitelist for capsforid names */
13977079be7Ssthen 	struct rbtree_type* caps_white;
140a58bff56Ssthen 
141933707f3Ssthen 	/** The maximum dependency depth that this resolver will pursue. */
142933707f3Ssthen 	int max_dependency_depth;
143933707f3Ssthen 
144933707f3Ssthen 	/**
145933707f3Ssthen 	 * The target fetch policy for each dependency level. This is
146933707f3Ssthen 	 * described as a simple number (per dependency level):
147933707f3Ssthen 	 *	negative numbers (usually just -1) mean fetch-all,
148933707f3Ssthen 	 *	0 means only fetch on demand, and
149933707f3Ssthen 	 *	positive numbers mean to fetch at most that many targets.
150933707f3Ssthen 	 * array of max_dependency_depth+1 size.
151933707f3Ssthen 	 */
152933707f3Ssthen 	int* target_fetch_policy;
15324893edcSsthen 
1547191de28Ssthen 	/** lock on ratelimit counter */
1557191de28Ssthen 	lock_basic_type queries_ratelimit_lock;
1567191de28Ssthen 	/** number of queries that have been ratelimited */
1577191de28Ssthen 	size_t num_queries_ratelimited;
158e21c60efSsthen 
159e21c60efSsthen 	/** number of retries on outgoing queries */
160e21c60efSsthen 	int outbound_msg_retry;
1618b7325afSsthen 
1628b7325afSsthen 	/** number of queries_sent */
1638b7325afSsthen 	int max_sent_count;
1648b7325afSsthen 
1658b7325afSsthen 	/** max number of query restarts to limit length of CNAME chain */
1668b7325afSsthen 	int max_query_restarts;
16724893edcSsthen };
16824893edcSsthen 
16924893edcSsthen /**
17024893edcSsthen  * QNAME minimisation state
17124893edcSsthen  */
17224893edcSsthen enum minimisation_state {
17324893edcSsthen 	/**
17424893edcSsthen 	 * (Re)start minimisation. Outgoing QNAME should be set to dp->name.
175bdfc4d55Sflorian 	 * State entered on new query or after following referral or CNAME.
17624893edcSsthen 	 */
17724893edcSsthen 	INIT_MINIMISE_STATE = 0,
17824893edcSsthen 	/**
179bdfc4d55Sflorian 	 * QNAME minimisation ongoing. Increase QNAME on every iteration.
18024893edcSsthen 	 */
18124893edcSsthen 	MINIMISE_STATE,
18224893edcSsthen 	/**
18324893edcSsthen 	 * Don't increment QNAME this iteration
18424893edcSsthen 	 */
18524893edcSsthen 	SKIP_MINIMISE_STATE,
18624893edcSsthen 	/**
18724893edcSsthen 	 * Send out full QNAME + original QTYPE
18824893edcSsthen 	 */
18924893edcSsthen 	DONOT_MINIMISE_STATE,
190933707f3Ssthen };
191933707f3Ssthen 
192933707f3Ssthen /**
193933707f3Ssthen  * State of the iterator for a query.
194933707f3Ssthen  */
195933707f3Ssthen enum iter_state {
196933707f3Ssthen 	/**
197933707f3Ssthen 	 * Externally generated queries start at this state. Query restarts are
198933707f3Ssthen 	 * reset to this state.
199933707f3Ssthen 	 */
200933707f3Ssthen 	INIT_REQUEST_STATE = 0,
201933707f3Ssthen 
202933707f3Ssthen 	/**
203933707f3Ssthen 	 * Root priming events reactivate here, most other events pass
204933707f3Ssthen 	 * through this naturally as the 2nd part of the INIT_REQUEST_STATE.
205933707f3Ssthen 	 */
206933707f3Ssthen 	INIT_REQUEST_2_STATE,
207933707f3Ssthen 
208933707f3Ssthen 	/**
209933707f3Ssthen 	 * Stub priming events reactivate here, most other events pass
210933707f3Ssthen 	 * through this naturally as the 3rd part of the INIT_REQUEST_STATE.
211933707f3Ssthen 	 */
212933707f3Ssthen 	INIT_REQUEST_3_STATE,
213933707f3Ssthen 
214933707f3Ssthen 	/**
215933707f3Ssthen 	 * Each time a delegation point changes for a given query or a
216933707f3Ssthen 	 * query times out and/or wakes up, this state is (re)visited.
217bdfc4d55Sflorian 	 * This state is responsible for iterating through a list of
218933707f3Ssthen 	 * nameserver targets.
219933707f3Ssthen 	 */
220933707f3Ssthen 	QUERYTARGETS_STATE,
221933707f3Ssthen 
222933707f3Ssthen 	/**
223933707f3Ssthen 	 * Responses to queries start at this state. This state handles
224933707f3Ssthen 	 * the decision tree associated with handling responses.
225933707f3Ssthen 	 */
226933707f3Ssthen 	QUERY_RESP_STATE,
227933707f3Ssthen 
228933707f3Ssthen 	/** Responses to priming queries finish at this state. */
229933707f3Ssthen 	PRIME_RESP_STATE,
230933707f3Ssthen 
231933707f3Ssthen 	/** Collecting query class information, for qclass=ANY, when
232933707f3Ssthen 	 * it spawns off queries for every class, it returns here. */
233933707f3Ssthen 	COLLECT_CLASS_STATE,
234933707f3Ssthen 
235d8d14d0cSsthen 	/** Find NS record to resolve DS record from, walking to the right
236d8d14d0cSsthen 	 * NS spot until we find it */
237d8d14d0cSsthen 	DSNS_FIND_STATE,
238d8d14d0cSsthen 
239933707f3Ssthen 	/** Responses that are to be returned upstream end at this state.
240933707f3Ssthen 	 * As well as responses to target queries. */
241933707f3Ssthen 	FINISHED_STATE
242933707f3Ssthen };
243933707f3Ssthen 
244933707f3Ssthen /**
245d1e2768aSsthen  * Shared counters for queries.
246d1e2768aSsthen  */
247d1e2768aSsthen enum target_count_variables {
248d1e2768aSsthen 	/** Reference count for the shared iter_qstate->target_count. */
249d1e2768aSsthen 	TARGET_COUNT_REF = 0,
250d1e2768aSsthen 	/** Number of target queries spawned for the query and subqueries. */
251d1e2768aSsthen 	TARGET_COUNT_QUERIES,
252d1e2768aSsthen 	/** Number of nxdomain responses encountered. */
253d1e2768aSsthen 	TARGET_COUNT_NX,
254*98bc733bSsthen 	/** Global quota on number of queries to upstream servers per
255*98bc733bSsthen 	 * client request, that is never reset. */
256*98bc733bSsthen 	TARGET_COUNT_GLOBAL_QUOTA,
257d1e2768aSsthen 
258d1e2768aSsthen 	/** This should stay last here, it is used for the allocation */
259d1e2768aSsthen 	TARGET_COUNT_MAX,
260d1e2768aSsthen };
261d1e2768aSsthen 
262d1e2768aSsthen /**
263933707f3Ssthen  * Per query state for the iterator module.
264933707f3Ssthen  */
265933707f3Ssthen struct iter_qstate {
266933707f3Ssthen 	/**
267933707f3Ssthen 	 * State of the iterator module.
268933707f3Ssthen 	 * This is the state that event is in or should sent to -- all
269933707f3Ssthen 	 * requests should start with the INIT_REQUEST_STATE. All
270933707f3Ssthen 	 * responses should start with QUERY_RESP_STATE. Subsequent
271933707f3Ssthen 	 * processing of the event will change this state.
272933707f3Ssthen 	 */
273933707f3Ssthen 	enum iter_state state;
274933707f3Ssthen 
275933707f3Ssthen 	/**
276933707f3Ssthen 	 * Final state for the iterator module.
277933707f3Ssthen 	 * This is the state that responses should be routed to once the
278933707f3Ssthen 	 * response is final. For externally initiated queries, this
279933707f3Ssthen 	 * will be FINISHED_STATE, locally initiated queries will have
280933707f3Ssthen 	 * different final states.
281933707f3Ssthen 	 */
282933707f3Ssthen 	enum iter_state final_state;
283933707f3Ssthen 
284933707f3Ssthen 	/**
285933707f3Ssthen 	 * The depth of this query, this means the depth of recursion.
286933707f3Ssthen 	 * This address is needed for another query, which is an address
287933707f3Ssthen 	 * needed for another query, etc. Original client query has depth 0.
288933707f3Ssthen 	 */
289933707f3Ssthen 	int depth;
290933707f3Ssthen 
291933707f3Ssthen 	/**
292933707f3Ssthen 	 * The response
293933707f3Ssthen 	 */
294933707f3Ssthen 	struct dns_msg* response;
295933707f3Ssthen 
296933707f3Ssthen 	/**
297933707f3Ssthen 	 * This is a list of RRsets that must be prepended to the
298933707f3Ssthen 	 * ANSWER section of a response before being sent upstream.
299933707f3Ssthen 	 */
300933707f3Ssthen 	struct iter_prep_list* an_prepend_list;
301933707f3Ssthen 	/** Last element of the prepend list */
302933707f3Ssthen 	struct iter_prep_list* an_prepend_last;
303933707f3Ssthen 
304933707f3Ssthen 	/**
305933707f3Ssthen 	 * This is the list of RRsets that must be prepended to the
306933707f3Ssthen 	 * AUTHORITY section of the response before being sent upstream.
307933707f3Ssthen 	 */
308933707f3Ssthen 	struct iter_prep_list* ns_prepend_list;
309933707f3Ssthen 	/** Last element of the authority prepend list */
310933707f3Ssthen 	struct iter_prep_list* ns_prepend_last;
311933707f3Ssthen 
312933707f3Ssthen 	/** query name used for chasing the results. Initially the same as
313933707f3Ssthen 	 * the state qinfo, but after CNAMEs this will be different.
314933707f3Ssthen 	 * The query info used to elicit the results needed. */
315933707f3Ssthen 	struct query_info qchase;
316933707f3Ssthen 	/** query flags to use when chasing the answer (i.e. RD flag) */
317933707f3Ssthen 	uint16_t chase_flags;
318933707f3Ssthen 	/** true if we set RD bit because of last resort recursion lame query*/
319933707f3Ssthen 	int chase_to_rd;
320933707f3Ssthen 
321933707f3Ssthen 	/**
322933707f3Ssthen 	 * This is the current delegation point for an in-progress query. This
323933707f3Ssthen 	 * object retains state as to which delegation targets need to be
324933707f3Ssthen 	 * (sub)queried for vs which ones have already been visited.
325933707f3Ssthen 	 */
326933707f3Ssthen 	struct delegpt* dp;
327933707f3Ssthen 
328933707f3Ssthen 	/** state for 0x20 fallback when capsfail happens, 0 not a fallback */
329933707f3Ssthen 	int caps_fallback;
330933707f3Ssthen 	/** state for capsfail: current server number to try */
331933707f3Ssthen 	size_t caps_server;
33298f3ca02Sbrad 	/** state for capsfail: stored query for comparisons. Can be NULL if
33398f3ca02Sbrad 	 * no response had been seen prior to starting the fallback. */
334933707f3Ssthen 	struct reply_info* caps_reply;
335a58bff56Ssthen 	struct dns_msg* caps_response;
336933707f3Ssthen 
337933707f3Ssthen 	/** Current delegation message - returned for non-RD queries */
338933707f3Ssthen 	struct dns_msg* deleg_msg;
339933707f3Ssthen 
340933707f3Ssthen 	/** number of outstanding target sub queries */
341933707f3Ssthen 	int num_target_queries;
342933707f3Ssthen 
343933707f3Ssthen 	/** outstanding direct queries */
344933707f3Ssthen 	int num_current_queries;
345933707f3Ssthen 
346933707f3Ssthen 	/** the number of times this query has been restarted. */
347933707f3Ssthen 	int query_restart_count;
348933707f3Ssthen 
34945872187Ssthen 	/** the number of times this query has followed a referral. */
350933707f3Ssthen 	int referral_count;
351933707f3Ssthen 
352933707f3Ssthen 	/** number of queries fired off */
353933707f3Ssthen 	int sent_count;
354933707f3Ssthen 
355d1e2768aSsthen 	/** malloced-array shared with this query and its subqueries. It keeps
356d1e2768aSsthen 	 * track of the defined enum target_count_variables counters. */
357ae1dea89Sflorian 	int* target_count;
358ae1dea89Sflorian 
35906a13c09Ssthen 	/** number of target lookups per delegation point. Reset to 0 after
36006a13c09Ssthen 	 * receiving referral answer. Not shared with subqueries. */
36106a13c09Ssthen 	int dp_target_count;
36206a13c09Ssthen 
363d1e2768aSsthen 	/** Delegation point that triggered the NXNS fallback; shared with
364d1e2768aSsthen 	 * this query and its subqueries, count-referenced by the reference
365d1e2768aSsthen 	 * counter in target_count.
366d1e2768aSsthen 	 * This also marks the fallback activation. */
367d1e2768aSsthen 	uint8_t** nxns_dp;
368d1e2768aSsthen 
369a58bff56Ssthen 	/** if true, already tested for ratelimiting and passed the test */
370a58bff56Ssthen 	int ratelimit_ok;
371a58bff56Ssthen 
372933707f3Ssthen 	/**
373933707f3Ssthen 	 * The query must store NS records from referrals as parentside RRs
374933707f3Ssthen 	 * Enabled once it hits resolution problems, to throttle retries.
375933707f3Ssthen 	 * If enabled it is the pointer to the old delegation point with
376933707f3Ssthen 	 * the old retry counts for bad-nameserver-addresses.
377933707f3Ssthen 	 */
378933707f3Ssthen 	struct delegpt* store_parent_NS;
379933707f3Ssthen 
380933707f3Ssthen 	/**
381933707f3Ssthen 	 * The query is for parent-side glue(A or AAAA) for a nameserver.
382933707f3Ssthen 	 * If the item is seen as glue in a referral, and pside_glue is NULL,
383933707f3Ssthen 	 * then it is stored in pside_glue for later.
384933707f3Ssthen 	 * If it was never seen, at the end, then a negative caching element
385933707f3Ssthen 	 * must be created.
386933707f3Ssthen 	 * The (data or negative) RR cache element then throttles retries.
387933707f3Ssthen 	 */
388933707f3Ssthen 	int query_for_pside_glue;
389933707f3Ssthen 	/** the parent-side-glue element (NULL if none, its first match) */
390933707f3Ssthen 	struct ub_packed_rrset_key* pside_glue;
391933707f3Ssthen 
392d8d14d0cSsthen 	/** If nonNULL we are walking upwards from DS query to find NS */
393d8d14d0cSsthen 	uint8_t* dsns_point;
394d8d14d0cSsthen 	/** length of the dname in dsns_point */
395d8d14d0cSsthen 	size_t dsns_point_len;
396d8d14d0cSsthen 
397933707f3Ssthen 	/**
398933707f3Ssthen 	 * expected dnssec information for this iteration step.
399933707f3Ssthen 	 * If dnssec rrsigs are expected and not given, the server is marked
400933707f3Ssthen 	 * lame (dnssec-lame).
401933707f3Ssthen 	 */
402933707f3Ssthen 	int dnssec_expected;
403933707f3Ssthen 
404933707f3Ssthen 	/**
405933707f3Ssthen 	 * We are expecting dnssec information, but we also know the server
406933707f3Ssthen 	 * is DNSSEC lame.  The response need not be marked dnssec-lame again.
407933707f3Ssthen 	 */
408933707f3Ssthen 	int dnssec_lame_query;
409933707f3Ssthen 
410933707f3Ssthen 	/**
411933707f3Ssthen 	 * This is flag that, if true, means that this event is
412933707f3Ssthen 	 * waiting for a stub priming query.
413933707f3Ssthen 	 */
414933707f3Ssthen 	int wait_priming_stub;
415933707f3Ssthen 
416933707f3Ssthen 	/**
417933707f3Ssthen 	 * This is a flag that, if true, means that this query is
418933707f3Ssthen 	 * for (re)fetching glue from a zone. Since the address should
419933707f3Ssthen 	 * have been glue, query again to the servers that should have
420933707f3Ssthen 	 * been returning it as glue.
421933707f3Ssthen 	 * The delegation point must be set to the one that should *not*
422933707f3Ssthen 	 * be used when creating the state. A higher one will be attempted.
423933707f3Ssthen 	 */
424933707f3Ssthen 	int refetch_glue;
425933707f3Ssthen 
426d896b962Ssthen 	/**
427d896b962Ssthen 	 * This flag detects that a completely empty nodata was received,
428d896b962Ssthen 	 * already so that it is accepted later. */
429d896b962Ssthen 	int empty_nodata_found;
430d896b962Ssthen 
431933707f3Ssthen 	/** list of pending queries to authoritative servers. */
432933707f3Ssthen 	struct outbound_list outlist;
43324893edcSsthen 
434e21c60efSsthen 	/** QNAME minimisation state, RFC9156 */
43524893edcSsthen 	enum minimisation_state minimisation_state;
43624893edcSsthen 
4372308e98cSsthen 	/** State for capsfail: QNAME minimisation state for comparisons. */
4382308e98cSsthen 	enum minimisation_state caps_minimisation_state;
4392308e98cSsthen 
44024893edcSsthen 	/**
44124893edcSsthen 	 * The query info that is sent upstream. Will be a subset of qchase
44224893edcSsthen 	 * when qname minimisation is enabled.
44324893edcSsthen 	 */
44424893edcSsthen 	struct query_info qinfo_out;
4452ee382b6Ssthen 
4462ee382b6Ssthen 	/**
447bdfc4d55Sflorian 	 * Count number of QNAME minimisation iterations. Used to limit number of
4482ee382b6Ssthen 	 * outgoing queries when QNAME minimisation is enabled.
4492ee382b6Ssthen 	 */
4502ee382b6Ssthen 	int minimise_count;
451c9ade66cSsthen 
452c9ade66cSsthen 	/**
453c9ade66cSsthen 	 * Count number of time-outs. Used to prevent resolving failures when
454a3167c07Ssthen 	 * the QNAME minimisation QTYPE is blocked. Used to determine if
455a3167c07Ssthen 	 * capsforid fallback should be started.*/
456a3167c07Ssthen 	int timeout_count;
457938a3a5eSflorian 
458938a3a5eSflorian 	/** True if the current response is from auth_zone */
459938a3a5eSflorian 	int auth_zone_response;
460938a3a5eSflorian 	/** True if the auth_zones should not be consulted for the query */
461938a3a5eSflorian 	int auth_zone_avoid;
462191f22c6Ssthen 	/** true if there have been scrubbing failures of reply packets */
463191f22c6Ssthen 	int scrub_failures;
464191f22c6Ssthen 	/** true if there have been parse failures of reply packets */
465191f22c6Ssthen 	int parse_failures;
466191f22c6Ssthen 	/** a failure printout address for last received answer */
4678b7325afSsthen 	union {
4688b7325afSsthen 		struct in_addr in;
4698b7325afSsthen #ifdef AF_INET6
4708b7325afSsthen 		struct in6_addr in6;
4718b7325afSsthen #endif
4728b7325afSsthen 	} fail_addr;
4738b7325afSsthen 	/** which fail_addr, 0 is nothing, 4 or 6 */
4748b7325afSsthen 	int fail_addr_type;
475933707f3Ssthen };
476933707f3Ssthen 
477933707f3Ssthen /**
478933707f3Ssthen  * List of prepend items
479933707f3Ssthen  */
480933707f3Ssthen struct iter_prep_list {
481933707f3Ssthen 	/** next in list */
482933707f3Ssthen 	struct iter_prep_list* next;
483933707f3Ssthen 	/** rrset */
484933707f3Ssthen 	struct ub_packed_rrset_key* rrset;
485933707f3Ssthen };
486933707f3Ssthen 
487933707f3Ssthen /**
488933707f3Ssthen  * Get the iterator function block.
489933707f3Ssthen  * @return: function block with function pointers to iterator methods.
490933707f3Ssthen  */
491933707f3Ssthen struct module_func_block* iter_get_funcblock(void);
492933707f3Ssthen 
493933707f3Ssthen /**
494933707f3Ssthen  * Get iterator state as a string
495933707f3Ssthen  * @param state: to convert
496933707f3Ssthen  * @return constant string that is printable.
497933707f3Ssthen  */
498933707f3Ssthen const char* iter_state_to_string(enum iter_state state);
499933707f3Ssthen 
500933707f3Ssthen /**
501933707f3Ssthen  * See if iterator state is a response state
502933707f3Ssthen  * @param s: to inspect
503933707f3Ssthen  * @return true if response state.
504933707f3Ssthen  */
505933707f3Ssthen int iter_state_is_responsestate(enum iter_state s);
506933707f3Ssthen 
507933707f3Ssthen /** iterator init */
508933707f3Ssthen int iter_init(struct module_env* env, int id);
509933707f3Ssthen 
510933707f3Ssthen /** iterator deinit */
511933707f3Ssthen void iter_deinit(struct module_env* env, int id);
512933707f3Ssthen 
513933707f3Ssthen /** iterator operate on a query */
514933707f3Ssthen void iter_operate(struct module_qstate* qstate, enum module_ev event, int id,
515933707f3Ssthen 	struct outbound_entry* outbound);
516933707f3Ssthen 
517933707f3Ssthen /**
518bdfc4d55Sflorian  * Return priming query results to interested super querystates.
519933707f3Ssthen  *
520933707f3Ssthen  * Sets the delegation point and delegation message (not nonRD queries).
521933707f3Ssthen  * This is a callback from walk_supers.
522933707f3Ssthen  *
523933707f3Ssthen  * @param qstate: query state that finished.
524933707f3Ssthen  * @param id: module id.
525933707f3Ssthen  * @param super: the qstate to inform.
526933707f3Ssthen  */
527933707f3Ssthen void iter_inform_super(struct module_qstate* qstate, int id,
528933707f3Ssthen 	struct module_qstate* super);
529933707f3Ssthen 
530933707f3Ssthen /** iterator cleanup query state */
531933707f3Ssthen void iter_clear(struct module_qstate* qstate, int id);
532933707f3Ssthen 
533933707f3Ssthen /** iterator alloc size routine */
534933707f3Ssthen size_t iter_get_mem(struct module_env* env, int id);
535933707f3Ssthen 
536933707f3Ssthen #endif /* ITERATOR_ITERATOR_H */
537