]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Change dns_adbentry_overquota() to dns_adb_overquota()
authorOndřej Surý <ondrej@isc.org>
Thu, 30 Mar 2023 19:19:17 +0000 (21:19 +0200)
committerOndřej Surý <ondrej@isc.org>
Tue, 4 Apr 2023 14:21:49 +0000 (16:21 +0200)
The dns_adbentry_overquota() was violating the layers accessing the
adbentry struct members directly.  Change it to dns_adb_overquota() to
match the dns_adb API.

lib/dns/adb.c
lib/dns/include/dns/adb.h
lib/dns/resolver.c

index 071774f4cca56aa66069ca1632a9ff34a8df47d4..8fe368445f018624295d3079cb57fb234e14128d 100644 (file)
@@ -388,6 +388,9 @@ adjustsrtt(dns_adbaddrinfo_t *addr, unsigned int rtt, unsigned int factor,
 static void
 log_quota(dns_adbentry_t *entry, const char *fmt, ...) ISC_FORMAT_PRINTF(2, 3);
 
+static bool
+adbentry_overquota(dns_adbentry_t *entry);
+
 /*
  * MUST NOT overlap DNS_ADBFIND_* flags!
  */
@@ -1567,7 +1570,7 @@ copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find,
                        entry = namehook->entry;
                        LOCK(&entry->lock);
 
-                       if (dns_adbentry_overquota(entry)) {
+                       if (adbentry_overquota(entry)) {
                                find->options |= (DNS_ADBFIND_LAMEPRUNED |
                                                  DNS_ADBFIND_OVERQUOTA);
                                goto nextv4;
@@ -1599,7 +1602,7 @@ copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find,
                        entry = namehook->entry;
                        LOCK(&entry->lock);
 
-                       if (dns_adbentry_overquota(entry)) {
+                       if (adbentry_overquota(entry)) {
                                find->options |= (DNS_ADBFIND_LAMEPRUNED |
                                                  DNS_ADBFIND_OVERQUOTA);
                                goto nextv6;
@@ -3714,18 +3717,23 @@ dns_adb_getquota(dns_adb_t *adb, uint32_t *quotap, uint32_t *freqp,
        }
 }
 
-bool
-dns_adbentry_overquota(dns_adbentry_t *entry) {
-       uint_fast32_t quota, active;
-
+static bool
+adbentry_overquota(dns_adbentry_t *entry) {
        REQUIRE(DNS_ADBENTRY_VALID(entry));
 
-       quota = atomic_load_relaxed(&entry->quota);
-       active = atomic_load_acquire(&entry->active);
+       uint_fast32_t quota = atomic_load_relaxed(&entry->quota);
+       uint_fast32_t active = atomic_load_acquire(&entry->active);
 
        return (quota != 0 && active >= quota);
 }
 
+bool
+dns_adb_overquota(dns_adb_t *adb ISC_ATTR_UNUSED, dns_adbaddrinfo_t *addrinfo) {
+       REQUIRE(DNS_ADBADDRINFO_VALID(addrinfo));
+
+       return (adbentry_overquota(addrinfo->entry));
+}
+
 void
 dns_adb_beginudpfetch(dns_adb_t *adb, dns_adbaddrinfo_t *addr) {
        uint_fast32_t active;
index b5b88abb8fec80a5040a45efd7bf1c41fc63187b..6a1af8915805cb2fa8525a7a9de015b38bbee688 100644 (file)
@@ -75,6 +75,7 @@
 #include <isc/lang.h>
 #include <isc/magic.h>
 #include <isc/mem.h>
+#include <isc/mutex.h>
 #include <isc/sockaddr.h>
 
 #include <dns/types.h>
@@ -743,7 +744,7 @@ dns_adb_getquota(dns_adb_t *adb, uint32_t *quotap, uint32_t *freqp,
  */
 
 bool
-dns_adbentry_overquota(dns_adbentry_t *entry);
+dns_adb_overquota(dns_adb_t *adb, dns_adbaddrinfo_t *addr);
 /*%<
  * Returns true if the specified ADB has too many active fetches.
  *
index 6f6cfbb6025ed6bf2291cb3c1d24716f2c2682b2..dab6b404ede56f7d1b8cde540ab04bf402017540 100644 (file)
@@ -2100,7 +2100,7 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo,
        query->magic = QUERY_MAGIC;
 
        if ((query->options & DNS_FETCHOPT_TCP) == 0) {
-               if (dns_adbentry_overquota(addrinfo->entry)) {
+               if (dns_adb_overquota(fctx->adb, addrinfo)) {
                        UNLOCK(&fctx->lock);
                        result = ISC_R_QUOTA;
                        goto cleanup_dispatch;
@@ -3964,7 +3964,7 @@ fctx_try(fetchctx_t *fctx, bool retrying, bool badcache) {
        addrinfo = fctx_nextaddress(fctx);
 
        /* Try to find an address that isn't over quota */
-       while (addrinfo != NULL && dns_adbentry_overquota(addrinfo->entry)) {
+       while (addrinfo != NULL && dns_adb_overquota(fctx->adb, addrinfo)) {
                addrinfo = fctx_nextaddress(fctx);
        }
 
@@ -3988,7 +3988,7 @@ fctx_try(fetchctx_t *fctx, bool retrying, bool badcache) {
                addrinfo = fctx_nextaddress(fctx);
 
                while (addrinfo != NULL &&
-                      dns_adbentry_overquota(addrinfo->entry))
+                      dns_adb_overquota(fctx->adb, addrinfo))
                {
                        addrinfo = fctx_nextaddress(fctx);
                }