diff options
author | Jakob Schlyter <jakob@cvs.openbsd.org> | 2013-01-08 07:20:05 +0000 |
---|---|---|
committer | Jakob Schlyter <jakob@cvs.openbsd.org> | 2013-01-08 07:20:05 +0000 |
commit | a728bb752630ed8941fd43b93eb875a2527c2ba8 (patch) | |
tree | 8590b0c0306b96e382743e093cba73b1e612aa5c | |
parent | e6390beea1017adea3a0c21ef6110678e50fa7de (diff) |
new IPv4 address for D.ROOT-SERVERS.NET
-rw-r--r-- | usr.sbin/unbound/iterator/iter_hints.c | 201 | ||||
-rw-r--r-- | usr.sbin/unbound/ldns/drill/root.c | 2 |
2 files changed, 127 insertions, 76 deletions
diff --git a/usr.sbin/unbound/iterator/iter_hints.c b/usr.sbin/unbound/iterator/iter_hints.c index 01c50b962dd..db7ac5233e3 100644 --- a/usr.sbin/unbound/iterator/iter_hints.c +++ b/usr.sbin/unbound/iterator/iter_hints.c @@ -44,7 +44,6 @@ #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" @@ -57,26 +56,39 @@ 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; - regional_destroy(hints->region); + hints_del_tree(hints); free(hints); } /** add hint to delegation hints */ static int -ah(struct delegpt* dp, struct regional* r, const char* sv, const char* ip) +ah(struct delegpt* dp, const char* sv, const char* ip) { struct sockaddr_storage addr; socklen_t addrlen; @@ -85,9 +97,9 @@ ah(struct delegpt* dp, struct regional* r, const char* sv, const char* ip) log_err("could not parse %s", sv); return 0; } - if(!delegpt_add_ns(dp, r, ldns_rdf_data(rdf), 0) || + if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0) || !extstrtoaddr(ip, &addr, &addrlen) || - !delegpt_add_target(dp, r, ldns_rdf_data(rdf), ldns_rdf_size(rdf), + !delegpt_add_target_mlc(dp, ldns_rdf_data(rdf), ldns_rdf_size(rdf), &addr, addrlen, 0, 0)) { ldns_rdf_deep_free(rdf); return 0; @@ -98,7 +110,7 @@ ah(struct delegpt* dp, struct regional* r, const char* sv, const char* ip) /** obtain compiletime provided root hints */ static struct delegpt* -compile_time_root_prime(struct regional* r, int do_ip4, int do_ip6) +compile_time_root_prime(int do_ip4, int do_ip6) { /* from: ; This file is made available by InterNIC @@ -109,39 +121,40 @@ compile_time_root_prime(struct regional* r, int do_ip4, int do_ip6) ; ; related version of root zone: 2010061700 */ - struct delegpt* dp = delegpt_create(r); + struct delegpt* dp = delegpt_create_mlc((uint8_t*)"\000"); 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, 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(!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.", "199.7.91.13")) 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(do_ip6) { - 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; + 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; } return dp; +failed: + delegpt_free_mlc(dp); + return 0; } /** insert new hint info into hint structure */ @@ -149,51 +162,50 @@ static int hints_insert(struct iter_hints* hints, uint16_t c, struct delegpt* dp, int noprime) { - struct iter_hints_stub* node = regional_alloc(hints->region, + struct iter_hints_stub* node = (struct iter_hints_stub*)malloc( sizeof(struct iter_hints_stub)); - uint8_t* nm; - if(!node) - return 0; - nm = regional_alloc_init(hints->region, dp->name, dp->namelen); - if(!nm) + if(!node) { + delegpt_free_mlc(dp); return 0; + } node->dp = dp; node->noprime = (uint8_t)noprime; - if(!name_tree_insert(&hints->tree, &node->node, nm, dp->namelen, + if(!name_tree_insert(&hints->tree, &node->node, dp->name, dp->namelen, dp->namelabs, c)) { log_err("second hints ignored."); + delegpt_free_mlc(dp); + free(node); } return 1; } /** set stub name */ -static int -read_stubs_name(struct iter_hints* hints, struct config_stub* s, - struct delegpt* dp) +static struct delegpt* +read_stubs_name(struct config_stub* s) { + struct delegpt* dp; ldns_rdf* rdf; if(!s->name) { log_err("stub zone without a name"); - return 0; + return NULL; } rdf = ldns_dname_new_frm_str(s->name); if(!rdf) { log_err("cannot parse stub zone name %s", s->name); - return 0; + return NULL; } - if(!delegpt_set_name(dp, hints->region, ldns_rdf_data(rdf))) { + if(!(dp=delegpt_create_mlc(ldns_rdf_data(rdf)))) { ldns_rdf_deep_free(rdf); log_err("out of memory"); - return 0; + return NULL; } ldns_rdf_deep_free(rdf); - return 1; + return dp; } /** set stub host names */ static int -read_stubs_host(struct iter_hints* hints, struct config_stub* s, - struct delegpt* dp) +read_stubs_host(struct config_stub* s, struct delegpt* dp) { struct config_strlist* p; ldns_rdf* rdf; @@ -205,7 +217,7 @@ read_stubs_host(struct iter_hints* hints, struct config_stub* s, s->name, p->str); return 0; } - if(!delegpt_add_ns(dp, hints->region, ldns_rdf_data(rdf), 0)) { + if(!delegpt_add_ns_mlc(dp, ldns_rdf_data(rdf), 0)) { ldns_rdf_deep_free(rdf); log_err("out of memory"); return 0; @@ -217,8 +229,7 @@ read_stubs_host(struct iter_hints* hints, struct config_stub* s, /** set stub server addresses */ static int -read_stubs_addr(struct iter_hints* hints, struct config_stub* s, - struct delegpt* dp) +read_stubs_addr(struct config_stub* s, struct delegpt* dp) { struct config_strlist* p; struct sockaddr_storage addr; @@ -230,7 +241,7 @@ read_stubs_addr(struct iter_hints* hints, struct config_stub* s, s->name, p->str); return 0; } - if(!delegpt_add_addr(dp, hints->region, &addr, addrlen, 0, 0)) { + if(!delegpt_add_addr_mlc(dp, &addr, addrlen, 0, 0)) { log_err("out of memory"); return 0; } @@ -243,20 +254,21 @@ 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) { - struct delegpt* dp = delegpt_create(hints->region); - if(!dp) { - log_err("out of memory"); + if(!(dp=read_stubs_name(s))) return 0; - } - 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)) + if(!read_stubs_host(s, dp) || !read_stubs_addr(s, dp)) { + delegpt_free_mlc(dp); 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); if(!hints_insert(hints, LDNS_RR_CLASS_IN, dp, !s->isprime)) return 0; - delegpt_log(VERB_QUERY, dp); } return 1; } @@ -279,7 +291,7 @@ read_root_hints(struct iter_hints* hints, char* fname) fname, strerror(errno)); return 0; } - dp = delegpt_create(hints->region); + dp = delegpt_create_mlc(NULL); if(!dp) { log_err("out of memory reading root hints"); fclose(f); @@ -300,14 +312,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(dp, hints->region, + if(!delegpt_add_ns_mlc(dp, 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(dp, hints->region, + if(!delegpt_set_name_mlc(dp, ldns_rdf_data(ldns_rr_owner(rr)))){ log_err("out of memory."); goto stop_read; @@ -321,7 +333,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(dp, hints->region, + if(!delegpt_add_target_mlc(dp, ldns_rdf_data(ldns_rr_owner(rr)), ldns_rdf_size(ldns_rr_owner(rr)), (struct sockaddr_storage*)&sa, len, @@ -337,7 +349,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(dp, hints->region, + if(!delegpt_add_target_mlc(dp, ldns_rdf_data(ldns_rr_owner(rr)), ldns_rdf_size(ldns_rr_owner(rr)), (struct sockaddr_storage*)&sa, len, @@ -360,6 +372,7 @@ 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)) { @@ -373,6 +386,7 @@ stop_read: ldns_rdf_deep_free(origin); if (prev_rr) ldns_rdf_deep_free(prev_rr); + delegpt_free_mlc(dp); fclose(f); return 0; } @@ -400,7 +414,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) { - regional_free_all(hints->region); + hints_del_tree(hints); name_tree_init(&hints->tree); /* read root hints */ @@ -413,8 +427,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(hints->region, - cfg->do_ip4, cfg->do_ip6); + struct delegpt* dp = compile_time_root_prime(cfg->do_ip4, + cfg->do_ip6); verbose(VERB_ALGO, "no config, using builtin root hints."); if(!dp) return 0; @@ -483,6 +497,43 @@ 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; - return sizeof(*hints) + regional_get_mem(hints->region); + 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); } + diff --git a/usr.sbin/unbound/ldns/drill/root.c b/usr.sbin/unbound/ldns/drill/root.c index a829935cd5a..ccbfe758599 100644 --- a/usr.sbin/unbound/ldns/drill/root.c +++ b/usr.sbin/unbound/ldns/drill/root.c @@ -32,7 +32,7 @@ init_root(void) ldns_rr_list_push_rr(global_dns_root, r); (void)ldns_rr_new_frm_str(&r, "C.ROOT-SERVERS.NET. 3600000 A 192.33.4.12", 0, NULL, NULL); ldns_rr_list_push_rr(global_dns_root, r); - (void)ldns_rr_new_frm_str(&r, "D.ROOT-SERVERS.NET. 3600000 A 128.8.10.90", 0, NULL, NULL); + (void)ldns_rr_new_frm_str(&r, "D.ROOT-SERVERS.NET. 3600000 A 199.7.91.13", 0, NULL, NULL); ldns_rr_list_push_rr(global_dns_root, r); (void)ldns_rr_new_frm_str(&r, "E.ROOT-SERVERS.NET. 3600000 A 192.203.230.10", 0, NULL, NULL); ldns_rr_list_push_rr(global_dns_root, r); |