2 * iterator/iter_delegpt.h - delegation point with NS and address information.
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 implements the Delegation Point. It contains a list of name servers
40 * and their addresses if known.
43 #ifndef ITERATOR_ITER_DELEGPT_H
44 #define ITERATOR_ITER_DELEGPT_H
50 struct ub_packed_rrset_key;
51 struct msgreply_entry;
55 * For a domain name, the NS rrset, and the A and AAAA records for those.
58 /** the domain name of the delegation point. */
60 /** length of the delegation point name */
62 /** number of labels in delegation point */
65 /** the nameservers, names from the NS RRset rdata. */
66 struct delegpt_ns* nslist;
67 /** the target addresses for delegation */
68 struct delegpt_addr* target_list;
69 /** the list of usable targets; subset of target_list
70 * the items in this list are not part of the result list. */
71 struct delegpt_addr* usable_list;
72 /** the list of returned targets; subset of target_list */
73 struct delegpt_addr* result_list;
75 /** if true, the NS RRset was bogus. All info is bad. */
77 /** if true, the parent-side NS record has been applied:
78 * its names have been added and their addresses can follow later.
79 * Also true if the delegationpoint was created from a delegation
80 * message and thus contains the parent-side-info already. */
81 uint8_t has_parent_side_NS;
82 /** for assertions on type of delegpt */
84 /** use SSL for upstream query */
86 /** delegpt from authoritative zone that is locally hosted */
91 * Nameservers for a delegation point.
95 struct delegpt_ns* next;
96 /** name of nameserver */
101 * If the name has been resolved. false if not queried for yet.
102 * true if the A, AAAA queries have been generated.
103 * marked true if those queries fail.
104 * and marked true if got4 and got6 are both true.
107 /** if the ipv4 address is in the delegpt */
109 /** if the ipv6 address is in the delegpt */
112 * If the name is parent-side only and thus dispreferred.
113 * Its addresses become dispreferred as well
116 /** if the parent-side ipv4 address has been looked up (last resort).
117 * Also enabled if a parent-side cache entry exists, or a parent-side
118 * negative-cache entry exists. */
120 /** if the parent-side ipv6 address has been looked up (last resort).
121 * Also enabled if a parent-side cache entry exists, or a parent-side
122 * negative-cache entry exists. */
127 * Address of target nameserver in delegation point.
129 struct delegpt_addr {
130 /** next delegation point in results */
131 struct delegpt_addr* next_result;
132 /** next delegation point in usable list */
133 struct delegpt_addr* next_usable;
134 /** next delegation point in all targets list */
135 struct delegpt_addr* next_target;
137 /** delegation point address */
138 struct sockaddr_storage addr;
139 /** length of addr */
141 /** number of attempts for this addr */
143 /** rtt stored here in the selection algorithm */
145 /** if true, the A or AAAA RR was bogus, so this address is bad.
146 * Also check the dp->bogus to see if everything is bogus. */
148 /** if true, this address is dispreferred: it is a lame IP address */
150 /** if the address is dnsseclame, but this cannot be cached, this
151 * option is useful to mark the address dnsseclame.
152 * This value is not copied in addr-copy and dp-copy. */
154 /** the TLS authentication name, (if not NULL) to use. */
159 * Create new delegation point.
160 * @param regional: where to allocate it.
161 * @return new delegation point or NULL on error.
163 struct delegpt* delegpt_create(struct regional* regional);
166 * Create a copy of a delegation point.
167 * @param dp: delegation point to copy.
168 * @param regional: where to allocate it.
169 * @return new delegation point or NULL on error.
171 struct delegpt* delegpt_copy(struct delegpt* dp, struct regional* regional);
174 * Set name of delegation point.
175 * @param dp: delegation point.
176 * @param regional: where to allocate the name copy.
177 * @param name: name to use.
178 * @return false on error.
180 int delegpt_set_name(struct delegpt* dp, struct regional* regional,
184 * Add a name to the delegation point.
185 * @param dp: delegation point.
186 * @param regional: where to allocate the info.
187 * @param name: domain name in wire format.
188 * @param lame: name is lame, disprefer it.
189 * @return false on error.
191 int delegpt_add_ns(struct delegpt* dp, struct regional* regional,
192 uint8_t* name, uint8_t lame);
195 * Add NS rrset; calls add_ns repeatedly.
196 * @param dp: delegation point.
197 * @param regional: where to allocate the info.
198 * @param ns_rrset: NS rrset.
199 * @param lame: rrset is lame, disprefer it.
200 * @return 0 on alloc error.
202 int delegpt_rrset_add_ns(struct delegpt* dp, struct regional* regional,
203 struct ub_packed_rrset_key* ns_rrset, uint8_t lame);
206 * Add target address to the delegation point.
207 * @param dp: delegation point.
208 * @param regional: where to allocate the info.
209 * @param name: name for which target was found (must be in nslist).
210 * This name is marked resolved.
211 * @param namelen: length of name.
212 * @param addr: the address.
213 * @param addrlen: the length of addr.
214 * @param bogus: security status for the address, pass true if bogus.
215 * @param lame: address is lame.
216 * @return false on error.
218 int delegpt_add_target(struct delegpt* dp, struct regional* regional,
219 uint8_t* name, size_t namelen, struct sockaddr_storage* addr,
220 socklen_t addrlen, uint8_t bogus, uint8_t lame);
223 * Add A RRset to delegpt.
224 * @param dp: delegation point.
225 * @param regional: where to allocate the info.
226 * @param rrset: RRset A to add.
227 * @param lame: rrset is lame, disprefer it.
228 * @return 0 on alloc error.
230 int delegpt_add_rrset_A(struct delegpt* dp, struct regional* regional,
231 struct ub_packed_rrset_key* rrset, uint8_t lame);
234 * Add AAAA RRset to delegpt.
235 * @param dp: delegation point.
236 * @param regional: where to allocate the info.
237 * @param rrset: RRset AAAA to add.
238 * @param lame: rrset is lame, disprefer it.
239 * @return 0 on alloc error.
241 int delegpt_add_rrset_AAAA(struct delegpt* dp, struct regional* regional,
242 struct ub_packed_rrset_key* rrset, uint8_t lame);
245 * Add any RRset to delegpt.
246 * Does not check for duplicates added.
247 * @param dp: delegation point.
248 * @param regional: where to allocate the info.
249 * @param rrset: RRset to add, NS, A, AAAA.
250 * @param lame: rrset is lame, disprefer it.
251 * @return 0 on alloc error.
253 int delegpt_add_rrset(struct delegpt* dp, struct regional* regional,
254 struct ub_packed_rrset_key* rrset, uint8_t lame);
257 * Add address to the delegation point. No servername is associated or checked.
258 * @param dp: delegation point.
259 * @param regional: where to allocate the info.
260 * @param addr: the address.
261 * @param addrlen: the length of addr.
262 * @param bogus: if address is bogus.
263 * @param lame: if address is lame.
264 * @param tls_auth_name: TLS authentication name (or NULL).
265 * @return false on error.
267 int delegpt_add_addr(struct delegpt* dp, struct regional* regional,
268 struct sockaddr_storage* addr, socklen_t addrlen,
269 uint8_t bogus, uint8_t lame, char* tls_auth_name);
272 * Find NS record in name list of delegation point.
273 * @param dp: delegation point.
274 * @param name: name of nameserver to look for, uncompressed wireformat.
275 * @param namelen: length of name.
276 * @return the ns structure or NULL if not found.
278 struct delegpt_ns* delegpt_find_ns(struct delegpt* dp, uint8_t* name,
282 * Find address record in total list of delegation point.
283 * @param dp: delegation point.
284 * @param addr: address
285 * @param addrlen: length of addr
286 * @return the addr structure or NULL if not found.
288 struct delegpt_addr* delegpt_find_addr(struct delegpt* dp,
289 struct sockaddr_storage* addr, socklen_t addrlen);
292 * Print the delegation point to the log. For debugging.
293 * @param v: verbosity value that is needed to emit to log.
294 * @param dp: delegation point.
296 void delegpt_log(enum verbosity_value v, struct delegpt* dp);
298 /** count NS and number missing for logging */
299 void delegpt_count_ns(struct delegpt* dp, size_t* numns, size_t* missing);
301 /** count addresses, and number in result and available lists, for logging */
302 void delegpt_count_addr(struct delegpt* dp, size_t* numaddr, size_t* numres,
306 * Add all usable targets to the result list.
307 * @param dp: delegation point.
309 void delegpt_add_unused_targets(struct delegpt* dp);
312 * Count number of missing targets. These are ns names with no resolved flag.
313 * @param dp: delegation point.
314 * @return number of missing targets (or 0).
316 size_t delegpt_count_missing_targets(struct delegpt* dp);
318 /** count total number of targets in dp */
319 size_t delegpt_count_targets(struct delegpt* dp);
322 * Create new delegation point from a dns message
324 * Note that this method does not actually test to see if the message is an
325 * actual referral. It really is just checking to see if it can construct a
326 * delegation point, so the message could be of some other type (some ANSWER
327 * messages, some CNAME messages, generally.) Note that the resulting
328 * DelegationPoint will contain targets for all "relevant" glue (i.e.,
329 * address records whose ownernames match the target of one of the NS
330 * records), so if policy dictates that some glue should be discarded beyond
331 * that, discard it before calling this method. Note that this method will
332 * find "glue" in either the ADDITIONAL section or the ANSWER section.
334 * @param msg: the dns message, referral.
335 * @param regional: where to allocate delegation point.
336 * @return new delegation point or NULL on alloc error, or if the
337 * message was not appropriate.
339 struct delegpt* delegpt_from_message(struct dns_msg* msg,
340 struct regional* regional);
343 * Add negative message to delegation point.
344 * @param dp: delegation point.
345 * @param msg: the message added, marks off A or AAAA from an NS entry.
347 void delegpt_add_neg_msg(struct delegpt* dp, struct msgreply_entry* msg);
350 * Register the fact that there is no ipv6 and thus AAAAs are not going
351 * to be queried for or be useful.
352 * @param dp: the delegation point. Updated to reflect no ipv6.
354 void delegpt_no_ipv6(struct delegpt* dp);
357 * Register the fact that there is no ipv4 and thus As are not going
358 * to be queried for or be useful.
359 * @param dp: the delegation point. Updated to reflect no ipv4.
361 void delegpt_no_ipv4(struct delegpt* dp);
364 * create malloced delegation point, with the given name
365 * @param name: uncompressed wireformat of delegpt name.
366 * @return NULL on alloc failure
368 struct delegpt* delegpt_create_mlc(uint8_t* name);
371 * free malloced delegation point.
372 * @param dp: must have been created with delegpt_create_mlc, free'd.
374 void delegpt_free_mlc(struct delegpt* dp);
377 * Set name of delegation point.
378 * @param dp: delegation point. malloced.
379 * @param name: name to use.
380 * @return false on error.
382 int delegpt_set_name_mlc(struct delegpt* dp, uint8_t* name);
385 * add a name to malloced delegation point.
386 * @param dp: must have been created with delegpt_create_mlc.
387 * @param name: the name to add.
388 * @param lame: the name is lame, disprefer.
389 * @return false on error.
391 int delegpt_add_ns_mlc(struct delegpt* dp, uint8_t* name, uint8_t lame);
394 * add an address to a malloced delegation point.
395 * @param dp: must have been created with delegpt_create_mlc.
396 * @param addr: the address.
397 * @param addrlen: the length of addr.
398 * @param bogus: if address is bogus.
399 * @param lame: if address is lame.
400 * @param tls_auth_name: TLS authentication name (or NULL).
401 * @return false on error.
403 int delegpt_add_addr_mlc(struct delegpt* dp, struct sockaddr_storage* addr,
404 socklen_t addrlen, uint8_t bogus, uint8_t lame, char* tls_auth_name);
407 * Add target address to the delegation point.
408 * @param dp: must have been created with delegpt_create_mlc.
409 * @param name: name for which target was found (must be in nslist).
410 * This name is marked resolved.
411 * @param namelen: length of name.
412 * @param addr: the address.
413 * @param addrlen: the length of addr.
414 * @param bogus: security status for the address, pass true if bogus.
415 * @param lame: address is lame.
416 * @return false on error.
418 int delegpt_add_target_mlc(struct delegpt* dp, uint8_t* name, size_t namelen,
419 struct sockaddr_storage* addr, socklen_t addrlen, uint8_t bogus,
422 /** get memory in use by dp */
423 size_t delegpt_get_mem(struct delegpt* dp);
425 #endif /* ITERATOR_ITER_DELEGPT_H */