diff options
author | Stuart Henderson <sthen@cvs.openbsd.org> | 2012-03-26 18:05:44 +0000 |
---|---|---|
committer | Stuart Henderson <sthen@cvs.openbsd.org> | 2012-03-26 18:05:44 +0000 |
commit | 6574014ff51101a11a35aa6da0384c24b4768145 (patch) | |
tree | 4b46f7ef2d91f57772852967e69183e75d2540e4 /usr.sbin/unbound | |
parent | fa1fdfd8c5c44f7c021da1b5fceb5dcbf4e26ea5 (diff) |
Import Unbound 1.4.16 to work on in-tree (not yet linked to the build).
These are the direct sources from NLnet Labs upstream, minus these:
compat contrib libunbound/python pythonmod testcode testdata winrc
ok deraadt@ jakob@
Diffstat (limited to 'usr.sbin/unbound')
-rw-r--r-- | usr.sbin/unbound/iterator/iter_hints.c | 201 |
1 files changed, 75 insertions, 126 deletions
diff --git a/usr.sbin/unbound/iterator/iter_hints.c b/usr.sbin/unbound/iterator/iter_hints.c index 09e4731135d..01c50b962dd 100644 --- a/usr.sbin/unbound/iterator/iter_hints.c +++ b/usr.sbin/unbound/iterator/iter_hints.c @@ -44,6 +44,7 @@ #include <ldns/rr.h> #include "iterator/iter_hints.h" #include "iterator/iter_delegpt.h" +#include "util/regional.h" #include "util/log.h" #include "util/config_file.h" #include "util/net_help.h" @@ -56,39 +57,26 @@ hints_create(void) sizeof(struct iter_hints)); if(!hints) return NULL; + hints->region = regional_create(); + if(!hints->region) { + hints_delete(hints); + return NULL; + } return hints; } -static void hints_stub_free(struct iter_hints_stub* s) -{ - if(!s) return; - delegpt_free_mlc(s->dp); - free(s); -} - -static void delhintnode(rbnode_t* n, void* ATTR_UNUSED(arg)) -{ - struct iter_hints_stub* node = (struct iter_hints_stub*)n; - hints_stub_free(node); -} - -static void hints_del_tree(struct iter_hints* hints) -{ - traverse_postorder(&hints->tree, &delhintnode, NULL); -} - void hints_delete(struct iter_hints* hints) { if(!hints) return; - hints_del_tree(hints); + regional_destroy(hints->region); free(hints); } /** add hint to delegation hints */ static int -ah(struct delegpt* dp, const char* sv, const char* ip) +ah(struct delegpt* dp, struct regional* r, const char* sv, const char* ip) { struct sockaddr_storage addr; socklen_t addrlen; @@ -97,9 +85,9 @@ ah(struct delegpt* dp, const char* sv, const char* ip) log_err("could not parse %s", sv); return 0; } - if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0) || + if(!delegpt_add_ns(dp, r, ldns_rdf_data(rdf), 0) || !extstrtoaddr(ip, &addr, &addrlen) || - !delegpt_add_target_mlc(dp, ldns_rdf_data(rdf), ldns_rdf_size(rdf), + !delegpt_add_target(dp, r, ldns_rdf_data(rdf), ldns_rdf_size(rdf), &addr, addrlen, 0, 0)) { ldns_rdf_deep_free(rdf); return 0; @@ -110,7 +98,7 @@ ah(struct delegpt* dp, const char* sv, const char* ip) /** obtain compiletime provided root hints */ static struct delegpt* -compile_time_root_prime(int do_ip4, int do_ip6) +compile_time_root_prime(struct regional* r, int do_ip4, int do_ip6) { /* from: ; This file is made available by InterNIC @@ -121,40 +109,39 @@ compile_time_root_prime(int do_ip4, int do_ip6) ; ; related version of root zone: 2010061700 */ - struct delegpt* dp = delegpt_create_mlc((uint8_t*)"\000"); + struct delegpt* dp = delegpt_create(r); if(!dp) return NULL; dp->has_parent_side_NS = 1; + if(!delegpt_set_name(dp, r, (uint8_t*)"\000")) + return NULL; if(do_ip4) { - if(!ah(dp, "A.ROOT-SERVERS.NET.", "198.41.0.4")) goto failed; - if(!ah(dp, "B.ROOT-SERVERS.NET.", "192.228.79.201")) goto failed; - if(!ah(dp, "C.ROOT-SERVERS.NET.", "192.33.4.12")) goto failed; - if(!ah(dp, "D.ROOT-SERVERS.NET.", "128.8.10.90")) goto failed; - if(!ah(dp, "E.ROOT-SERVERS.NET.", "192.203.230.10")) goto failed; - if(!ah(dp, "F.ROOT-SERVERS.NET.", "192.5.5.241")) goto failed; - if(!ah(dp, "G.ROOT-SERVERS.NET.", "192.112.36.4")) goto failed; - if(!ah(dp, "H.ROOT-SERVERS.NET.", "128.63.2.53")) goto failed; - if(!ah(dp, "I.ROOT-SERVERS.NET.", "192.36.148.17")) goto failed; - if(!ah(dp, "J.ROOT-SERVERS.NET.", "192.58.128.30")) goto failed; - if(!ah(dp, "K.ROOT-SERVERS.NET.", "193.0.14.129")) goto failed; - if(!ah(dp, "L.ROOT-SERVERS.NET.", "199.7.83.42")) goto failed; - if(!ah(dp, "M.ROOT-SERVERS.NET.", "202.12.27.33")) goto failed; + if(!ah(dp, r, "A.ROOT-SERVERS.NET.", "198.41.0.4")) return 0; + if(!ah(dp, r, "B.ROOT-SERVERS.NET.", "192.228.79.201")) return 0; + if(!ah(dp, r, "C.ROOT-SERVERS.NET.", "192.33.4.12")) return 0; + if(!ah(dp, r, "D.ROOT-SERVERS.NET.", "128.8.10.90")) return 0; + if(!ah(dp, r, "E.ROOT-SERVERS.NET.", "192.203.230.10")) return 0; + if(!ah(dp, r, "F.ROOT-SERVERS.NET.", "192.5.5.241")) return 0; + if(!ah(dp, r, "G.ROOT-SERVERS.NET.", "192.112.36.4")) return 0; + if(!ah(dp, r, "H.ROOT-SERVERS.NET.", "128.63.2.53")) return 0; + if(!ah(dp, r, "I.ROOT-SERVERS.NET.", "192.36.148.17")) return 0; + if(!ah(dp, r, "J.ROOT-SERVERS.NET.", "192.58.128.30")) return 0; + if(!ah(dp, r, "K.ROOT-SERVERS.NET.", "193.0.14.129")) return 0; + if(!ah(dp, r, "L.ROOT-SERVERS.NET.", "199.7.83.42")) return 0; + if(!ah(dp, r, "M.ROOT-SERVERS.NET.", "202.12.27.33")) return 0; } if(do_ip6) { - if(!ah(dp, "A.ROOT-SERVERS.NET.", "2001:503:ba3e::2:30")) goto failed; - if(!ah(dp, "D.ROOT-SERVERS.NET.", "2001:500:2d::d")) goto failed; - if(!ah(dp, "F.ROOT-SERVERS.NET.", "2001:500:2f::f")) goto failed; - if(!ah(dp, "H.ROOT-SERVERS.NET.", "2001:500:1::803f:235")) goto failed; - if(!ah(dp, "I.ROOT-SERVERS.NET.", "2001:7fe::53")) goto failed; - if(!ah(dp, "J.ROOT-SERVERS.NET.", "2001:503:c27::2:30")) goto failed; - if(!ah(dp, "K.ROOT-SERVERS.NET.", "2001:7fd::1")) goto failed; - if(!ah(dp, "L.ROOT-SERVERS.NET.", "2001:500:3::42")) goto failed; - if(!ah(dp, "M.ROOT-SERVERS.NET.", "2001:dc3::35")) goto failed; + if(!ah(dp, r, "A.ROOT-SERVERS.NET.", "2001:503:ba3e::2:30")) return 0; + if(!ah(dp, r, "D.ROOT-SERVERS.NET.", "2001:500:2d::d")) return 0; + if(!ah(dp, r, "F.ROOT-SERVERS.NET.", "2001:500:2f::f")) return 0; + if(!ah(dp, r, "H.ROOT-SERVERS.NET.", "2001:500:1::803f:235")) return 0; + if(!ah(dp, r, "I.ROOT-SERVERS.NET.", "2001:7fe::53")) return 0; + if(!ah(dp, r, "J.ROOT-SERVERS.NET.", "2001:503:c27::2:30")) return 0; + if(!ah(dp, r, "K.ROOT-SERVERS.NET.", "2001:7fd::1")) return 0; + if(!ah(dp, r, "L.ROOT-SERVERS.NET.", "2001:500:3::42")) return 0; + if(!ah(dp, r, "M.ROOT-SERVERS.NET.", "2001:dc3::35")) return 0; } return dp; -failed: - delegpt_free_mlc(dp); - return 0; } /** insert new hint info into hint structure */ @@ -162,50 +149,51 @@ static int hints_insert(struct iter_hints* hints, uint16_t c, struct delegpt* dp, int noprime) { - struct iter_hints_stub* node = (struct iter_hints_stub*)malloc( + struct iter_hints_stub* node = regional_alloc(hints->region, sizeof(struct iter_hints_stub)); - if(!node) { - delegpt_free_mlc(dp); + uint8_t* nm; + if(!node) + return 0; + nm = regional_alloc_init(hints->region, dp->name, dp->namelen); + if(!nm) return 0; - } node->dp = dp; node->noprime = (uint8_t)noprime; - if(!name_tree_insert(&hints->tree, &node->node, dp->name, dp->namelen, + if(!name_tree_insert(&hints->tree, &node->node, nm, dp->namelen, dp->namelabs, c)) { log_err("second hints ignored."); - delegpt_free_mlc(dp); - free(node); } return 1; } /** set stub name */ -static struct delegpt* -read_stubs_name(struct config_stub* s) +static int +read_stubs_name(struct iter_hints* hints, struct config_stub* s, + struct delegpt* dp) { - struct delegpt* dp; ldns_rdf* rdf; if(!s->name) { log_err("stub zone without a name"); - return NULL; + return 0; } rdf = ldns_dname_new_frm_str(s->name); if(!rdf) { log_err("cannot parse stub zone name %s", s->name); - return NULL; + return 0; } - if(!(dp=delegpt_create_mlc(ldns_rdf_data(rdf)))) { + if(!delegpt_set_name(dp, hints->region, ldns_rdf_data(rdf))) { ldns_rdf_deep_free(rdf); log_err("out of memory"); - return NULL; + return 0; } ldns_rdf_deep_free(rdf); - return dp; + return 1; } /** set stub host names */ static int -read_stubs_host(struct config_stub* s, struct delegpt* dp) +read_stubs_host(struct iter_hints* hints, struct config_stub* s, + struct delegpt* dp) { struct config_strlist* p; ldns_rdf* rdf; @@ -217,7 +205,7 @@ read_stubs_host(struct config_stub* s, struct delegpt* dp) s->name, p->str); return 0; } - if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0)) { + if(!delegpt_add_ns(dp, hints->region, ldns_rdf_data(rdf), 0)) { ldns_rdf_deep_free(rdf); log_err("out of memory"); return 0; @@ -229,7 +217,8 @@ read_stubs_host(struct config_stub* s, struct delegpt* dp) /** set stub server addresses */ static int -read_stubs_addr(struct config_stub* s, struct delegpt* dp) +read_stubs_addr(struct iter_hints* hints, struct config_stub* s, + struct delegpt* dp) { struct config_strlist* p; struct sockaddr_storage addr; @@ -241,7 +230,7 @@ read_stubs_addr(struct config_stub* s, struct delegpt* dp) s->name, p->str); return 0; } - if(!delegpt_add_addr_mlc(dp, &addr, addrlen, 0, 0)) { + if(!delegpt_add_addr(dp, hints->region, &addr, addrlen, 0, 0)) { log_err("out of memory"); return 0; } @@ -254,21 +243,20 @@ static int read_stubs(struct iter_hints* hints, struct config_file* cfg) { struct config_stub* s; - struct delegpt* dp; for(s = cfg->stubs; s; s = s->next) { - if(!(dp=read_stubs_name(s))) - return 0; - if(!read_stubs_host(s, dp) || !read_stubs_addr(s, dp)) { - delegpt_free_mlc(dp); + struct delegpt* dp = delegpt_create(hints->region); + if(!dp) { + log_err("out of memory"); return 0; } - /* the flag is turned off for 'stub-first' so that the - * last resort will ask for parent-side NS record and thus - * fallback to the internet name servers on a failure */ - dp->has_parent_side_NS = (uint8_t)!s->isfirst; - delegpt_log(VERB_QUERY, dp); + dp->has_parent_side_NS = 1; + if(!read_stubs_name(hints, s, dp) || + !read_stubs_host(hints, s, dp) || + !read_stubs_addr(hints, s, dp)) + return 0; if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp, !s->isprime)) return 0; + delegpt_log(VERB_QUERY, dp); } return 1; } @@ -291,7 +279,7 @@ read_root_hints(struct iter_hints* hints, char* fname) fname, strerror(errno)); return 0; } - dp = delegpt_create_mlc(NULL); + dp = delegpt_create(hints->region); if(!dp) { log_err("out of memory reading root hints"); fclose(f); @@ -312,14 +300,14 @@ read_root_hints(struct iter_hints* hints, char* fname) goto stop_read; } if(ldns_rr_get_type(rr) == LDNS_RR_TYPE_NS) { - if(!delegpt_add_ns_mlc(dp, + if(!delegpt_add_ns(dp, hints->region, ldns_rdf_data(ldns_rr_rdf(rr, 0)), 0)) { log_err("out of memory reading root hints"); goto stop_read; } c = ldns_rr_get_class(rr); if(!dp->name) { - if(!delegpt_set_name_mlc(dp, + if(!delegpt_set_name(dp, hints->region, ldns_rdf_data(ldns_rr_owner(rr)))){ log_err("out of memory."); goto stop_read; @@ -333,7 +321,7 @@ read_root_hints(struct iter_hints* hints, char* fname) sa.sin_port = (in_port_t)htons(UNBOUND_DNS_PORT); memmove(&sa.sin_addr, ldns_rdf_data(ldns_rr_rdf(rr, 0)), INET_SIZE); - if(!delegpt_add_target_mlc(dp, + if(!delegpt_add_target(dp, hints->region, ldns_rdf_data(ldns_rr_owner(rr)), ldns_rdf_size(ldns_rr_owner(rr)), (struct sockaddr_storage*)&sa, len, @@ -349,7 +337,7 @@ read_root_hints(struct iter_hints* hints, char* fname) sa.sin6_port = (in_port_t)htons(UNBOUND_DNS_PORT); memmove(&sa.sin6_addr, ldns_rdf_data(ldns_rr_rdf(rr, 0)), INET6_SIZE); - if(!delegpt_add_target_mlc(dp, + if(!delegpt_add_target(dp, hints->region, ldns_rdf_data(ldns_rr_owner(rr)), ldns_rdf_size(ldns_rr_owner(rr)), (struct sockaddr_storage*)&sa, len, @@ -372,7 +360,6 @@ read_root_hints(struct iter_hints* hints, char* fname) fclose(f); if(!dp->name) { log_warn("root hints %s: no NS content", fname); - delegpt_free_mlc(dp); return 1; } if(!hints_insert(hints, c, dp, 0)) { @@ -386,7 +373,6 @@ stop_read: ldns_rdf_deep_free(origin); if (prev_rr) ldns_rdf_deep_free(prev_rr); - delegpt_free_mlc(dp); fclose(f); return 0; } @@ -414,7 +400,7 @@ read_root_hints_list(struct iter_hints* hints, struct config_file* cfg) int hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg) { - hints_del_tree(hints); + regional_free_all(hints->region); name_tree_init(&hints->tree); /* read root hints */ @@ -427,8 +413,8 @@ hints_apply_cfg(struct iter_hints* hints, struct config_file* cfg) /* use fallback compiletime root hints */ if(!hints_lookup_root(hints, LDNS_RR_CLASS_IN)) { - struct delegpt* dp = compile_time_root_prime(cfg->do_ip4, - cfg->do_ip6); + struct delegpt* dp = compile_time_root_prime(hints->region, + cfg->do_ip4, cfg->do_ip6); verbose(VERB_ALGO, "no config, using builtin root hints."); if(!dp) return 0; @@ -497,43 +483,6 @@ int hints_next_root(struct iter_hints* hints, uint16_t* qclass) size_t hints_get_mem(struct iter_hints* hints) { - size_t s; - struct iter_hints_stub* p; if(!hints) return 0; - s = sizeof(*hints); - RBTREE_FOR(p, struct iter_hints_stub*, &hints->tree) { - s += sizeof(*p) + delegpt_get_mem(p->dp); - } - return s; -} - -int -hints_add_stub(struct iter_hints* hints, uint16_t c, struct delegpt* dp, - int noprime) -{ - struct iter_hints_stub *z; - if((z=(struct iter_hints_stub*)name_tree_find(&hints->tree, - dp->name, dp->namelen, dp->namelabs, c)) != NULL) { - (void)rbtree_delete(&hints->tree, &z->node); - hints_stub_free(z); - } - if(!hints_insert(hints, c, dp, noprime)) - return 0; - name_tree_init_parents(&hints->tree); - return 1; -} - -void -hints_delete_stub(struct iter_hints* hints, uint16_t c, uint8_t* nm) -{ - struct iter_hints_stub *z; - size_t len; - int labs = dname_count_size_labels(nm, &len); - if(!(z=(struct iter_hints_stub*)name_tree_find(&hints->tree, - nm, len, labs, c))) - return; /* nothing to do */ - (void)rbtree_delete(&hints->tree, &z->node); - hints_stub_free(z); - name_tree_init_parents(&hints->tree); + return sizeof(*hints) + regional_get_mem(hints->region); } - |