diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 6337ce92f3..754bbbb5a5 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -2244,9 +2244,7 @@ setup_lookup(dig_lookup_t *lookup) { name, lookup->oname, lookup->name, &lookup->namebuf); } else { - result = dns_name_copy( - name, lookup->name, - &lookup->namebuf); + dns_name_copynf(name, lookup->name); } } if (result != ISC_R_SUCCESS) { diff --git a/lib/dns/badcache.c b/lib/dns/badcache.c index 7439713026..86ba39c4c6 100644 --- a/lib/dns/badcache.c +++ b/lib/dns/badcache.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -57,7 +58,8 @@ struct dns_bcentry { isc_time_t expire; uint32_t flags; unsigned int hashval; - dns_name_t name; + dns_fixedname_t fname; + dns_name_t *name; }; static void @@ -183,8 +185,7 @@ badcache_resize(dns_badcache_t *bc, isc_time_t *now) { for (bad = bc->table[i]; bad != NULL; bad = next) { next = bad->next; if (isc_time_compare(&bad->expire, now) < 0) { - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub_relaxed(&bc->count, 1); } else { bad->next = newtable[bad->hashval % newsize]; @@ -231,7 +232,7 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, prev = NULL; for (bad = bc->table[hash]; bad != NULL; bad = next) { next = bad->next; - if (bad->type == type && dns_name_equal(name, &bad->name)) { + if (bad->type == type && dns_name_equal(name, bad->name)) { if (update) { bad->expire = *expire; bad->flags = flags; @@ -244,8 +245,7 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, } else { prev->next = bad->next; } - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub_relaxed(&bc->count, 1); } else { prev = bad; @@ -253,18 +253,22 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, } if (bad == NULL) { + unsigned count; isc_buffer_t buffer; - bad = isc_mem_get(bc->mctx, sizeof(*bad) + name->length); - bad->type = type; - bad->hashval = hashval; - bad->expire = *expire; - bad->flags = flags; + + bad = isc_mem_get(bc->mctx, sizeof(*bad)); + *bad = (dns_bcentry_t){ .type = type, + .hashval = hashval, + .expire = *expire, + .flags = flags, + .next = bc->table[hash] }; + isc_buffer_init(&buffer, bad + 1, name->length); - dns_name_init(&bad->name, NULL); - dns_name_copy(name, &bad->name, &buffer); - bad->next = bc->table[hash]; + bad->name = dns_fixedname_initname(&bad->fname); + dns_name_copynf(name, bad->name); bc->table[hash] = bad; - unsigned count = atomic_fetch_add_relaxed(&bc->count, 1); + + count = atomic_fetch_add_relaxed(&bc->count, 1); if ((count > bc->size * 8) || (count < bc->size * 2 && bc->size > bc->minsize)) { resize = true; @@ -325,12 +329,11 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name, bc->table[hash] = bad->next; } - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub(&bc->count, 1); continue; } - if (bad->type == type && dns_name_equal(name, &bad->name)) { + if (bad->type == type && dns_name_equal(name, bad->name)) { if (flagp != NULL) { *flagp = bad->flags; } @@ -350,8 +353,7 @@ skip: bad = bc->table[i]; if (bad != NULL && isc_time_compare(&bad->expire, now) < 0) { bc->table[i] = bad->next; - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub_relaxed(&bc->count, 1); } UNLOCK(&bc->tlocks[i]); @@ -372,8 +374,7 @@ dns_badcache_flush(dns_badcache_t *bc) { for (i = 0; atomic_load_relaxed(&bc->count) > 0 && i < bc->size; i++) { for (entry = bc->table[i]; entry != NULL; entry = next) { next = entry->next; - isc_mem_put(bc->mctx, entry, - sizeof(*entry) + entry->name.length); + isc_mem_put(bc->mctx, entry, sizeof(*entry)); atomic_fetch_sub_relaxed(&bc->count, 1); } bc->table[i] = NULL; @@ -404,15 +405,14 @@ dns_badcache_flushname(dns_badcache_t *bc, const dns_name_t *name) { int n; next = bad->next; n = isc_time_compare(&bad->expire, &now); - if (n < 0 || dns_name_equal(name, &bad->name)) { + if (n < 0 || dns_name_equal(name, bad->name)) { if (prev == NULL) { bc->table[hash] = bad->next; } else { prev->next = bad->next; } - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub_relaxed(&bc->count, 1); } else { prev = bad; @@ -450,15 +450,14 @@ dns_badcache_flushtree(dns_badcache_t *bc, const dns_name_t *name) { for (bad = bc->table[i]; bad != NULL; bad = next) { next = bad->next; n = isc_time_compare(&bad->expire, &now); - if (n < 0 || dns_name_issubdomain(&bad->name, name)) { + if (n < 0 || dns_name_issubdomain(bad->name, name)) { if (prev == NULL) { bc->table[i] = bad->next; } else { prev->next = bad->next; } - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub_relaxed(&bc->count, 1); } else { prev = bad; @@ -501,13 +500,12 @@ dns_badcache_print(dns_badcache_t *bc, const char *cachename, FILE *fp) { bc->table[i] = bad->next; } - isc_mem_put(bc->mctx, bad, - sizeof(*bad) + bad->name.length); + isc_mem_put(bc->mctx, bad, sizeof(*bad)); atomic_fetch_sub_relaxed(&bc->count, 1); continue; } prev = bad; - dns_name_format(&bad->name, namebuf, sizeof(namebuf)); + dns_name_format(bad->name, namebuf, sizeof(namebuf)); dns_rdatatype_format(bad->type, typebuf, sizeof(typebuf)); t = isc_time_microdiff(&bad->expire, &now);