iter_delegpt.c File Reference

This file implements the Delegation Point. More...

#include "config.h"
#include "iterator/iter_delegpt.h"
#include "services/cache/dns.h"
#include "util/regional.h"
#include "util/data/dname.h"
#include "util/data/packed_rrset.h"
#include "util/data/msgreply.h"
#include "util/net_help.h"
#include "sldns/rrdef.h"
#include "sldns/sbuffer.h"

Functions

struct delegptdelegpt_create (struct regional *region)
 Create new delegation point. More...
 
struct delegptdelegpt_copy (struct delegpt *dp, struct regional *region)
 Create a copy of a delegation point. More...
 
int delegpt_set_name (struct delegpt *dp, struct regional *region, uint8_t *name)
 Set name of delegation point. More...
 
int delegpt_add_ns (struct delegpt *dp, struct regional *region, uint8_t *name, uint8_t lame, char *tls_auth_name, int port)
 Add a name to the delegation point. More...
 
struct delegpt_nsdelegpt_find_ns (struct delegpt *dp, uint8_t *name, size_t namelen)
 Find NS record in name list of delegation point. More...
 
struct delegpt_addrdelegpt_find_addr (struct delegpt *dp, struct sockaddr_storage *addr, socklen_t addrlen)
 Find address record in total list of delegation point. More...
 
int delegpt_add_target (struct delegpt *dp, struct regional *region, uint8_t *name, size_t namelen, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t bogus, uint8_t lame, int *additions)
 Add target address to the delegation point. More...
 
int delegpt_add_addr (struct delegpt *dp, struct regional *region, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t bogus, uint8_t lame, char *tls_auth_name, int port, int *additions)
 Add address to the delegation point. More...
 
void delegpt_count_ns (struct delegpt *dp, size_t *numns, size_t *missing)
 count NS and number missing for logging
 
void delegpt_count_addr (struct delegpt *dp, size_t *numaddr, size_t *numres, size_t *numavail)
 count addresses, and number in result and available lists, for logging
 
void delegpt_log (enum verbosity_value v, struct delegpt *dp)
 Print the delegation point to the log. More...
 
int delegpt_addr_on_result_list (struct delegpt *dp, struct delegpt_addr *find)
 See if the addr is on the result list. More...
 
void delegpt_usable_list_remove_addr (struct delegpt *dp, struct delegpt_addr *del)
 Remove the addr from the usable list. More...
 
void delegpt_add_to_result_list (struct delegpt *dp, struct delegpt_addr *a)
 Add the delegpt_addr back to the result list, if it is not already on the result list. More...
 
void delegpt_add_unused_targets (struct delegpt *dp)
 Add all usable targets to the result list. More...
 
size_t delegpt_count_targets (struct delegpt *dp)
 count total number of targets in dp
 
size_t delegpt_count_missing_targets (struct delegpt *dp, int *alllame)
 Count number of missing targets. More...
 
static struct ub_packed_rrset_keyfind_NS (struct reply_info *rep, size_t from, size_t to)
 find NS rrset in given list
 
struct delegptdelegpt_from_message (struct dns_msg *msg, struct regional *region)
 Create new delegation point from a dns message. More...
 
int delegpt_rrset_add_ns (struct delegpt *dp, struct regional *region, struct ub_packed_rrset_key *ns_rrset, uint8_t lame)
 Add NS rrset; calls add_ns repeatedly. More...
 
int delegpt_add_rrset_A (struct delegpt *dp, struct regional *region, struct ub_packed_rrset_key *ak, uint8_t lame, int *additions)
 Add A RRset to delegpt. More...
 
int delegpt_add_rrset_AAAA (struct delegpt *dp, struct regional *region, struct ub_packed_rrset_key *ak, uint8_t lame, int *additions)
 Add AAAA RRset to delegpt. More...
 
int delegpt_add_rrset (struct delegpt *dp, struct regional *region, struct ub_packed_rrset_key *rrset, uint8_t lame, int *additions)
 Add any RRset to delegpt. More...
 
