]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/iterator/iter_fwd.h
2 * iterator/iter_fwd.h - iterative resolver module forward zones.
4 * Copyright (c) 2007, NLnet Labs. All rights reserved.
6 * This software is open source.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
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.
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.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
27 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
28 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
29 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * This file contains functions to assist the iterator module.
40 * Keep track of forward zones, and read those from config.
43 #ifndef ITERATOR_ITER_FWD_H
44 #define ITERATOR_ITER_FWD_H
45 #include "util/rbtree.h"
50 * Iterator forward zones structure
52 struct iter_forwards
{
54 * Zones are stored in this tree. Sort order is specially chosen.
55 * first sorted on qclass. Then on dname in nsec-like order, so that
56 * a lookup on class, name will return an exact match or the closest
57 * match which gives the ancestor needed.
58 * contents of type iter_forward_zone.
64 * Iterator forward servers for a particular zone.
66 struct iter_forward_zone
{
67 /** redblacktree node, key is this structure: class and name */
73 /** number of labels in name */
75 /** delegation point with forward server information for this zone.
76 * If NULL then this forward entry is used to indicate that a
77 * stub-zone with the same name exists, and should be used.
78 * This delegation point is malloced.
81 /** pointer to parent in tree (or NULL if none) */
82 struct iter_forward_zone
* parent
;
83 /** class. host order. */
89 * @return new forwards or NULL on error.
91 struct iter_forwards
* forwards_create(void);
95 * @param fwd: to delete.
97 void forwards_delete(struct iter_forwards
* fwd
);
100 * Process forwards config.
101 * @param fwd: where to store.
102 * @param cfg: config options.
103 * @return 0 on error.
105 int forwards_apply_cfg(struct iter_forwards
* fwd
, struct config_file
* cfg
);
108 * Find forward zone exactly by name
109 * @param fwd: forward storage.
110 * @param qname: The qname of the query.
111 * @param qclass: The qclass of the query.
112 * @return: A delegation point or null.
114 struct delegpt
* forwards_find(struct iter_forwards
* fwd
, uint8_t* qname
,
118 * Find forward zone information
119 * For this qname/qclass find forward zone information, returns delegation
120 * point with server names and addresses, or NULL if no forwarding is needed.
122 * @param fwd: forward storage.
123 * @param qname: The qname of the query.
124 * @param qclass: The qclass of the query.
125 * @return: A delegation point if the query has to be forwarded to that list,
128 struct delegpt
* forwards_lookup(struct iter_forwards
* fwd
,
129 uint8_t* qname
, uint16_t qclass
);
132 * Same as forwards_lookup, but for the root only
133 * @param fwd: forward storage.
134 * @param qclass: The qclass of the query.
135 * @return: A delegation point if root forward exists, otherwise null.
137 struct delegpt
* forwards_lookup_root(struct iter_forwards
* fwd
,
141 * Find next root item in forwards lookup tree.
142 * @param fwd: the forward storage
143 * @param qclass: class to look at next, or higher.
144 * @return false if none found, or if true stored in qclass.
146 int forwards_next_root(struct iter_forwards
* fwd
, uint16_t* qclass
);
149 * Get memory in use by forward storage
150 * @param fwd: forward storage.
151 * @return bytes in use
153 size_t forwards_get_mem(struct iter_forwards
* fwd
);
155 /** compare two fwd entries */
156 int fwd_cmp(const void* k1
, const void* k2
);
159 * Add zone to forward structure. For external use since it recalcs
161 * @param fwd: the forward data structure
162 * @param c: class of zone
163 * @param dp: delegation point with name and target nameservers for new
164 * forward zone. malloced.
165 * @return false on failure (out of memory);
167 int forwards_add_zone(struct iter_forwards
* fwd
, uint16_t c
,
171 * Remove zone from forward structure. For external use since it
172 * recalcs the tree parents.
173 * @param fwd: the forward data structure
174 * @param c: class of zone
175 * @param nm: name of zone (in uncompressed wireformat).
177 void forwards_delete_zone(struct iter_forwards
* fwd
, uint16_t c
, uint8_t* nm
);
180 * Add stub hole (empty entry in forward table, that makes resolution skip
181 * a forward-zone because the stub zone should override the forward zone).
182 * Does not add one if not necessary.
183 * @param fwd: the forward data structure
184 * @param c: class of zone
185 * @param nm: name of zone (in uncompressed wireformat).
186 * @return false on failure (out of memory);
188 int forwards_add_stub_hole(struct iter_forwards
* fwd
, uint16_t c
, uint8_t* nm
);
191 * Remove stub hole, if one exists.
192 * @param fwd: the forward data structure
193 * @param c: class of zone
194 * @param nm: name of zone (in uncompressed wireformat).
196 void forwards_delete_stub_hole(struct iter_forwards
* fwd
, uint16_t c
,
199 #endif /* ITERATOR_ITER_FWD_H */