summaryrefslogtreecommitdiff
path: root/usr.sbin/unbound/services/localzone.c
diff options
context:
space:
mode:
authorStuart Henderson <sthen@cvs.openbsd.org>2017-09-29 16:27:15 +0000
committerStuart Henderson <sthen@cvs.openbsd.org>2017-09-29 16:27:15 +0000
commit05a4d0febb63836d27b0bec2addee46048418657 (patch)
tree33e262239ef0955daf78b180fd95586ed004e901 /usr.sbin/unbound/services/localzone.c
parent7b9e8478f0635b6e05f828b0e268b36ac9eddf21 (diff)
update to unbound-1.6.6, ok florian
Diffstat (limited to 'usr.sbin/unbound/services/localzone.c')
-rw-r--r--usr.sbin/unbound/services/localzone.c111
1 files changed, 75 insertions, 36 deletions
diff --git a/usr.sbin/unbound/services/localzone.c b/usr.sbin/unbound/services/localzone.c
index a19b5252643..6bde432e8d0 100644
--- a/usr.sbin/unbound/services/localzone.c
+++ b/usr.sbin/unbound/services/localzone.c
@@ -260,7 +260,8 @@ rrstr_get_rr_content(const char* str, uint8_t** nm, uint16_t* type,
/** return name and class of rr; parses string */
static int
-get_rr_nameclass(const char* str, uint8_t** nm, uint16_t* dclass)
+get_rr_nameclass(const char* str, uint8_t** nm, uint16_t* dclass,
+ uint16_t* dtype)
{
uint8_t rr[LDNS_RR_BUF_SIZE];
size_t len = sizeof(rr), dname_len = 0;
@@ -274,6 +275,7 @@ get_rr_nameclass(const char* str, uint8_t** nm, uint16_t* dclass)
}
*nm = memdup(rr, dname_len);
*dclass = sldns_wirerr_get_class(rr, len, dname_len);
+ *dtype = sldns_wirerr_get_type(rr, len, dname_len);
if(!*nm) {
log_err("out of memory");
return 0;
@@ -522,18 +524,18 @@ static int
lz_enter_rr_str(struct local_zones* zones, const char* rr)
{
uint8_t* rr_name;
- uint16_t rr_class;
+ uint16_t rr_class, rr_type;
size_t len;
int labs;
struct local_zone* z;
int r;
- if(!get_rr_nameclass(rr, &rr_name, &rr_class)) {
+ if(!get_rr_nameclass(rr, &rr_name, &rr_class, &rr_type)) {
log_err("bad rr %s", rr);
return 0;
}
labs = dname_count_size_labels(rr_name, &len);
lock_rw_rdlock(&zones->lock);
- z = local_zones_lookup(zones, rr_name, len, labs, rr_class);
+ z = local_zones_lookup(zones, rr_name, len, labs, rr_class, rr_type);
if(!z) {
lock_rw_unlock(&zones->lock);
fatal_exit("internal error: no zone for rr %s", rr);
@@ -719,9 +721,9 @@ lz_nodefault(struct config_file* cfg, const char* name)
return 0;
}
-/** enter AS112 default zone */
+/** enter (AS112) empty default zone */
static int
-add_as112_default(struct local_zones* zones, struct config_file* cfg,
+add_empty_default(struct local_zones* zones, struct config_file* cfg,
const char* name)
{
struct local_zone* z;
@@ -762,7 +764,7 @@ int local_zone_enter_defaults(struct local_zones* zones, struct config_file* cfg
/* localhost. zone */
if(!lz_exists(zones, "localhost.") &&
!lz_nodefault(cfg, "localhost.")) {
- if(!(z=lz_enter_zone(zones, "localhost.", "static",
+ if(!(z=lz_enter_zone(zones, "localhost.", "redirect",
LDNS_RR_CLASS_IN)) ||
!lz_enter_rr_into_zone(z,
"localhost. 10800 IN NS localhost.") ||
@@ -816,26 +818,24 @@ int local_zone_enter_defaults(struct local_zones* zones, struct config_file* cfg
lock_rw_unlock(&z->lock);
}
/* onion. zone (RFC 7686) */
- if(!lz_exists(zones, "onion.") &&
- !lz_nodefault(cfg, "onion.")) {
- if(!(z=lz_enter_zone(zones, "onion.", "static",
- LDNS_RR_CLASS_IN)) ||
- !lz_enter_rr_into_zone(z,
- "onion. 10800 IN NS localhost.") ||
- !lz_enter_rr_into_zone(z,
- "onion. 10800 IN SOA localhost. nobody.invalid. "
- "1 3600 1200 604800 10800")) {
- log_err("out of memory adding default zone");
- if(z) { lock_rw_unlock(&z->lock); }
- return 0;
- }
- lock_rw_unlock(&z->lock);
+ if(!add_empty_default(zones, cfg, "onion.")) {
+ log_err("out of memory adding default zone");
+ return 0;
+ }
+ /* test. zone (RFC 7686) */
+ if(!add_empty_default(zones, cfg, "test.")) {
+ log_err("out of memory adding default zone");
+ return 0;
+ }
+ /* invalid. zone (RFC 7686) */
+ if(!add_empty_default(zones, cfg, "invalid.")) {
+ log_err("out of memory adding default zone");
+ return 0;
}
-
/* block AS112 zones, unless asked not to */
if(!cfg->unblock_lan_zones) {
for(zstr = as112_zones; *zstr; zstr++) {
- if(!add_as112_default(zones, cfg, *zstr)) {
+ if(!add_empty_default(zones, cfg, *zstr)) {
log_err("out of memory adding default zone");
return 0;
}
@@ -913,16 +913,17 @@ lz_setup_implicit(struct local_zones* zones, struct config_file* cfg)
init_parents(zones); /* to enable local_zones_lookup() */
for(p = cfg->local_data; p; p = p->next) {
uint8_t* rr_name;
- uint16_t rr_class;
+ uint16_t rr_class, rr_type;
size_t len;
int labs;
- if(!get_rr_nameclass(p->str, &rr_name, &rr_class)) {
+ if(!get_rr_nameclass(p->str, &rr_name, &rr_class, &rr_type)) {
log_err("Bad local-data RR %s", p->str);
return 0;
}
labs = dname_count_size_labels(rr_name, &len);
lock_rw_rdlock(&zones->lock);
- if(!local_zones_lookup(zones, rr_name, len, labs, rr_class)) {
+ if(!local_zones_lookup(zones, rr_name, len, labs, rr_class,
+ rr_type)) {
if(!have_name) {
dclass = rr_class;
nm = rr_name;
@@ -1053,21 +1054,26 @@ local_zones_apply_cfg(struct local_zones* zones, struct config_file* cfg)
struct local_zone*
local_zones_lookup(struct local_zones* zones,
- uint8_t* name, size_t len, int labs, uint16_t dclass)
+ uint8_t* name, size_t len, int labs, uint16_t dclass, uint16_t dtype)
{
return local_zones_tags_lookup(zones, name, len, labs,
- dclass, NULL, 0, 1);
+ dclass, dtype, NULL, 0, 1);
}
struct local_zone*
local_zones_tags_lookup(struct local_zones* zones,
- uint8_t* name, size_t len, int labs, uint16_t dclass,
+ uint8_t* name, size_t len, int labs, uint16_t dclass, uint16_t dtype,
uint8_t* taglist, size_t taglen, int ignoretags)
{
rbnode_type* res = NULL;
struct local_zone *result;
struct local_zone key;
int m;
+ /* for type DS use a zone higher when on a zonecut */
+ if(dtype == LDNS_RR_TYPE_DS && !dname_is_root(name)) {
+ dname_remove_label(&name, &len);
+ labs--;
+ }
key.node.key = &key;
key.dclass = dclass;
key.name = name;
@@ -1583,7 +1589,7 @@ local_zones_answer(struct local_zones* zones, struct module_env* env,
if(view->local_zones &&
(z = local_zones_lookup(view->local_zones,
qinfo->qname, qinfo->qname_len, labs,
- qinfo->qclass))) {
+ qinfo->qclass, qinfo->qtype))) {
verbose(VERB_ALGO,
"using localzone from view: %s",
view->name);
@@ -1600,8 +1606,8 @@ local_zones_answer(struct local_zones* zones, struct module_env* env,
/* try global local_zones tree */
lock_rw_rdlock(&zones->lock);
if(!(z = local_zones_tags_lookup(zones, qinfo->qname,
- qinfo->qname_len, labs, qinfo->qclass, taglist,
- taglen, 0))) {
+ qinfo->qname_len, labs, qinfo->qclass, qinfo->qtype,
+ taglist, taglen, 0))) {
lock_rw_unlock(&zones->lock);
return 0;
}
@@ -1756,19 +1762,19 @@ int
local_zones_add_RR(struct local_zones* zones, const char* rr)
{
uint8_t* rr_name;
- uint16_t rr_class;
+ uint16_t rr_class, rr_type;
size_t len;
int labs;
struct local_zone* z;
int r;
- if(!get_rr_nameclass(rr, &rr_name, &rr_class)) {
+ if(!get_rr_nameclass(rr, &rr_name, &rr_class, &rr_type)) {
return 0;
}
labs = dname_count_size_labels(rr_name, &len);
/* could first try readlock then get writelock if zone does not exist,
* but we do not add enough RRs (from multiple threads) to optimize */
lock_rw_wrlock(&zones->lock);
- z = local_zones_lookup(zones, rr_name, len, labs, rr_class);
+ z = local_zones_lookup(zones, rr_name, len, labs, rr_class, rr_type);
if(!z) {
z = local_zones_add_zone(zones, rr_name, len, labs, rr_class,
local_zone_transparent);
@@ -1820,14 +1826,47 @@ del_empty_term(struct local_zone* z, struct local_data* d,
}
}
+/** find and remove type from list in domain struct */
+static void
+del_local_rrset(struct local_data* d, uint16_t dtype)
+{
+ struct local_rrset* prev=NULL, *p=d->rrsets;
+ while(p && ntohs(p->rrset->rk.type) != dtype) {
+ prev = p;
+ p = p->next;
+ }
+ if(!p)
+ return; /* rrset type not found */
+ /* unlink it */
+ if(prev) prev->next = p->next;
+ else d->rrsets = p->next;
+ /* no memory recycling for zone deletions ... */
+}
+
void local_zones_del_data(struct local_zones* zones,
uint8_t* name, size_t len, int labs, uint16_t dclass)
{
/* find zone */
struct local_zone* z;
struct local_data* d;
+
+ /* remove DS */
+ lock_rw_rdlock(&zones->lock);
+ z = local_zones_lookup(zones, name, len, labs, dclass, LDNS_RR_TYPE_DS);
+ if(z) {
+ lock_rw_wrlock(&z->lock);
+ d = lz_find_node(z, name, len, labs);
+ if(d) {
+ del_local_rrset(d, LDNS_RR_TYPE_DS);
+ del_empty_term(z, d, name, len, labs);
+ }
+ lock_rw_unlock(&z->lock);
+ }
+ lock_rw_unlock(&zones->lock);
+
+ /* remove other types */
lock_rw_rdlock(&zones->lock);
- z = local_zones_lookup(zones, name, len, labs, dclass);
+ z = local_zones_lookup(zones, name, len, labs, dclass, 0);
if(!z) {
/* no such zone, we're done */
lock_rw_unlock(&zones->lock);