xref: /openbsd-src/usr.sbin/unbound/iterator/iter_hints.h (revision 4c1e55dc91edd6e69ccc60ce855900fbc12cf34f)
1 /*
2  * iterator/iter_hints.h - iterative resolver module stub and root hints.
3  *
4  * Copyright (c) 2007, NLnet Labs. All rights reserved.
5  *
6  * This software is open source.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * Neither the name of the NLNET LABS nor the names of its contributors may
20  * be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
26  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 /**
37  * \file
38  *
39  * This file contains functions to assist the iterator module.
40  * Keep track of stub and root hints, and read those from config.
41  */
42 
43 #ifndef ITERATOR_ITER_HINTS_H
44 #define ITERATOR_ITER_HINTS_H
45 #include "util/storage/dnstree.h"
46 struct iter_env;
47 struct config_file;
48 struct delegpt;
49 struct regional;
50 
51 /**
52  * Iterator hints structure
53  */
54 struct iter_hints {
55 	/** regional where hints are allocated */
56 	struct regional* region;
57 	/**
58 	 * Hints are stored in this tree. Sort order is specially chosen.
59 	 * first sorted on qclass. Then on dname in nsec-like order, so that
60 	 * a lookup on class, name will return an exact match or the closest
61 	 * match which gives the ancestor needed.
62 	 * contents of type iter_hints_stub. The class IN root is in here.
63 	 * uses name_tree_node from dnstree.h.
64 	 */
65 	rbtree_t tree;
66 };
67 
68 /**
69  * Iterator hints for a particular stub.
70  */
71 struct iter_hints_stub {
72 	/** tree sorted by name, class */
73 	struct name_tree_node node;
74 	/** delegation point with hint information for this stub. */
75 	struct delegpt* dp;
76 	/** does the stub need to forego priming (like on other ports) */
77 	uint8_t noprime;
78 };
79 
80 /**
81  * Create hints
82  * @return new hints or NULL on error.
83  */
84 struct iter_hints* hints_create(void);
85 
86 /**
87  * Delete hints.
88  * @param hints: to delete.
89  */
90 void hints_delete(struct iter_hints* hints);
91 
92 /**
93  * Process hints config. Sets default values for root hints if no config.
94  * @param hints: where to store.
95  * @param cfg: config options.
96  * @return 0 on error.
97  */
98 int hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg);
99 
100 /**
101  * Find root hints for the given class.
102  * @param hints: hint storage.
103  * @param qclass: class for which root hints are requested. host order.
104  * @return: NULL if no hints, or a ptr to stored hints.
105  */
106 struct delegpt* hints_lookup_root(struct iter_hints* hints, uint16_t qclass);
107 
108 /**
109  * Find next root hints (to cycle through all root hints).
110  * @param hints: hint storage
111  * @param qclass: class for which root hints are sought.
112  * 	0 means give the first available root hints class.
113  * 	x means, give class x or a higher class if any.
114  * 	returns the found class in this variable.
115  * @return true if a root hint class is found.
116  * 	false if not root hint class is found (qclass may have been changed).
117  */
118 int hints_next_root(struct iter_hints* hints, uint16_t* qclass);
119 
120 /**
121  * Given a qname/qclass combination, and the delegation point from the cache
122  * for this qname/qclass, determine if this combination indicates that a
123  * stub hint exists and must be primed.
124  *
125  * @param hints: hint storage.
126  * @param qname: The qname that generated the delegation point.
127  * @param qclass: The qclass that generated the delegation point.
128  * @param dp: The cache generated delegation point.
129  * @return: A priming delegation point if there is a stub hint that must
130  *         be primed, otherwise null.
131  */
132 struct iter_hints_stub* hints_lookup_stub(struct iter_hints* hints,
133 	uint8_t* qname, uint16_t qclass, struct delegpt* dp);
134 
135 /**
136  * Get memory in use by hints
137  * @param hints: hint storage.
138  * @return bytes in use
139  */
140 size_t hints_get_mem(struct iter_hints* hints);
141 
142 #endif /* ITERATOR_ITER_HINTS_H */
143