void delegpt_mark_neg (struct delegpt_ns *ns, uint16_t qtype)
 Mark negative return in delegation point for specific nameserver. More...
 
void delegpt_add_neg_msg (struct delegpt *dp, struct msgreply_entry *msg)
 Add negative message to delegation point. More...
 
void delegpt_no_ipv6 (struct delegpt *dp)
 Register the fact that there is no ipv6 and thus AAAAs are not going to be queried for or be useful. More...
 
void delegpt_no_ipv4 (struct delegpt *dp)
 Register the fact that there is no ipv4 and thus As are not going to be queried for or be useful. More...
 
struct delegptdelegpt_create_mlc (uint8_t *name)
 create malloced delegation point, with the given name More...
 
void delegpt_free_mlc (struct delegpt *dp)
 free malloced delegation point. More...
 
int delegpt_set_name_mlc (struct delegpt *dp, uint8_t *name)
 Set name of delegation point. More...
 
int delegpt_add_ns_mlc (struct delegpt *dp, uint8_t *name, uint8_t lame, char *tls_auth_name, int port)
 add a name to malloced delegation point. More...
 
int delegpt_add_addr_mlc (struct delegpt *dp, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t bogus, uint8_t lame, char *tls_auth_name, int port)
 add an address to a malloced delegation point. More...
 
int delegpt_add_target_mlc (struct delegpt *dp, uint8_t *name, size_t namelen, struct sockaddr_storage *addr, socklen_t addrlen, uint8_t bogus, uint8_t lame)
 Add target address to the delegation point. More...
 
size_t delegpt_get_mem (struct delegpt *dp)
 get memory in use by dp
 

Detailed Description

This file implements the Delegation Point.

It contains a list of name servers and their addresses if known.

Function Documentation

◆ delegpt_create()

struct delegpt* delegpt_create ( struct regional regional)

Create new delegation point.

Parameters
regionalwhere to allocate it.
Returns
new delegation point or NULL on error.

References regional_alloc().

Referenced by delegpt_copy(), delegpt_from_message(), and dns_cache_find_delegation().

◆ delegpt_copy()

◆ delegpt_set_name()

int delegpt_set_name ( struct delegpt dp,
struct regional regional,
uint8_t *  name 
)

Set name of delegation point.

Parameters
dpdelegation point.
regionalwhere to allocate the name copy.
namename to use.
Returns
false on error.

References dname_count_size_labels(), delegpt::dp_type_mlc, log_assert, delegpt::name, delegpt::namelabs, delegpt::namelen, and regional_alloc_init().

Referenced by delegpt_copy(), delegpt_from_message(), and dns_cache_find_delegation().

◆ delegpt_add_ns()

int delegpt_add_ns ( struct delegpt dp,
struct regional regional,
uint8_t *  name,
uint8_t  lame,
char *  tls_auth_name,
int  port 
)

Add a name to the delegation point.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
namedomain name in wire format.
lamename is lame, disprefer it.
tls_auth_nameTLS authentication name (or NULL).
portport to use for resolved addresses.
Returns
false on error.

References delegpt_ns::cache_lookup_count, delegpt_find_ns(), dname_count_size_labels(), delegpt_ns::done_pside4, delegpt_ns::done_pside6, delegpt::dp_type_mlc, delegpt_ns::got4, delegpt_ns::got6, delegpt_ns::lame, log_assert, delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::next, delegpt::nslist, delegpt_ns::port, regional_alloc(), regional_alloc_init(), regional_strdup(), delegpt_ns::resolved, and delegpt_ns::tls_auth_name.

Referenced by delegpt_copy().

◆ delegpt_find_ns()

struct delegpt_ns* delegpt_find_ns ( struct delegpt dp,
uint8_t *  name,
size_t  namelen 
)

Find NS record in name list of delegation point.

Parameters
dpdelegation point.
namename of nameserver to look for, uncompressed wireformat.
namelenlength of name.
Returns
the ns structure or NULL if not found.

References delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::next, delegpt::nslist, and query_dname_compare().

