]>
git.saurik.com Git - apple/network_cmds.git/blob - unbound/iterator/iter_delegpt.h
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 */
87 * Nameservers for a delegation point.
91 struct delegpt_ns
* next
;
92 /** name of nameserver */
97 * If the name has been resolved. false if not queried for yet.
98 * true if the A, AAAA queries have been generated.
99 * marked true if those queries fail.
100 * and marked true if got4 and got6 are both true.
103 /** if the ipv4 address is in the delegpt */
105 /** if the ipv6 address is in the delegpt */
108 * If the name is parent-side only and thus dispreferred.
109 * Its addresses become dispreferred as well
112 /** if the parent-side ipv4 address has been looked up (last resort).
113 * Also enabled if a parent-side cache entry exists, or a parent-side
114 * negative-cache entry exists. */
116 /** if the parent-side ipv6 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. */
123 * Address of target nameserver in delegation point.
125 struct delegpt_addr
{
126 /** next delegation point in results */
127 struct delegpt_addr
* next_result
;
128 /** next delegation point in usable list */
129 struct delegpt_addr
* next_usable
;
130 /** next delegation point in all targets list */
131 struct delegpt_addr
* next_target
;
133 /** delegation point address */
134 struct sockaddr_storage addr
;
135 /** length of addr */
137 /** number of attempts for this addr */
139 /** rtt stored here in the selection algorithm */
141 /** if true, the A or AAAA RR was bogus, so this address is bad.
142 * Also check the dp->bogus to see if everything is bogus. */
144 /** if true, this address is dispreferred: it is a lame IP address */
146 /** if the address is dnsseclame, but this cannot be cached, this
147 * option is useful to mark the address dnsseclame.
148 * This value is not copied in addr-copy and dp-copy. */
153 * Create new delegation point.
154 * @param regional: where to allocate it.
155 * @return new delegation point or NULL on error.
157 struct delegpt
* delegpt_create(struct regional
* regional
);
160 * Create a copy of a delegation point.
161 * @param dp: delegation point to copy.
162 * @param regional: where to allocate it.
163 * @return new delegation point or NULL on error.
165 struct delegpt
* delegpt_copy(struct delegpt
* dp
, struct regional
* regional
);
168 * Set name of delegation point.
169 * @param dp: delegation point.
170 * @param regional: where to allocate the name copy.
171 * @param name: name to use.
172 * @return false on error.
174 int delegpt_set_name(struct delegpt
* dp
, struct regional
* regional
,
178 * Add a name to the delegation point.
179 * @param dp: delegation point.
180 * @param regional: where to allocate the info.
181 * @param name: domain name in wire format.
182 * @param lame: name is lame, disprefer it.
183 * @return false on error.
185 int delegpt_add_ns(struct delegpt
* dp
, struct regional
* regional
,
186 uint8_t* name
, uint8_t lame
);
189 * Add NS rrset; calls add_ns repeatedly.
190 * @param dp: delegation point.
191 * @param regional: where to allocate the info.
192 * @param ns_rrset: NS rrset.
193 * @param lame: rrset is lame, disprefer it.
194 * @return 0 on alloc error.
196 int delegpt_rrset_add_ns(struct delegpt
* dp
, struct regional
* regional
,
197 struct ub_packed_rrset_key
* ns_rrset
, uint8_t lame
);
200 * Add target address to the delegation point.
201 * @param dp: delegation point.
202 * @param regional: where to allocate the info.
203 * @param name: name for which target was found (must be in nslist).
204 * This name is marked resolved.
205 * @param namelen: length of name.
206 * @param addr: the address.
207 * @param addrlen: the length of addr.
208 * @param bogus: security status for the address, pass true if bogus.
209 * @param lame: address is lame.
210 * @return false on error.
212 int delegpt_add_target(struct delegpt
* dp
, struct regional
* regional
,
213 uint8_t* name
, size_t namelen
, struct sockaddr_storage
* addr
,
214 socklen_t addrlen
, uint8_t bogus
, uint8_t lame
);
217 * Add A RRset to delegpt.
218 * @param dp: delegation point.
219 * @param regional: where to allocate the info.
220 * @param rrset: RRset A to add.
221 * @param lame: rrset is lame, disprefer it.
222 * @return 0 on alloc error.
224 int delegpt_add_rrset_A(struct delegpt
* dp
, struct regional
* regional
,
225 struct ub_packed_rrset_key
* rrset
, uint8_t lame
);
228 * Add AAAA RRset to delegpt.
229 * @param dp: delegation point.
230 * @param regional: where to allocate the info.
231 * @param rrset: RRset AAAA to add.
232 * @param lame: rrset is lame, disprefer it.
233 * @return 0 on alloc error.
235 int delegpt_add_rrset_AAAA(struct delegpt
* dp
, struct regional
* regional
,
236 struct ub_packed_rrset_key
* rrset
, uint8_t lame
);
239 * Add any RRset to delegpt.
240 * Does not check for duplicates added.
241 * @param dp: delegation point.
242 * @param regional: where to allocate the info.
243 * @param rrset: RRset to add, NS, A, AAAA.
244 * @param lame: rrset is lame, disprefer it.
245 * @return 0 on alloc error.
247 int delegpt_add_rrset(struct delegpt
* dp
, struct regional
* regional
,
248 struct ub_packed_rrset_key
* rrset
, uint8_t lame
);
251 * Add address to the delegation point. No servername is associated or checked.
252 * @param dp: delegation point.
253 * @param regional: where to allocate the info.
254 * @param addr: the address.
255 * @param addrlen: the length of addr.
256 * @param bogus: if address is bogus.
257 * @param lame: if address is lame.
258 * @return false on error.
260 int delegpt_add_addr(struct delegpt
* dp
, struct regional
* regional
,
261 struct sockaddr_storage
* addr
, socklen_t addrlen
,
262 uint8_t bogus
, uint8_t lame
);
265 * Find NS record in name list of delegation point.
266 * @param dp: delegation point.
267 * @param name: name of nameserver to look for, uncompressed wireformat.
268 * @param namelen: length of name.
269 * @return the ns structure or NULL if not found.
271 struct delegpt_ns
* delegpt_find_ns(struct delegpt
* dp
, uint8_t* name
,
275 * Find address record in total list of delegation point.
276 * @param dp: delegation point.
277 * @param addr: address
278 * @param addrlen: length of addr
279 * @return the addr structure or NULL if not found.
281 struct delegpt_addr
* delegpt_find_addr(struct delegpt
* dp
,
282 struct sockaddr_storage
* addr
, socklen_t addrlen
);
285 * Print the delegation point to the log. For debugging.
286 * @param v: verbosity value that is needed to emit to log.
287 * @param dp: delegation point.
289 void delegpt_log(enum verbosity_value v
, struct delegpt
* dp
);
291 /** count NS and number missing for logging */
292 void delegpt_count_ns(struct delegpt
* dp
, size_t* numns
, size_t* missing
);
294 /** count addresses, and number in result and available lists, for logging */
295 void delegpt_count_addr(struct delegpt
* dp
, size_t* numaddr
, size_t* numres
,
299 * Add all usable targets to the result list.
300 * @param dp: delegation point.
302 void delegpt_add_unused_targets(struct delegpt
* dp
);
305 * Count number of missing targets. These are ns names with no resolved flag.
306 * @param dp: delegation point.
307 * @return number of missing targets (or 0).
309 size_t delegpt_count_missing_targets(struct delegpt
* dp
);
311 /** count total number of targets in dp */
312 size_t delegpt_count_targets(struct delegpt
* dp
);
315 * Create new delegation point from a dns message
317 * Note that this method does not actually test to see if the message is an
318 * actual referral. It really is just checking to see if it can construct a
319 * delegation point, so the message could be of some other type (some ANSWER
320 * messages, some CNAME messages, generally.) Note that the resulting
321 * DelegationPoint will contain targets for all "relevant" glue (i.e.,
322 * address records whose ownernames match the target of one of the NS
323 * records), so if policy dictates that some glue should be discarded beyond
324 * that, discard it before calling this method. Note that this method will
325 * find "glue" in either the ADDITIONAL section or the ANSWER section.
327 * @param msg: the dns message, referral.
328 * @param regional: where to allocate delegation point.
329 * @return new delegation point or NULL on alloc error, or if the
330 * message was not appropriate.
332 struct delegpt
* delegpt_from_message(struct dns_msg
* msg
,
333 struct regional
* regional
);
336 * Add negative message to delegation point.
337 * @param dp: delegation point.
338 * @param msg: the message added, marks off A or AAAA from an NS entry.
340 void delegpt_add_neg_msg(struct delegpt
* dp
, struct msgreply_entry
* msg
);
343 * Register the fact that there is no ipv6 and thus AAAAs are not going
344 * to be queried for or be useful.
345 * @param dp: the delegation point. Updated to reflect no ipv6.
347 void delegpt_no_ipv6(struct delegpt
* dp
);
350 * Register the fact that there is no ipv4 and thus As are not going
351 * to be queried for or be useful.
352 * @param dp: the delegation point. Updated to reflect no ipv4.
354 void delegpt_no_ipv4(struct delegpt
* dp
);
357 * create malloced delegation point, with the given name
358 * @param name: uncompressed wireformat of degegpt name.
359 * @return NULL on alloc failure
361 struct delegpt
* delegpt_create_mlc(uint8_t* name
);
364 * free malloced delegation point.
365 * @param dp: must have been created with delegpt_create_mlc, free'd.
367 void delegpt_free_mlc(struct delegpt
* dp
);
370 * Set name of delegation point.
371 * @param dp: delegation point. malloced.
372 * @param name: name to use.
373 * @return false on error.
375 int delegpt_set_name_mlc(struct delegpt
* dp
, uint8_t* name
);
378 * add a name to malloced delegation point.
379 * @param dp: must have been created with delegpt_create_mlc.
380 * @param name: the name to add.
381 * @param lame: the name is lame, disprefer.
382 * @return false on error.
384 int delegpt_add_ns_mlc(struct delegpt
* dp
, uint8_t* name
, uint8_t lame
);
387 * add an address to a malloced delegation point.
388 * @param dp: must have been created with delegpt_create_mlc.
389 * @param addr: the address.
390 * @param addrlen: the length of addr.
391 * @param bogus: if address is bogus.
392 * @param lame: if address is lame.
393 * @return false on error.
395 int delegpt_add_addr_mlc(struct delegpt
* dp
, struct sockaddr_storage
* addr
,
396 socklen_t addrlen
, uint8_t bogus
, uint8_t lame
);
399 * Add target address to the delegation point.
400 * @param dp: must have been created with delegpt_create_mlc.
401 * @param name: name for which target was found (must be in nslist).
402 * This name is marked resolved.
403 * @param namelen: length of name.
404 * @param addr: the address.
405 * @param addrlen: the length of addr.
406 * @param bogus: security status for the address, pass true if bogus.
407 * @param lame: address is lame.
408 * @return false on error.
410 int delegpt_add_target_mlc(struct delegpt
* dp
, uint8_t* name
, size_t namelen
,
411 struct sockaddr_storage
* addr
, socklen_t addrlen
, uint8_t bogus
,
414 /** get memory in use by dp */
415 size_t delegpt_get_mem(struct delegpt
* dp
);
417 #endif /* ITERATOR_ITER_DELEGPT_H */