xref: /freebsd/contrib/unbound/iterator/iterator.h (revision 0a92a9fca737edafbad03ee5a8efebe302851cff)
1b7579f77SDag-Erling Smørgrav /*
2b7579f77SDag-Erling Smørgrav  * iterator/iterator.h - iterative resolver DNS query response module
3b7579f77SDag-Erling Smørgrav  *
4b7579f77SDag-Erling Smørgrav  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5b7579f77SDag-Erling Smørgrav  *
6b7579f77SDag-Erling Smørgrav  * This software is open source.
7b7579f77SDag-Erling Smørgrav  *
8b7579f77SDag-Erling Smørgrav  * Redistribution and use in source and binary forms, with or without
9b7579f77SDag-Erling Smørgrav  * modification, are permitted provided that the following conditions
10b7579f77SDag-Erling Smørgrav  * are met:
11b7579f77SDag-Erling Smørgrav  *
12b7579f77SDag-Erling Smørgrav  * Redistributions of source code must retain the above copyright notice,
13b7579f77SDag-Erling Smørgrav  * this list of conditions and the following disclaimer.
14b7579f77SDag-Erling Smørgrav  *
15b7579f77SDag-Erling Smørgrav  * Redistributions in binary form must reproduce the above copyright notice,
16b7579f77SDag-Erling Smørgrav  * this list of conditions and the following disclaimer in the documentation
17b7579f77SDag-Erling Smørgrav  * and/or other materials provided with the distribution.
18b7579f77SDag-Erling Smørgrav  *
19b7579f77SDag-Erling Smørgrav  * Neither the name of the NLNET LABS nor the names of its contributors may
20b7579f77SDag-Erling Smørgrav  * be used to endorse or promote products derived from this software without
21b7579f77SDag-Erling Smørgrav  * specific prior written permission.
22b7579f77SDag-Erling Smørgrav  *
23b7579f77SDag-Erling Smørgrav  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2417d15b25SDag-Erling Smørgrav  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2517d15b25SDag-Erling Smørgrav  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2617d15b25SDag-Erling Smørgrav  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2717d15b25SDag-Erling Smørgrav  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2817d15b25SDag-Erling Smørgrav  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
2917d15b25SDag-Erling Smørgrav  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
3017d15b25SDag-Erling Smørgrav  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
3117d15b25SDag-Erling Smørgrav  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
3217d15b25SDag-Erling Smørgrav  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
3317d15b25SDag-Erling Smørgrav  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34b7579f77SDag-Erling Smørgrav  */
35b7579f77SDag-Erling Smørgrav 
36b7579f77SDag-Erling Smørgrav /**
37b7579f77SDag-Erling Smørgrav  * \file
38b7579f77SDag-Erling Smørgrav  *
398a384985SDag-Erling Smørgrav  * This file contains a module that performs recursive iterative DNS query
40b7579f77SDag-Erling Smørgrav  * processing.
41b7579f77SDag-Erling Smørgrav  */
42b7579f77SDag-Erling Smørgrav 
43b7579f77SDag-Erling Smørgrav #ifndef ITERATOR_ITERATOR_H
44b7579f77SDag-Erling Smørgrav #define ITERATOR_ITERATOR_H
45b7579f77SDag-Erling Smørgrav #include "services/outbound_list.h"
46b7579f77SDag-Erling Smørgrav #include "util/data/msgreply.h"
47b7579f77SDag-Erling Smørgrav #include "util/module.h"
48b7579f77SDag-Erling Smørgrav struct delegpt;
49b7579f77SDag-Erling Smørgrav struct iter_hints;
50b7579f77SDag-Erling Smørgrav struct iter_forwards;
51b7579f77SDag-Erling Smørgrav struct iter_donotq;
52b7579f77SDag-Erling Smørgrav struct iter_prep_list;
53b7579f77SDag-Erling Smørgrav struct iter_priv;
543005e0a3SDag-Erling Smørgrav struct rbtree_type;
55b7579f77SDag-Erling Smørgrav 
5652df462fSXin LI /** max number of targets spawned for a query and its subqueries */
57b75612f8SDag-Erling Smørgrav #define MAX_TARGET_COUNT	64
58091e9e46SCy Schubert /** max number of target lookups per qstate, per delegation point */
59091e9e46SCy Schubert #define MAX_DP_TARGET_COUNT	16
60091e9e46SCy Schubert /** max number of nxdomains allowed for target lookups for a query and
61091e9e46SCy Schubert  * its subqueries */
62091e9e46SCy Schubert #define MAX_TARGET_NX		5
63*0a92a9fcSCy Schubert /** max number of nxdomains allowed for target lookups for a query and
64*0a92a9fcSCy Schubert  * its subqueries when fallback has kicked in */
65*0a92a9fcSCy Schubert #define MAX_TARGET_NX_FALLBACK	(MAX_TARGET_NX*2)
66b7579f77SDag-Erling Smørgrav /** max number of query restarts. Determines max number of CNAME chain. */
675469a995SCy Schubert #define MAX_RESTART_COUNT	11
68b7579f77SDag-Erling Smørgrav /** max number of referrals. Makes sure resolver does not run away */
69b7579f77SDag-Erling Smørgrav #define MAX_REFERRAL_COUNT	130
70b7579f77SDag-Erling Smørgrav /** max number of queries-sent-out.  Make sure large NS set does not loop */
71ff825849SDag-Erling Smørgrav #define MAX_SENT_COUNT		32
72e2d15004SDag-Erling Smørgrav /** max number of queries for which to perform dnsseclameness detection,
738a384985SDag-Erling Smørgrav  * (rrsigs missing detection) after that, just pick up that response */
74e2d15004SDag-Erling Smørgrav #define DNSSEC_LAME_DETECT_COUNT 4
75e2d15004SDag-Erling Smørgrav /**
76e2d15004SDag-Erling Smørgrav  * max number of QNAME minimisation iterations. Limits number of queries for
77e2d15004SDag-Erling Smørgrav  * QNAMEs with a lot of labels.
78e2d15004SDag-Erling Smørgrav */
79e2d15004SDag-Erling Smørgrav #define MAX_MINIMISE_COUNT	10
80b5663de9SDag-Erling Smørgrav /* max number of time-outs for minimised query. Prevents resolving failures
81b5663de9SDag-Erling Smørgrav  * when the QNAME minimisation QTYPE is blocked. */
82b5663de9SDag-Erling Smørgrav #define MAX_MINIMISE_TIMEOUT_COUNT 3
83e2d15004SDag-Erling Smørgrav /**
84e2d15004SDag-Erling Smørgrav  * number of labels from QNAME that are always send individually when using
85e2d15004SDag-Erling Smørgrav  * QNAME minimisation, even when the number of labels of the QNAME is bigger
869cf5bc93SCy Schubert  * than MAX_MINIMISE_COUNT */
87e2d15004SDag-Erling Smørgrav #define MINIMISE_ONE_LAB	4
88e2d15004SDag-Erling Smørgrav #define MINIMISE_MULTIPLE_LABS	(MAX_MINIMISE_COUNT - MINIMISE_ONE_LAB)
89b7579f77SDag-Erling Smørgrav /** at what query-sent-count to stop target fetch policy */
90b7579f77SDag-Erling Smørgrav #define TARGET_FETCH_STOP	3
91b7579f77SDag-Erling Smørgrav /** how nice is a server without further information, in msec
92b7579f77SDag-Erling Smørgrav  * Equals rtt initial timeout value.
93b7579f77SDag-Erling Smørgrav  */
94e86b9096SDag-Erling Smørgrav extern int UNKNOWN_SERVER_NICENESS;
95b7579f77SDag-Erling Smørgrav /** maximum timeout before a host is deemed unsuitable, in msec.
96b7579f77SDag-Erling Smørgrav  * After host_ttl this will be timed out and the host will be tried again.
97b7579f77SDag-Erling Smørgrav  * Equals RTT_MAX_TIMEOUT
98b7579f77SDag-Erling Smørgrav  */
99b7579f77SDag-Erling Smørgrav #define USEFUL_SERVER_TOP_TIMEOUT	120000
100b7579f77SDag-Erling Smørgrav /** RTT band, within this amount from the best, servers are chosen randomly.
101b7579f77SDag-Erling Smørgrav  * Chosen so that the UNKNOWN_SERVER_NICENESS falls within the band of a
102b7579f77SDag-Erling Smørgrav  * fast server, this causes server exploration as a side benefit. msec. */
103b7579f77SDag-Erling Smørgrav #define RTT_BAND 400
104b7579f77SDag-Erling Smørgrav /** Start value for blacklisting a host, 2*USEFUL_SERVER_TOP_TIMEOUT in sec */
105b7579f77SDag-Erling Smørgrav #define INFRA_BACKOFF_INITIAL 240
106b7579f77SDag-Erling Smørgrav 
107b7579f77SDag-Erling Smørgrav /**
108b7579f77SDag-Erling Smørgrav  * Global state for the iterator.
109b7579f77SDag-Erling Smørgrav  */
110b7579f77SDag-Erling Smørgrav struct iter_env {
111b7579f77SDag-Erling Smørgrav 	/** A flag to indicate whether or not we have an IPv6 route */
112b7579f77SDag-Erling Smørgrav 	int supports_ipv6;
113b7579f77SDag-Erling Smørgrav 
114b7579f77SDag-Erling Smørgrav 	/** A flag to indicate whether or not we have an IPv4 route */
115b7579f77SDag-Erling Smørgrav 	int supports_ipv4;
116b7579f77SDag-Erling Smørgrav 
117b7579f77SDag-Erling Smørgrav 	/** A set of inetaddrs that should never be queried. */
118b7579f77SDag-Erling Smørgrav 	struct iter_donotq* donotq;
119b7579f77SDag-Erling Smørgrav 
120b7579f77SDag-Erling Smørgrav 	/** private address space and private domains */
121b7579f77SDag-Erling Smørgrav 	struct iter_priv* priv;
122b7579f77SDag-Erling Smørgrav 
12309a3aaf3SDag-Erling Smørgrav 	/** whitelist for capsforid names */
1243005e0a3SDag-Erling Smørgrav 	struct rbtree_type* caps_white;
12509a3aaf3SDag-Erling Smørgrav 
126b7579f77SDag-Erling Smørgrav 	/** The maximum dependency depth that this resolver will pursue. */
127b7579f77SDag-Erling Smørgrav 	int max_dependency_depth;
128b7579f77SDag-Erling Smørgrav 
129b7579f77SDag-Erling Smørgrav 	/**
130b7579f77SDag-Erling Smørgrav 	 * The target fetch policy for each dependency level. This is
131b7579f77SDag-Erling Smørgrav 	 * described as a simple number (per dependency level):
132b7579f77SDag-Erling Smørgrav 	 *	negative numbers (usually just -1) mean fetch-all,
133b7579f77SDag-Erling Smørgrav 	 *	0 means only fetch on demand, and
134b7579f77SDag-Erling Smørgrav 	 *	positive numbers mean to fetch at most that many targets.
135b7579f77SDag-Erling Smørgrav 	 * array of max_dependency_depth+1 size.
136b7579f77SDag-Erling Smørgrav 	 */
137b7579f77SDag-Erling Smørgrav 	int* target_fetch_policy;
13805ab2901SDag-Erling Smørgrav 
139971980c3SDag-Erling Smørgrav 	/** lock on ratelimit counter */
140971980c3SDag-Erling Smørgrav 	lock_basic_type queries_ratelimit_lock;
141971980c3SDag-Erling Smørgrav 	/** number of queries that have been ratelimited */
142971980c3SDag-Erling Smørgrav 	size_t num_queries_ratelimited;
14324e36522SCy Schubert 
14424e36522SCy Schubert 	/** number of retries on outgoing queries */
14524e36522SCy Schubert 	int outbound_msg_retry;
14605ab2901SDag-Erling Smørgrav };
14705ab2901SDag-Erling Smørgrav 
14805ab2901SDag-Erling Smørgrav /**
14905ab2901SDag-Erling Smørgrav  * QNAME minimisation state
15005ab2901SDag-Erling Smørgrav  */
15105ab2901SDag-Erling Smørgrav enum minimisation_state {
15205ab2901SDag-Erling Smørgrav 	/**
15305ab2901SDag-Erling Smørgrav 	 * (Re)start minimisation. Outgoing QNAME should be set to dp->name.
1548a384985SDag-Erling Smørgrav 	 * State entered on new query or after following referral or CNAME.
15505ab2901SDag-Erling Smørgrav 	 */
15605ab2901SDag-Erling Smørgrav 	INIT_MINIMISE_STATE = 0,
15705ab2901SDag-Erling Smørgrav 	/**
1588a384985SDag-Erling Smørgrav 	 * QNAME minimisation ongoing. Increase QNAME on every iteration.
15905ab2901SDag-Erling Smørgrav 	 */
16005ab2901SDag-Erling Smørgrav 	MINIMISE_STATE,
16105ab2901SDag-Erling Smørgrav 	/**
16205ab2901SDag-Erling Smørgrav 	 * Don't increment QNAME this iteration
16305ab2901SDag-Erling Smørgrav 	 */
16405ab2901SDag-Erling Smørgrav 	SKIP_MINIMISE_STATE,
16505ab2901SDag-Erling Smørgrav 	/**
16605ab2901SDag-Erling Smørgrav 	 * Send out full QNAME + original QTYPE
16705ab2901SDag-Erling Smørgrav 	 */
16805ab2901SDag-Erling Smørgrav 	DONOT_MINIMISE_STATE,
169b7579f77SDag-Erling Smørgrav };
170b7579f77SDag-Erling Smørgrav 
171b7579f77SDag-Erling Smørgrav /**
172b7579f77SDag-Erling Smørgrav  * State of the iterator for a query.
173b7579f77SDag-Erling Smørgrav  */
174b7579f77SDag-Erling Smørgrav enum iter_state {
175b7579f77SDag-Erling Smørgrav 	/**
176b7579f77SDag-Erling Smørgrav 	 * Externally generated queries start at this state. Query restarts are
177b7579f77SDag-Erling Smørgrav 	 * reset to this state.
178b7579f77SDag-Erling Smørgrav 	 */
179b7579f77SDag-Erling Smørgrav 	INIT_REQUEST_STATE = 0,
180b7579f77SDag-Erling Smørgrav 
181b7579f77SDag-Erling Smørgrav 	/**
182b7579f77SDag-Erling Smørgrav 	 * Root priming events reactivate here, most other events pass
183b7579f77SDag-Erling Smørgrav 	 * through this naturally as the 2nd part of the INIT_REQUEST_STATE.
184b7579f77SDag-Erling Smørgrav 	 */
185b7579f77SDag-Erling Smørgrav 	INIT_REQUEST_2_STATE,
186b7579f77SDag-Erling Smørgrav 
187b7579f77SDag-Erling Smørgrav 	/**
188b7579f77SDag-Erling Smørgrav 	 * Stub priming events reactivate here, most other events pass
189b7579f77SDag-Erling Smørgrav 	 * through this naturally as the 3rd part of the INIT_REQUEST_STATE.
190b7579f77SDag-Erling Smørgrav 	 */
191b7579f77SDag-Erling Smørgrav 	INIT_REQUEST_3_STATE,
192b7579f77SDag-Erling Smørgrav 
193b7579f77SDag-Erling Smørgrav 	/**
194b7579f77SDag-Erling Smørgrav 	 * Each time a delegation point changes for a given query or a
195b7579f77SDag-Erling Smørgrav 	 * query times out and/or wakes up, this state is (re)visited.
1968a384985SDag-Erling Smørgrav 	 * This state is responsible for iterating through a list of
197b7579f77SDag-Erling Smørgrav 	 * nameserver targets.
198b7579f77SDag-Erling Smørgrav 	 */
199b7579f77SDag-Erling Smørgrav 	QUERYTARGETS_STATE,
200b7579f77SDag-Erling Smørgrav 
201b7579f77SDag-Erling Smørgrav 	/**
202b7579f77SDag-Erling Smørgrav 	 * Responses to queries start at this state. This state handles
203b7579f77SDag-Erling Smørgrav 	 * the decision tree associated with handling responses.
204b7579f77SDag-Erling Smørgrav 	 */
205b7579f77SDag-Erling Smørgrav 	QUERY_RESP_STATE,
206b7579f77SDag-Erling Smørgrav 
207b7579f77SDag-Erling Smørgrav 	/** Responses to priming queries finish at this state. */
208b7579f77SDag-Erling Smørgrav 	PRIME_RESP_STATE,
209b7579f77SDag-Erling Smørgrav 
210b7579f77SDag-Erling Smørgrav 	/** Collecting query class information, for qclass=ANY, when
211b7579f77SDag-Erling Smørgrav 	 * it spawns off queries for every class, it returns here. */
212b7579f77SDag-Erling Smørgrav 	COLLECT_CLASS_STATE,
213b7579f77SDag-Erling Smørgrav 
214b7579f77SDag-Erling Smørgrav 	/** Find NS record to resolve DS record from, walking to the right
215b7579f77SDag-Erling Smørgrav 	 * NS spot until we find it */
216b7579f77SDag-Erling Smørgrav 	DSNS_FIND_STATE,
217b7579f77SDag-Erling Smørgrav 
218b7579f77SDag-Erling Smørgrav 	/** Responses that are to be returned upstream end at this state.
219b7579f77SDag-Erling Smørgrav 	 * As well as responses to target queries. */
220b7579f77SDag-Erling Smørgrav 	FINISHED_STATE
221b7579f77SDag-Erling Smørgrav };
222b7579f77SDag-Erling Smørgrav 
223b7579f77SDag-Erling Smørgrav /**
224*0a92a9fcSCy Schubert  * Shared counters for queries.
225*0a92a9fcSCy Schubert  */
226*0a92a9fcSCy Schubert enum target_count_variables {
227*0a92a9fcSCy Schubert 	/** Reference count for the shared iter_qstate->target_count. */
228*0a92a9fcSCy Schubert 	TARGET_COUNT_REF = 0,
229*0a92a9fcSCy Schubert 	/** Number of target queries spawned for the query and subqueries. */
230*0a92a9fcSCy Schubert 	TARGET_COUNT_QUERIES,
231*0a92a9fcSCy Schubert 	/** Number of nxdomain responses encountered. */
232*0a92a9fcSCy Schubert 	TARGET_COUNT_NX,
233*0a92a9fcSCy Schubert 
234*0a92a9fcSCy Schubert 	/** This should stay last here, it is used for the allocation */
235*0a92a9fcSCy Schubert 	TARGET_COUNT_MAX,
236*0a92a9fcSCy Schubert };
237*0a92a9fcSCy Schubert 
238*0a92a9fcSCy Schubert /**
239b7579f77SDag-Erling Smørgrav  * Per query state for the iterator module.
240b7579f77SDag-Erling Smørgrav  */
241b7579f77SDag-Erling Smørgrav struct iter_qstate {
242b7579f77SDag-Erling Smørgrav 	/**
243b7579f77SDag-Erling Smørgrav 	 * State of the iterator module.
244b7579f77SDag-Erling Smørgrav 	 * This is the state that event is in or should sent to -- all
245b7579f77SDag-Erling Smørgrav 	 * requests should start with the INIT_REQUEST_STATE. All
246b7579f77SDag-Erling Smørgrav 	 * responses should start with QUERY_RESP_STATE. Subsequent
247b7579f77SDag-Erling Smørgrav 	 * processing of the event will change this state.
248b7579f77SDag-Erling Smørgrav 	 */
249b7579f77SDag-Erling Smørgrav 	enum iter_state state;
250b7579f77SDag-Erling Smørgrav 
251b7579f77SDag-Erling Smørgrav 	/**
252b7579f77SDag-Erling Smørgrav 	 * Final state for the iterator module.
253b7579f77SDag-Erling Smørgrav 	 * This is the state that responses should be routed to once the
254b7579f77SDag-Erling Smørgrav 	 * response is final. For externally initiated queries, this
255b7579f77SDag-Erling Smørgrav 	 * will be FINISHED_STATE, locally initiated queries will have
256b7579f77SDag-Erling Smørgrav 	 * different final states.
257b7579f77SDag-Erling Smørgrav 	 */
258b7579f77SDag-Erling Smørgrav 	enum iter_state final_state;
259b7579f77SDag-Erling Smørgrav 
260b7579f77SDag-Erling Smørgrav 	/**
261b7579f77SDag-Erling Smørgrav 	 * The depth of this query, this means the depth of recursion.
262b7579f77SDag-Erling Smørgrav 	 * This address is needed for another query, which is an address
263b7579f77SDag-Erling Smørgrav 	 * needed for another query, etc. Original client query has depth 0.
264b7579f77SDag-Erling Smørgrav 	 */
265b7579f77SDag-Erling Smørgrav 	int depth;
266b7579f77SDag-Erling Smørgrav 
267b7579f77SDag-Erling Smørgrav 	/**
268b7579f77SDag-Erling Smørgrav 	 * The response
269b7579f77SDag-Erling Smørgrav 	 */
270b7579f77SDag-Erling Smørgrav 	struct dns_msg* response;
271b7579f77SDag-Erling Smørgrav 
272b7579f77SDag-Erling Smørgrav 	/**
273b7579f77SDag-Erling Smørgrav 	 * This is a list of RRsets that must be prepended to the
274b7579f77SDag-Erling Smørgrav 	 * ANSWER section of a response before being sent upstream.
275b7579f77SDag-Erling Smørgrav 	 */
276b7579f77SDag-Erling Smørgrav 	struct iter_prep_list* an_prepend_list;
277b7579f77SDag-Erling Smørgrav 	/** Last element of the prepend list */
278b7579f77SDag-Erling Smørgrav 	struct iter_prep_list* an_prepend_last;
279b7579f77SDag-Erling Smørgrav 
280b7579f77SDag-Erling Smørgrav 	/**
281b7579f77SDag-Erling Smørgrav 	 * This is the list of RRsets that must be prepended to the
282b7579f77SDag-Erling Smørgrav 	 * AUTHORITY section of the response before being sent upstream.
283b7579f77SDag-Erling Smørgrav 	 */
284b7579f77SDag-Erling Smørgrav 	struct iter_prep_list* ns_prepend_list;
285b7579f77SDag-Erling Smørgrav 	/** Last element of the authority prepend list */
286b7579f77SDag-Erling Smørgrav 	struct iter_prep_list* ns_prepend_last;
287b7579f77SDag-Erling Smørgrav 
288b7579f77SDag-Erling Smørgrav 	/** query name used for chasing the results. Initially the same as
289b7579f77SDag-Erling Smørgrav 	 * the state qinfo, but after CNAMEs this will be different.
290b7579f77SDag-Erling Smørgrav 	 * The query info used to elicit the results needed. */
291b7579f77SDag-Erling Smørgrav 	struct query_info qchase;
292b7579f77SDag-Erling Smørgrav 	/** query flags to use when chasing the answer (i.e. RD flag) */
293b7579f77SDag-Erling Smørgrav 	uint16_t chase_flags;
294b7579f77SDag-Erling Smørgrav 	/** true if we set RD bit because of last resort recursion lame query*/
295b7579f77SDag-Erling Smørgrav 	int chase_to_rd;
296b7579f77SDag-Erling Smørgrav 
297b7579f77SDag-Erling Smørgrav 	/**
298b7579f77SDag-Erling Smørgrav 	 * This is the current delegation point for an in-progress query. This
299b7579f77SDag-Erling Smørgrav 	 * object retains state as to which delegation targets need to be
300b7579f77SDag-Erling Smørgrav 	 * (sub)queried for vs which ones have already been visited.
301b7579f77SDag-Erling Smørgrav 	 */
302b7579f77SDag-Erling Smørgrav 	struct delegpt* dp;
303b7579f77SDag-Erling Smørgrav 
304b7579f77SDag-Erling Smørgrav 	/** state for 0x20 fallback when capsfail happens, 0 not a fallback */
305b7579f77SDag-Erling Smørgrav 	int caps_fallback;
306b7579f77SDag-Erling Smørgrav 	/** state for capsfail: current server number to try */
307b7579f77SDag-Erling Smørgrav 	size_t caps_server;
308ff825849SDag-Erling Smørgrav 	/** state for capsfail: stored query for comparisons. Can be NULL if
309ff825849SDag-Erling Smørgrav 	 * no response had been seen prior to starting the fallback. */
310b7579f77SDag-Erling Smørgrav 	struct reply_info* caps_reply;
31109a3aaf3SDag-Erling Smørgrav 	struct dns_msg* caps_response;
312b7579f77SDag-Erling Smørgrav 
313b7579f77SDag-Erling Smørgrav 	/** Current delegation message - returned for non-RD queries */
314b7579f77SDag-Erling Smørgrav 	struct dns_msg* deleg_msg;
315b7579f77SDag-Erling Smørgrav 
316b7579f77SDag-Erling Smørgrav 	/** number of outstanding target sub queries */
317b7579f77SDag-Erling Smørgrav 	int num_target_queries;
318b7579f77SDag-Erling Smørgrav 
319b7579f77SDag-Erling Smørgrav 	/** outstanding direct queries */
320b7579f77SDag-Erling Smørgrav 	int num_current_queries;
321b7579f77SDag-Erling Smørgrav 
322b7579f77SDag-Erling Smørgrav 	/** the number of times this query has been restarted. */
323b7579f77SDag-Erling Smørgrav 	int query_restart_count;
324b7579f77SDag-Erling Smørgrav 
325b7579f77SDag-Erling Smørgrav 	/** the number of times this query as followed a referral. */
326b7579f77SDag-Erling Smørgrav 	int referral_count;
327b7579f77SDag-Erling Smørgrav 
328b7579f77SDag-Erling Smørgrav 	/** number of queries fired off */
329b7579f77SDag-Erling Smørgrav 	int sent_count;
330b7579f77SDag-Erling Smørgrav 
331*0a92a9fcSCy Schubert 	/** malloced-array shared with this query and its subqueries. It keeps
332*0a92a9fcSCy Schubert 	 * track of the defined enum target_count_variables counters. */
33352df462fSXin LI 	int* target_count;
33452df462fSXin LI 
335091e9e46SCy Schubert 	/** number of target lookups per delegation point. Reset to 0 after
336091e9e46SCy Schubert 	 * receiving referral answer. Not shared with subqueries. */
337091e9e46SCy Schubert 	int dp_target_count;
338091e9e46SCy Schubert 
339*0a92a9fcSCy Schubert 	/** Delegation point that triggered the NXNS fallback; shared with
340*0a92a9fcSCy Schubert 	 * this query and its subqueries, count-referenced by the reference
341*0a92a9fcSCy Schubert 	 * counter in target_count.
342*0a92a9fcSCy Schubert 	 * This also marks the fallback activation. */
343*0a92a9fcSCy Schubert 	uint8_t** nxns_dp;
344*0a92a9fcSCy Schubert 
34509a3aaf3SDag-Erling Smørgrav 	/** if true, already tested for ratelimiting and passed the test */
34609a3aaf3SDag-Erling Smørgrav 	int ratelimit_ok;
34709a3aaf3SDag-Erling Smørgrav 
348b7579f77SDag-Erling Smørgrav 	/**
349b7579f77SDag-Erling Smørgrav 	 * The query must store NS records from referrals as parentside RRs
350b7579f77SDag-Erling Smørgrav 	 * Enabled once it hits resolution problems, to throttle retries.
351b7579f77SDag-Erling Smørgrav 	 * If enabled it is the pointer to the old delegation point with
352b7579f77SDag-Erling Smørgrav 	 * the old retry counts for bad-nameserver-addresses.
353b7579f77SDag-Erling Smørgrav 	 */
354b7579f77SDag-Erling Smørgrav 	struct delegpt* store_parent_NS;
355b7579f77SDag-Erling Smørgrav 
356b7579f77SDag-Erling Smørgrav 	/**
357b7579f77SDag-Erling Smørgrav 	 * The query is for parent-side glue(A or AAAA) for a nameserver.
358b7579f77SDag-Erling Smørgrav 	 * If the item is seen as glue in a referral, and pside_glue is NULL,
359b7579f77SDag-Erling Smørgrav 	 * then it is stored in pside_glue for later.
360b7579f77SDag-Erling Smørgrav 	 * If it was never seen, at the end, then a negative caching element
361b7579f77SDag-Erling Smørgrav 	 * must be created.
362b7579f77SDag-Erling Smørgrav 	 * The (data or negative) RR cache element then throttles retries.
363b7579f77SDag-Erling Smørgrav 	 */
364b7579f77SDag-Erling Smørgrav 	int query_for_pside_glue;
365b7579f77SDag-Erling Smørgrav 	/** the parent-side-glue element (NULL if none, its first match) */
366b7579f77SDag-Erling Smørgrav 	struct ub_packed_rrset_key* pside_glue;
367b7579f77SDag-Erling Smørgrav 
368b7579f77SDag-Erling Smørgrav 	/** If nonNULL we are walking upwards from DS query to find NS */
369b7579f77SDag-Erling Smørgrav 	uint8_t* dsns_point;
370b7579f77SDag-Erling Smørgrav 	/** length of the dname in dsns_point */
371b7579f77SDag-Erling Smørgrav 	size_t dsns_point_len;
372b7579f77SDag-Erling Smørgrav 
373b7579f77SDag-Erling Smørgrav 	/**
374b7579f77SDag-Erling Smørgrav 	 * expected dnssec information for this iteration step.
375b7579f77SDag-Erling Smørgrav 	 * If dnssec rrsigs are expected and not given, the server is marked
376b7579f77SDag-Erling Smørgrav 	 * lame (dnssec-lame).
377b7579f77SDag-Erling Smørgrav 	 */
378b7579f77SDag-Erling Smørgrav 	int dnssec_expected;
379b7579f77SDag-Erling Smørgrav 
380b7579f77SDag-Erling Smørgrav 	/**
381b7579f77SDag-Erling Smørgrav 	 * We are expecting dnssec information, but we also know the server
382b7579f77SDag-Erling Smørgrav 	 * is DNSSEC lame.  The response need not be marked dnssec-lame again.
383b7579f77SDag-Erling Smørgrav 	 */
384b7579f77SDag-Erling Smørgrav 	int dnssec_lame_query;
385b7579f77SDag-Erling Smørgrav 
386b7579f77SDag-Erling Smørgrav 	/**
387b7579f77SDag-Erling Smørgrav 	 * This is flag that, if true, means that this event is
388b7579f77SDag-Erling Smørgrav 	 * waiting for a stub priming query.
389b7579f77SDag-Erling Smørgrav 	 */
390b7579f77SDag-Erling Smørgrav 	int wait_priming_stub;
391b7579f77SDag-Erling Smørgrav 
392b7579f77SDag-Erling Smørgrav 	/**
393b7579f77SDag-Erling Smørgrav 	 * This is a flag that, if true, means that this query is
394b7579f77SDag-Erling Smørgrav 	 * for (re)fetching glue from a zone. Since the address should
395b7579f77SDag-Erling Smørgrav 	 * have been glue, query again to the servers that should have
396b7579f77SDag-Erling Smørgrav 	 * been returning it as glue.
397b7579f77SDag-Erling Smørgrav 	 * The delegation point must be set to the one that should *not*
398b7579f77SDag-Erling Smørgrav 	 * be used when creating the state. A higher one will be attempted.
399b7579f77SDag-Erling Smørgrav 	 */
400b7579f77SDag-Erling Smørgrav 	int refetch_glue;
401b7579f77SDag-Erling Smørgrav 
402b7579f77SDag-Erling Smørgrav 	/** list of pending queries to authoritative servers. */
403b7579f77SDag-Erling Smørgrav 	struct outbound_list outlist;
40405ab2901SDag-Erling Smørgrav 
4059cf5bc93SCy Schubert 	/** QNAME minimisation state, RFC9156 */
40605ab2901SDag-Erling Smørgrav 	enum minimisation_state minimisation_state;
40705ab2901SDag-Erling Smørgrav 
4084c75e3aaSDag-Erling Smørgrav 	/** State for capsfail: QNAME minimisation state for comparisons. */
4094c75e3aaSDag-Erling Smørgrav 	enum minimisation_state caps_minimisation_state;
4104c75e3aaSDag-Erling Smørgrav 
41105ab2901SDag-Erling Smørgrav 	/**
41205ab2901SDag-Erling Smørgrav 	 * The query info that is sent upstream. Will be a subset of qchase
41305ab2901SDag-Erling Smørgrav 	 * when qname minimisation is enabled.
41405ab2901SDag-Erling Smørgrav 	 */
41505ab2901SDag-Erling Smørgrav 	struct query_info qinfo_out;
416e2d15004SDag-Erling Smørgrav 
417e2d15004SDag-Erling Smørgrav 	/**
4188a384985SDag-Erling Smørgrav 	 * Count number of QNAME minimisation iterations. Used to limit number of
419e2d15004SDag-Erling Smørgrav 	 * outgoing queries when QNAME minimisation is enabled.
420e2d15004SDag-Erling Smørgrav 	 */
421e2d15004SDag-Erling Smørgrav 	int minimise_count;
422b5663de9SDag-Erling Smørgrav 
423b5663de9SDag-Erling Smørgrav 	/**
424b5663de9SDag-Erling Smørgrav 	 * Count number of time-outs. Used to prevent resolving failures when
42525039b37SCy Schubert 	 * the QNAME minimisation QTYPE is blocked. Used to determine if
42625039b37SCy Schubert 	 * capsforid fallback should be started.*/
42725039b37SCy Schubert 	int timeout_count;
42857bddd21SDag-Erling Smørgrav 
42957bddd21SDag-Erling Smørgrav 	/** True if the current response is from auth_zone */
43057bddd21SDag-Erling Smørgrav 	int auth_zone_response;
43157bddd21SDag-Erling Smørgrav 	/** True if the auth_zones should not be consulted for the query */
43257bddd21SDag-Erling Smørgrav 	int auth_zone_avoid;
4335469a995SCy Schubert 	/** true if there have been scrubbing failures of reply packets */
4345469a995SCy Schubert 	int scrub_failures;
4355469a995SCy Schubert 	/** true if there have been parse failures of reply packets */
4365469a995SCy Schubert 	int parse_failures;
4375469a995SCy Schubert 	/** a failure printout address for last received answer */
4385469a995SCy Schubert 	struct comm_reply* fail_reply;
439b7579f77SDag-Erling Smørgrav };
440b7579f77SDag-Erling Smørgrav 
441b7579f77SDag-Erling Smørgrav /**
442b7579f77SDag-Erling Smørgrav  * List of prepend items
443b7579f77SDag-Erling Smørgrav  */
444b7579f77SDag-Erling Smørgrav struct iter_prep_list {
445b7579f77SDag-Erling Smørgrav 	/** next in list */
446b7579f77SDag-Erling Smørgrav 	struct iter_prep_list* next;
447b7579f77SDag-Erling Smørgrav 	/** rrset */
448b7579f77SDag-Erling Smørgrav 	struct ub_packed_rrset_key* rrset;
449b7579f77SDag-Erling Smørgrav };
450b7579f77SDag-Erling Smørgrav 
451b7579f77SDag-Erling Smørgrav /**
452b7579f77SDag-Erling Smørgrav  * Get the iterator function block.
453b7579f77SDag-Erling Smørgrav  * @return: function block with function pointers to iterator methods.
454b7579f77SDag-Erling Smørgrav  */
455b7579f77SDag-Erling Smørgrav struct module_func_block* iter_get_funcblock(void);
456b7579f77SDag-Erling Smørgrav 
457b7579f77SDag-Erling Smørgrav /**
458b7579f77SDag-Erling Smørgrav  * Get iterator state as a string
459b7579f77SDag-Erling Smørgrav  * @param state: to convert
460b7579f77SDag-Erling Smørgrav  * @return constant string that is printable.
461b7579f77SDag-Erling Smørgrav  */
462b7579f77SDag-Erling Smørgrav const char* iter_state_to_string(enum iter_state state);
463b7579f77SDag-Erling Smørgrav 
464b7579f77SDag-Erling Smørgrav /**
465b7579f77SDag-Erling Smørgrav  * See if iterator state is a response state
466b7579f77SDag-Erling Smørgrav  * @param s: to inspect
467b7579f77SDag-Erling Smørgrav  * @return true if response state.
468b7579f77SDag-Erling Smørgrav  */
469b7579f77SDag-Erling Smørgrav int iter_state_is_responsestate(enum iter_state s);
470b7579f77SDag-Erling Smørgrav 
471b7579f77SDag-Erling Smørgrav /** iterator init */
472b7579f77SDag-Erling Smørgrav int iter_init(struct module_env* env, int id);
473b7579f77SDag-Erling Smørgrav 
474b7579f77SDag-Erling Smørgrav /** iterator deinit */
475b7579f77SDag-Erling Smørgrav void iter_deinit(struct module_env* env, int id);
476b7579f77SDag-Erling Smørgrav 
477b7579f77SDag-Erling Smørgrav /** iterator operate on a query */
478b7579f77SDag-Erling Smørgrav void iter_operate(struct module_qstate* qstate, enum module_ev event, int id,
479b7579f77SDag-Erling Smørgrav 	struct outbound_entry* outbound);
480b7579f77SDag-Erling Smørgrav 
481b7579f77SDag-Erling Smørgrav /**
4828a384985SDag-Erling Smørgrav  * Return priming query results to interested super querystates.
483b7579f77SDag-Erling Smørgrav  *
484b7579f77SDag-Erling Smørgrav  * Sets the delegation point and delegation message (not nonRD queries).
485b7579f77SDag-Erling Smørgrav  * This is a callback from walk_supers.
486b7579f77SDag-Erling Smørgrav  *
487b7579f77SDag-Erling Smørgrav  * @param qstate: query state that finished.
488b7579f77SDag-Erling Smørgrav  * @param id: module id.
489b7579f77SDag-Erling Smørgrav  * @param super: the qstate to inform.
490b7579f77SDag-Erling Smørgrav  */
491b7579f77SDag-Erling Smørgrav void iter_inform_super(struct module_qstate* qstate, int id,
492b7579f77SDag-Erling Smørgrav 	struct module_qstate* super);
493b7579f77SDag-Erling Smørgrav 
494b7579f77SDag-Erling Smørgrav /** iterator cleanup query state */
495b7579f77SDag-Erling Smørgrav void iter_clear(struct module_qstate* qstate, int id);
496b7579f77SDag-Erling Smørgrav 
497b7579f77SDag-Erling Smørgrav /** iterator alloc size routine */
498b7579f77SDag-Erling Smørgrav size_t iter_get_mem(struct module_env* env, int id);
499b7579f77SDag-Erling Smørgrav 
500b7579f77SDag-Erling Smørgrav #endif /* ITERATOR_ITERATOR_H */
501