Referenced by delegpt_add_neg_msg(), delegpt_add_ns(), delegpt_add_ns_mlc(), delegpt_add_target(), delegpt_add_target_mlc(), error_supers(), and iter_dp_is_useless().

◆ delegpt_find_addr()

struct delegpt_addr* delegpt_find_addr ( struct delegpt dp,
struct sockaddr_storage *  addr,
socklen_t  addrlen 
)

Find address record in total list of delegation point.

Parameters
dpdelegation point.
addraddress
addrlenlength of addr
Returns
the addr structure or NULL if not found.

References delegpt_addr::addr, delegpt_addr::addrlen, delegpt_addr::next_target, sockaddr_cmp_addr(), and delegpt::target_list.

Referenced by delegpt_add_addr(), delegpt_add_addr_mlc(), iter_merge_retry_counts(), and processQueryResponse().

◆ delegpt_add_target()

int delegpt_add_target ( struct delegpt dp,
struct regional regional,
uint8_t *  name,
size_t  namelen,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t  bogus,
uint8_t  lame,
int *  additions 
)

Add target address to the delegation point.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
namename for which target was found (must be in nslist). This name is marked resolved.
namelenlength of name.
addrthe address.
addrlenthe length of addr.
bogussecurity status for the address, pass true if bogus.
lameaddress is lame.
additionswill be set to 1 if a new address is added
Returns
false on error.

References addr_is_ip6(), delegpt_add_addr(), delegpt_find_ns(), delegpt_ns::done_pside4, delegpt_ns::done_pside6, delegpt::dp_type_mlc, delegpt_ns::got4, delegpt_ns::got6, delegpt_ns::lame, log_assert, delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::port, delegpt_ns::resolved, and delegpt_ns::tls_auth_name.

Referenced by delegpt_add_rrset_A(), and delegpt_add_rrset_AAAA().

◆ delegpt_add_addr()

int delegpt_add_addr ( struct delegpt dp,
struct regional regional,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t  bogus,
uint8_t  lame,
char *  tls_auth_name,
int  port,
int *  additions 
)

Add address to the delegation point.

No servername is associated or checked.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
addrthe address.
addrlenthe length of addr.
bogusif address is bogus.
lameif address is lame.
tls_auth_nameTLS authentication name (or NULL).
portthe port to use; if -1 the port is taken from addr.
additionswill be set to 1 if a new address is added
Returns
false on error.

References delegpt_addr::addr, delegpt_addr::addrlen, delegpt_addr::attempts, delegpt_addr::bogus, delegpt_find_addr(), delegpt_addr::dnsseclame, delegpt::dp_type_mlc, delegpt_addr::lame, log_assert, delegpt_addr::next_result, delegpt_addr::next_target, delegpt_addr::next_usable, regional_alloc(), regional_strdup(), sockaddr_store_port(), delegpt::target_list, delegpt_addr::tls_auth_name, and delegpt::usable_list.

Referenced by delegpt_add_target(), and delegpt_copy().

◆ delegpt_log()

◆ delegpt_addr_on_result_list()

int delegpt_addr_on_result_list ( struct delegpt dp,
struct delegpt_addr find 
)

See if the addr is on the result list.

Parameters
dpdelegation point.
findthe pointer is searched for on the result list.
Returns
1 if found, 0 if not found.

References delegpt_addr::next_result, and delegpt::result_list.

Referenced by delegpt_add_to_result_list().

◆ delegpt_usable_list_remove_addr()

void delegpt_usable_list_remove_addr ( struct delegpt dp,
struct delegpt_addr del 
)

Remove the addr from the usable list.

Parameters
dpthe delegation point.
delthe addr to remove from the list, the pointer is searched for.

References delegpt_addr::next_usable, and delegpt::usable_list.

Referenced by delegpt_add_to_result_list().

◆ delegpt_add_to_result_list()

void delegpt_add_to_result_list ( struct delegpt dp,
struct delegpt_addr a 
)

Add the delegpt_addr back to the result list, if it is not already on the result list.

