unsigned char *cookie;
uint16_t cookielen;
- _Atomic(isc_stdtime_t) expires;
+ isc_stdtime_t expires;
_Atomic(isc_stdtime_t) lastage;
/*%<
* A nonzero 'expires' field indicates that the entry should
static void
free_adbnamehook(dns_adb_t *adb, dns_adbnamehook_t **namehookp);
static dns_adbentry_t *
-new_adbentry(dns_adb_t *adb, const isc_sockaddr_t *addr);
+new_adbentry(dns_adb_t *adb, const isc_sockaddr_t *addr, isc_stdtime_t now);
static void
destroy_adbentry(dns_adbentry_t *entry);
static bool
UNREACHABLE();
}
- again:
entry = get_attached_and_locked_entry(adb, now, &sockaddr);
-
- if (ENTRY_DEAD(entry)) {
- UNLOCK(&entry->lock);
- dns_adbentry_detach(&entry);
- goto again;
- }
+ INSIST(!ENTRY_DEAD(entry));
dns_adbnamehook_t *anh = NULL;
for (anh = ISC_LIST_HEAD(*hookhead); anh != NULL;
}
INSIST(result == ISC_R_SUCCESS);
- switch (rdataset->trust) {
- case dns_trust_glue:
- case dns_trust_additional:
- rdataset->ttl = ADB_CACHE_MINIMUM;
- break;
- case dns_trust_ultimate:
- rdataset->ttl = 0;
- break;
- default:
- rdataset->ttl = ttlclamp(rdataset->ttl);
- }
-
switch (rdtype) {
case dns_rdatatype_a:
DP(NCACHE_LEVEL,
}
static dns_adbentry_t *
-new_adbentry(dns_adb_t *adb, const isc_sockaddr_t *addr) {
+new_adbentry(dns_adb_t *adb, const isc_sockaddr_t *addr, isc_stdtime_t now) {
dns_adbentry_t *entry = NULL;
entry = isc_mem_get(adb->mctx, sizeof(*entry));
.quota = adb->quota,
.references = ISC_REFCOUNT_INITIALIZER(1),
.adb = dns_adb_ref(adb),
+ .expires = now + ADB_ENTRY_WINDOW,
.magic = DNS_ADBENTRY_MAGIC,
};
INSIST(locktype == isc_rwlocktype_write);
/* Allocate a new entry and add it to the hash table. */
- adbentry = new_adbentry(adb, addr);
+ adbentry = new_adbentry(adb, addr, now);
void *found = NULL;
result = isc_hashmap_add(adb->entries, hashval, match_adbentry,
return (false);
}
- if (atomic_load(&adbentry->expires) == 0 ||
- atomic_load(&adbentry->expires) > now)
- {
+ if (!EXPIRE_OK(adbentry->expires, now)) {
return (false);
}
}
fprintf(f, "]");
}
- if (atomic_load(&entry->expires) != 0) {
- fprintf(f, " [ttl %d]",
- (int)(atomic_load(&entry->expires) - now));
- }
+ fprintf(f, " [ttl %d]", entry->expires - now);
if (adb != NULL && adb->quota != 0 && adb->atr_freq != 0) {
uint_fast32_t quota = atomic_load_relaxed(&entry->quota);
REQUIRE(DNS_ADBADDRINFO_VALID(addr));
REQUIRE(factor <= 10);
- dns_adbentry_t *entry = addr->entry;
-
isc_stdtime_t now = 0;
- if (atomic_load(&entry->expires) == 0 || factor == DNS_ADB_RTTADJAGE) {
+ if (factor == DNS_ADB_RTTADJAGE) {
now = isc_stdtime_now();
}
atomic_store(&addr->entry->srtt, new_srtt);
addr->srtt = new_srtt;
}
-
- (void)atomic_compare_exchange_strong(&addr->entry->expires,
- &(isc_stdtime_t){ 0 },
- now + ADB_ENTRY_WINDOW);
}
void
REQUIRE(DNS_ADB_VALID(adb));
REQUIRE(DNS_ADBADDRINFO_VALID(addr));
- isc_stdtime_t now;
dns_adbentry_t *entry = addr->entry;
unsigned int flags = atomic_load(&entry->flags);
/* repeat */
}
- if (atomic_load(&entry->expires) == 0) {
- now = isc_stdtime_now();
- atomic_store(&entry->expires, now + ADB_ENTRY_WINDOW);
- }
-
/*
* Note that we do not update the other bits in addr->flags with
* the most recent values from addr->entry->flags.
}
entry = get_attached_and_locked_entry(adb, now, sa);
- INSIST(entry != NULL);
UNLOCK(&entry->lock);
dns_adb_freeaddrinfo(dns_adb_t *adb, dns_adbaddrinfo_t **addrp) {
dns_adbaddrinfo_t *addr = NULL;
dns_adbentry_t *entry = NULL;
- isc_stdtime_t now;
REQUIRE(DNS_ADB_VALID(adb));
REQUIRE(addrp != NULL);
REQUIRE(DNS_ADBENTRY_VALID(entry));
- now = isc_stdtime_now();
- (void)atomic_compare_exchange_strong(
- &entry->expires, &(isc_stdtime_t){ 0 }, now + ADB_ENTRY_WINDOW);
-
free_adbaddrinfo(adb, &addr);
}