2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

remove the remaining uses of dns_name_copy()

dns_name_copy() has been replaced nearly everywhere with
dns_name_copynf().  this commit changes the last two uses of
the original function.  afterward, we can remove the old
dns_name_copy() implementation, and replace it with _copynf().
This commit is contained in:
Evan Hunt
2021-05-21 17:10:59 -07:00
parent 6803f394c5
commit b1fe1b8ae3
2 changed files with 30 additions and 34 deletions

View File

@@ -2244,9 +2244,7 @@ setup_lookup(dig_lookup_t *lookup) {
name, lookup->oname, name, lookup->oname,
lookup->name, &lookup->namebuf); lookup->name, &lookup->namebuf);
} else { } else {
result = dns_name_copy( dns_name_copynf(name, lookup->name);
name, lookup->name,
&lookup->namebuf);
} }
} }
if (result != ISC_R_SUCCESS) { if (result != ISC_R_SUCCESS) {

View File

@@ -27,6 +27,7 @@
#include <isc/util.h> #include <isc/util.h>
#include <dns/badcache.h> #include <dns/badcache.h>
#include <dns/fixedname.h>
#include <dns/name.h> #include <dns/name.h>
#include <dns/rdatatype.h> #include <dns/rdatatype.h>
#include <dns/types.h> #include <dns/types.h>
@@ -57,7 +58,8 @@ struct dns_bcentry {
isc_time_t expire; isc_time_t expire;
uint32_t flags; uint32_t flags;
unsigned int hashval; unsigned int hashval;
dns_name_t name; dns_fixedname_t fname;
dns_name_t *name;
}; };
static void 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) { for (bad = bc->table[i]; bad != NULL; bad = next) {
next = bad->next; next = bad->next;
if (isc_time_compare(&bad->expire, now) < 0) { if (isc_time_compare(&bad->expire, now) < 0) {
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
} else { } else {
bad->next = newtable[bad->hashval % newsize]; bad->next = newtable[bad->hashval % newsize];
@@ -231,7 +232,7 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name,
prev = NULL; prev = NULL;
for (bad = bc->table[hash]; bad != NULL; bad = next) { for (bad = bc->table[hash]; bad != NULL; bad = next) {
next = 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) { if (update) {
bad->expire = *expire; bad->expire = *expire;
bad->flags = flags; bad->flags = flags;
@@ -244,8 +245,7 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name,
} else { } else {
prev->next = bad->next; prev->next = bad->next;
} }
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
} else { } else {
prev = bad; prev = bad;
@@ -253,18 +253,22 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name,
} }
if (bad == NULL) { if (bad == NULL) {
unsigned count;
isc_buffer_t buffer; isc_buffer_t buffer;
bad = isc_mem_get(bc->mctx, sizeof(*bad) + name->length);
bad->type = type; bad = isc_mem_get(bc->mctx, sizeof(*bad));
bad->hashval = hashval; *bad = (dns_bcentry_t){ .type = type,
bad->expire = *expire; .hashval = hashval,
bad->flags = flags; .expire = *expire,
.flags = flags,
.next = bc->table[hash] };
isc_buffer_init(&buffer, bad + 1, name->length); isc_buffer_init(&buffer, bad + 1, name->length);
dns_name_init(&bad->name, NULL); bad->name = dns_fixedname_initname(&bad->fname);
dns_name_copy(name, &bad->name, &buffer); dns_name_copynf(name, bad->name);
bad->next = bc->table[hash];
bc->table[hash] = bad; 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) || if ((count > bc->size * 8) ||
(count < bc->size * 2 && bc->size > bc->minsize)) { (count < bc->size * 2 && bc->size > bc->minsize)) {
resize = true; resize = true;
@@ -325,12 +329,11 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name,
bc->table[hash] = bad->next; bc->table[hash] = bad->next;
} }
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub(&bc->count, 1); atomic_fetch_sub(&bc->count, 1);
continue; continue;
} }
if (bad->type == type && dns_name_equal(name, &bad->name)) { if (bad->type == type && dns_name_equal(name, bad->name)) {
if (flagp != NULL) { if (flagp != NULL) {
*flagp = bad->flags; *flagp = bad->flags;
} }
@@ -350,8 +353,7 @@ skip:
bad = bc->table[i]; bad = bc->table[i];
if (bad != NULL && isc_time_compare(&bad->expire, now) < 0) { if (bad != NULL && isc_time_compare(&bad->expire, now) < 0) {
bc->table[i] = bad->next; bc->table[i] = bad->next;
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
} }
UNLOCK(&bc->tlocks[i]); 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 (i = 0; atomic_load_relaxed(&bc->count) > 0 && i < bc->size; i++) {
for (entry = bc->table[i]; entry != NULL; entry = next) { for (entry = bc->table[i]; entry != NULL; entry = next) {
next = entry->next; next = entry->next;
isc_mem_put(bc->mctx, entry, isc_mem_put(bc->mctx, entry, sizeof(*entry));
sizeof(*entry) + entry->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
} }
bc->table[i] = NULL; bc->table[i] = NULL;
@@ -404,15 +405,14 @@ dns_badcache_flushname(dns_badcache_t *bc, const dns_name_t *name) {
int n; int n;
next = bad->next; next = bad->next;
n = isc_time_compare(&bad->expire, &now); 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) { if (prev == NULL) {
bc->table[hash] = bad->next; bc->table[hash] = bad->next;
} else { } else {
prev->next = bad->next; prev->next = bad->next;
} }
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
} else { } else {
prev = bad; 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) { for (bad = bc->table[i]; bad != NULL; bad = next) {
next = bad->next; next = bad->next;
n = isc_time_compare(&bad->expire, &now); 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) { if (prev == NULL) {
bc->table[i] = bad->next; bc->table[i] = bad->next;
} else { } else {
prev->next = bad->next; prev->next = bad->next;
} }
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
} else { } else {
prev = bad; prev = bad;
@@ -501,13 +500,12 @@ dns_badcache_print(dns_badcache_t *bc, const char *cachename, FILE *fp) {
bc->table[i] = bad->next; bc->table[i] = bad->next;
} }
isc_mem_put(bc->mctx, bad, isc_mem_put(bc->mctx, bad, sizeof(*bad));
sizeof(*bad) + bad->name.length);
atomic_fetch_sub_relaxed(&bc->count, 1); atomic_fetch_sub_relaxed(&bc->count, 1);
continue; continue;
} }
prev = bad; prev = bad;
dns_name_format(&bad->name, namebuf, sizeof(namebuf)); dns_name_format(bad->name, namebuf, sizeof(namebuf));
dns_rdatatype_format(bad->type, typebuf, dns_rdatatype_format(bad->type, typebuf,
sizeof(typebuf)); sizeof(typebuf));
t = isc_time_microdiff(&bad->expire, &now); t = isc_time_microdiff(&bad->expire, &now);