Also removes it from the usable list.

Parameters
dpdelegation point.
aaddr to add, nothing happens if it is already on the result list. It is removed from the usable list.

References delegpt_addr_on_result_list(), delegpt_usable_list_remove_addr(), delegpt_addr::next_result, and delegpt::result_list.

Referenced by iter_dec_attempts().

◆ delegpt_add_unused_targets()

void delegpt_add_unused_targets ( struct delegpt dp)

Add all usable targets to the result list.

Parameters
dpdelegation point.

References delegpt_addr::next_result, delegpt_addr::next_usable, delegpt::result_list, and delegpt::usable_list.

◆ delegpt_count_missing_targets()

size_t delegpt_count_missing_targets ( struct delegpt dp,
int *  alllame 
)

Count number of missing targets.

These are ns names with no resolved flag.

Parameters
dpdelegation point.
alllameif set, check if all the missing targets are lame.
Returns
number of missing targets (or 0).

References delegpt_ns::lame, delegpt_ns::next, delegpt::nslist, and delegpt_ns::resolved.

Referenced by iter_filter_order(), and query_for_targets().

◆ delegpt_from_message()

struct delegpt* delegpt_from_message ( struct dns_msg msg,
struct regional regional 
)

Create new delegation point from a dns message.

Note that this method does not actually test to see if the message is an actual referral. It really is just checking to see if it can construct a delegation point, so the message could be of some other type (some ANSWER messages, some CNAME messages, generally.) Note that the resulting DelegationPoint will contain targets for all "relevant" glue (i.e., address records whose ownernames match the target of one of the NS records), so if policy dictates that some glue should be discarded beyond that, discard it before calling this method. Note that this method will find "glue" in either the ADDITIONAL section or the ANSWER section.

Parameters
msgthe dns message, referral.
regionalwhere to allocate delegation point.
Returns
new delegation point or NULL on alloc error, or if the message was not appropriate.

References reply_info::an_numrrsets, delegpt_add_rrset_A(), delegpt_add_rrset_AAAA(), delegpt_create(), delegpt_rrset_add_ns(), delegpt_set_name(), packed_rrset_key::dname, find_NS(), delegpt::has_parent_side_NS, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, reply_info::ns_numrrsets, dns_msg::rep, ub_packed_rrset_key::rk, reply_info::rrset_count, reply_info::rrsets, and packed_rrset_key::type.

◆ delegpt_rrset_add_ns()

int delegpt_rrset_add_ns ( struct delegpt dp,
struct regional regional,
struct ub_packed_rrset_key ns_rrset,
uint8_t  lame 
)

Add NS rrset; calls add_ns repeatedly.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
ns_rrsetNS rrset.
lamerrset is lame, disprefer it.
Returns
0 on alloc error.

References delegpt::bogus, packed_rrset_data::count, lruhash_entry::data, dname_valid(), delegpt::dp_type_mlc, ub_packed_rrset_key::entry, log_assert, packed_rrset_data::rr_data, packed_rrset_data::rr_len, sec_status_bogus, and packed_rrset_data::security.

Referenced by delegpt_add_rrset(), delegpt_from_message(), dns_cache_find_delegation(), and iter_lookup_parent_NS_from_cache().

◆ delegpt_add_rrset_A()

int delegpt_add_rrset_A ( struct delegpt dp,
struct regional regional,
struct ub_packed_rrset_key rrset,
uint8_t  lame,
int *  additions 
)

Add A RRset to delegpt.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
rrsetRRset A to add.
lamerrset is lame, disprefer it.
additionswill be set to 1 if a new address is added
Returns
0 on alloc error.

References packed_rrset_data::count, lruhash_entry::data, delegpt_add_target(), packed_rrset_key::dname, packed_rrset_key::dname_len, delegpt::dp_type_mlc, ub_packed_rrset_key::entry, INET_SIZE, log_assert, ub_packed_rrset_key::rk, packed_rrset_data::rr_data, packed_rrset_data::rr_len, sec_status_bogus, and packed_rrset_data::security.

Referenced by delegpt_add_rrset(), delegpt_from_message(), and find_add_addrs().

◆ delegpt_add_rrset_AAAA()

int delegpt_add_rrset_AAAA ( struct delegpt dp,
struct regional regional,
struct ub_packed_rrset_key rrset,
uint8_t  lame,
int *  additions 
)

Add AAAA RRset to delegpt.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
rrsetRRset AAAA to add.
lamerrset is lame, disprefer it.
additionswill be set to 1 if a new address is added
Returns
0 on alloc error.

References packed_rrset_data::count, lruhash_entry::data, delegpt_add_target(), packed_rrset_key::dname, packed_rrset_key::dname_len, delegpt::dp_type_mlc, ub_packed_rrset_key::entry, INET6_SIZE, log_assert, ub_packed_rrset_key::rk, packed_rrset_data::rr_data, packed_rrset_data::rr_len, sec_status_bogus, and packed_rrset_data::security.

Referenced by delegpt_add_rrset(), delegpt_from_message(), and find_add_addrs().

◆ delegpt_add_rrset()

int delegpt_add_rrset ( struct delegpt dp,
struct regional regional,
struct ub_packed_rrset_key rrset,
uint8_t  lame,
int *  additions 
)

Add any RRset to delegpt.

Does not check for duplicates added.

Parameters
dpdelegation point.
regionalwhere to allocate the info.
rrsetRRset to add, NS, A, AAAA.
lamerrset is lame, disprefer it.
additionswill be set to 1 if a new address is added
Returns
0 on alloc error.

References delegpt_add_rrset_A(), delegpt_add_rrset_AAAA(), delegpt_rrset_add_ns(), LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, LDNS_RR_TYPE_NS, log_warn(), ub_packed_rrset_key::rk, and packed_rrset_key::type.

◆ delegpt_mark_neg()

void delegpt_mark_neg ( struct delegpt_ns ns,
uint16_t  qtype 
)

Mark negative return in delegation point for specific nameserver.

sets the got4 or got6 to negative, updates the ns->resolved.

Parameters
nsthe nameserver in the delegpt.
qtypeA or AAAA (host order).

References delegpt_ns::got4, delegpt_ns::got6, LDNS_RR_TYPE_A, LDNS_RR_TYPE_AAAA, and delegpt_ns::resolved.

Referenced by delegpt_add_neg_msg(), and error_supers().

◆ delegpt_add_neg_msg()

void delegpt_add_neg_msg ( struct delegpt dp,
struct msgreply_entry msg 
)

Add negative message to delegation point.

Parameters
dpdelegation point.
msgthe message added, marks off A or AAAA from an NS entry.

References reply_info::an_numrrsets, lruhash_entry::data, delegpt_find_ns(), delegpt_mark_neg(), msgreply_entry::entry, reply_info::flags, FLAGS_GET_RCODE, msgreply_entry::key, query_info::qname, query_info::qname_len, and query_info::qtype.

Referenced by find_add_addrs().

◆ delegpt_no_ipv6()

void delegpt_no_ipv6 ( struct delegpt dp)

Register the fact that there is no ipv6 and thus AAAAs are not going to be queried for or be useful.

Parameters
dpthe delegation point. Updated to reflect no ipv6.

References delegpt_ns::got4, delegpt_ns::next, delegpt::nslist, and delegpt_ns::resolved.

◆ delegpt_no_ipv4()

void delegpt_no_ipv4 ( struct delegpt dp)

Register the fact that there is no ipv4 and thus As are not going to be queried for or be useful.

Parameters
dpthe delegation point. Updated to reflect no ipv4.

References delegpt_ns::got6, delegpt_ns::next, delegpt::nslist, and delegpt_ns::resolved.

◆ delegpt_create_mlc()

struct delegpt* delegpt_create_mlc ( uint8_t *  name)

create malloced delegation point, with the given name

Parameters
nameuncompressed wireformat of delegpt name.
Returns
NULL on alloc failure

References dname_count_size_labels(), delegpt::dp_type_mlc, memdup(), delegpt::name, delegpt::namelabs, and delegpt::namelen.

Referenced by compile_time_root_prime(), parse_delegpt(), read_fwds_name(), read_root_hints(), and read_stubs_name().

◆ delegpt_free_mlc()

void delegpt_free_mlc ( struct delegpt dp)

◆ delegpt_set_name_mlc()

int delegpt_set_name_mlc ( struct delegpt dp,
uint8_t *  name 
)

Set name of delegation point.

Parameters
dpdelegation point. malloced.
namename to use.
Returns
false on error.

References dname_count_size_labels(), delegpt::dp_type_mlc, log_assert, memdup(), delegpt::name, delegpt::namelabs, and delegpt::namelen.

◆ delegpt_add_ns_mlc()

int delegpt_add_ns_mlc ( struct delegpt dp,
uint8_t *  name,
uint8_t  lame,
char *  tls_auth_name,
int  port 
)

add a name to malloced delegation point.

Parameters
dpmust have been created with delegpt_create_mlc.
namethe name to add.
lamethe name is lame, disprefer.
tls_auth_nameTLS authentication name (or NULL).
portport to use for resolved addresses.
Returns
false on error.

References delegpt_ns::cache_lookup_count, delegpt_find_ns(), dname_count_size_labels(), delegpt_ns::done_pside4, delegpt_ns::done_pside6, delegpt::dp_type_mlc, delegpt_ns::got4, delegpt_ns::got6, delegpt_ns::lame, log_assert, memdup(), delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::next, delegpt::nslist, delegpt_ns::port, delegpt_ns::resolved, and delegpt_ns::tls_auth_name.

Referenced by ah(), parse_delegpt(), read_fwds_host(), and read_stubs_host().

◆ delegpt_add_addr_mlc()

int delegpt_add_addr_mlc ( struct delegpt dp,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t  bogus,
uint8_t  lame,
char *  tls_auth_name,
int  port 
)

add an address to a malloced delegation point.

Parameters
dpmust have been created with delegpt_create_mlc.
addrthe address.
addrlenthe length of addr.
bogusif address is bogus.
lameif address is lame.
tls_auth_nameTLS authentication name (or NULL).
portthe port to use; if -1 the port is taken from addr.
Returns
false on error.

References delegpt_addr::addr, delegpt_addr::addrlen, delegpt_addr::attempts, delegpt_addr::bogus, delegpt_find_addr(), delegpt_addr::dnsseclame, delegpt::dp_type_mlc, delegpt_addr::lame, log_assert, delegpt_addr::next_result, delegpt_addr::next_target, delegpt_addr::next_usable, sockaddr_store_port(), delegpt::target_list, delegpt_addr::tls_auth_name, and delegpt::usable_list.

Referenced by delegpt_add_target_mlc(), parse_delegpt(), read_fwds_addr(), and read_stubs_addr().

◆ delegpt_add_target_mlc()

int delegpt_add_target_mlc ( struct delegpt dp,
uint8_t *  name,
size_t  namelen,
struct sockaddr_storage *  addr,
socklen_t  addrlen,
uint8_t  bogus,
uint8_t  lame 
)

Add target address to the delegation point.

Parameters
dpmust have been created with delegpt_create_mlc.
namename for which target was found (must be in nslist). This name is marked resolved.
namelenlength of name.
addrthe address.
addrlenthe length of addr.
bogussecurity status for the address, pass true if bogus.
lameaddress is lame.
Returns
false on error.

References addr_is_ip6(), delegpt_add_addr_mlc(), delegpt_find_ns(), delegpt_ns::done_pside4, delegpt_ns::done_pside6, delegpt::dp_type_mlc, delegpt_ns::got4, delegpt_ns::got6, delegpt_ns::lame, log_assert, delegpt_ns::name, delegpt_ns::namelen, delegpt_ns::port, delegpt_ns::resolved, and delegpt_ns::tls_auth_name.

Referenced by ah().