]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Export zone functions
authorMatthijs Mekking <matthijs@isc.org>
Fri, 17 Oct 2025 14:14:09 +0000 (16:14 +0200)
committerMatthijs Mekking <matthijs@isc.org>
Fri, 31 Oct 2025 12:43:47 +0000 (13:43 +0100)
Make some zone functions available that we are going to need in the
notify code.

lib/dns/include/dns/zone.h
lib/dns/zone.c
lib/dns/zone_p.h
tests/dns/nsec3param_test.c
tests/dns/sigs_test.c
tests/dns/skr_test.c

index 7a7a8325cf894ab54a3afd31dd5a5bc90b013eb2..acde98421b154af080918dfe6c940697ad6d9bb2 100644 (file)
@@ -280,6 +280,15 @@ dns_zone_getorigin(dns_zone_t *zone);
  *\li  'zone' to be a valid zone.
  */
 
+dns_rdataclass_t
+dns_zone_getrdclass(dns_zone_t *zone);
+/*%<
+ *     Returns the value of the rdclass.
+ *
+ * Require:
+ *\li  'zone' to be a valid zone.
+ */
+
 void
 dns_zone_setfile(dns_zone_t *zone, const char *file, const char *initial_file,
                 dns_masterformat_t format, const dns_master_style_t *style);
index 918489e4eefce8d5469b913514e22cab59961b27..e7ea558681b0623122660a40bcb3f5da060b3685 100644 (file)
 #define DNS_DEFAULT_IDLEOUT 3600       /*%< 1 hour */
 #define MAX_XFER_TIME      (2 * 3600) /*%< Documented default is 2 hours */
 #define RESIGN_DELAY       3600       /*%< 1 hour */
-#define UDP_REQUEST_TIMEOUT 5         /*%< 5 seconds */
-#define UDP_REQUEST_RETRIES 2
-#define TCP_REQUEST_TIMEOUT \
-       (UDP_REQUEST_TIMEOUT * (UDP_REQUEST_RETRIES + 1) + 1)
 
 #ifndef DNS_MAX_EXPIRE
 #define DNS_MAX_EXPIRE 14515200 /*%< 24 weeks */
@@ -987,20 +983,6 @@ zone_journal_rollforward(dns_zone_t *zone, dns_db_t *db, bool *needdump,
 static void
 setnsec3param(void *arg);
 
-static void
-zmgr_tlsctx_attach(dns_zonemgr_t *zmgr, isc_tlsctx_cache_t **ptlsctx_cache);
-/*%<
- *     Attach to TLS client context cache used for zone transfers via
- *     encrypted transports (e.g. XoT).
- *
- * The obtained reference needs to be detached by a call to
- * 'isc_tlsctx_cache_detach()' when not needed anymore.
- *
- * Requires:
- *\li  'zmgr' is a valid zone manager.
- *\li  'ptlsctx_cache' is not 'NULL' and points to 'NULL'.
- */
-
 #define ENTER zone_debuglog(zone, __func__, 1, "enter")
 
 static const unsigned int dbargc_default = 1;
@@ -6215,15 +6197,6 @@ ISC_REFCOUNT_TRACE_IMPL(dns_zone, zone_destroy);
 ISC_REFCOUNT_IMPL(dns_zone, zone_destroy);
 #endif
 
-void
-dns_zone_iattach(dns_zone_t *source, dns_zone_t **target) {
-       REQUIRE(DNS_ZONE_VALID(source));
-
-       LOCK_ZONE(source);
-       zone_iattach(source, target);
-       UNLOCK_ZONE(source);
-}
-
 static void
 zone_iattach(dns_zone_t *source, dns_zone_t **target) {
        REQUIRE(DNS_ZONE_VALID(source));
@@ -6235,6 +6208,20 @@ zone_iattach(dns_zone_t *source, dns_zone_t **target) {
        *target = source;
 }
 
+void
+dns__zone_iattach_locked(dns_zone_t *source, dns_zone_t **target) {
+       zone_iattach(source, target);
+}
+
+void
+dns_zone_iattach(dns_zone_t *source, dns_zone_t **target) {
+       REQUIRE(DNS_ZONE_VALID(source));
+
+       LOCK_ZONE(source);
+       zone_iattach(source, target);
+       UNLOCK_ZONE(source);
+}
+
 static void
 zone_idetach(dns_zone_t **zonep) {
        dns_zone_t *zone;
@@ -6253,6 +6240,11 @@ zone_idetach(dns_zone_t **zonep) {
               0);
 }
 
+void
+dns__zone_idetach_locked(dns_zone_t **zonep) {
+       zone_idetach(zonep);
+}
+
 void
 dns_zone_idetach(dns_zone_t **zonep) {
        dns_zone_t *zone;
@@ -12770,11 +12762,7 @@ notify_destroy(dns_notify_t *notify, bool locked) {
                if (!locked) {
                        UNLOCK_ZONE(notify->zone);
                }
-               if (locked) {
-                       zone_idetach(&notify->zone);
-               } else {
-                       dns_zone_idetach(&notify->zone);
-               }
+               dns_zone_idetach(&notify->zone, locked);
        }
        if (notify->find != NULL) {
                dns_adb_destroyfind(&notify->find);
@@ -13006,7 +12994,7 @@ again:
                options |= DNS_REQUESTOPT_TCP;
        }
 
-       zmgr_tlsctx_attach(notify->zone->zmgr, &zmgr_tlsctx_cache);
+       dns_zonemgr_tlsctx_attach(notify->zone->zmgr, &zmgr_tlsctx_cache);
 
        const unsigned int connect_timeout = isc_nm_getinitialtimeout() /
                                             MS_PER_SEC;
@@ -16514,6 +16502,20 @@ dns_zone_getorigin(dns_zone_t *zone) {
        return &zone->origin;
 }
 
+dns_rdataclass_t
+dns_zone_getrdclass(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+
+       return zone->rdclass;
+}
+
+dns_notifyctx_t *
+dns__zone_getnotifyctx(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+
+       return &zone->notifyctx;
+}
+
 void
 dns_zone_setidlein(dns_zone_t *zone, uint32_t idlein) {
        REQUIRE(DNS_ZONE_VALID(zone));
@@ -16545,6 +16547,43 @@ dns_zone_getidleout(dns_zone_t *zone) {
        return zone->idleout;
 }
 
+void
+dns__zone_stats_increment(dns_zone_t *zone, isc_statscounter_t counter) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       REQUIRE(LOCKED_ZONE(zone));
+       inc_stats(zone, counter);
+}
+
+void
+dns__zone_lock(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       LOCK_ZONE(zone);
+}
+
+void
+dns__zone_unlock(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       UNLOCK_ZONE(zone);
+}
+
+bool
+dns__zone_locked(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       return LOCKED_ZONE(zone);
+}
+
+bool
+dns__zone_loaded(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       return DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) != 0;
+}
+
+bool
+dns__zone_exiting(dns_zone_t *zone) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       return DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING) != 0;
+}
+
 static void
 notify_done(void *arg) {
        dns_request_t *request = (dns_request_t *)arg;
@@ -18889,7 +18928,7 @@ got_transfer_quota(void *arg) {
 
        INSIST(isc_sockaddr_pf(&primaryaddr) == isc_sockaddr_pf(&sourceaddr));
 
-       zmgr_tlsctx_attach(zone->zmgr, &zmgr_tlsctx_cache);
+       dns__zonemgr_tlsctx_attach(zone->zmgr, &zmgr_tlsctx_cache);
 
        dns_xfrin_create(zone, xfrtype, ixfr_maxdiffs, &primaryaddr,
                         &sourceaddr, zone->tsigkey, soa_transport_type,
@@ -19033,7 +19072,7 @@ next:
                }
        }
 
-       zmgr_tlsctx_attach(zone->zmgr, &zmgr_tlsctx_cache);
+       dns__zonemgr_tlsctx_attach(zone->zmgr, &zmgr_tlsctx_cache);
        const unsigned int connect_timeout = isc_nm_getprimariestimeout() /
                                             MS_PER_SEC;
        result = dns_request_createraw(
@@ -19898,6 +19937,13 @@ dns_zonemgr_getnotifyrate(dns_zonemgr_t *zmgr) {
        return zmgr->notifyrate;
 }
 
+void
+dns__zonemgr_getnotifyrl(dns_zonemgr_t *zmgr, isc_ratelimiter_t **prl) {
+       REQUIRE(DNS_ZONEMGR_VALID(zmgr));
+
+       *prl = zmgr->notifyrl;
+}
+
 unsigned int
 dns_zonemgr_getstartupnotifyrate(dns_zonemgr_t *zmgr) {
        REQUIRE(DNS_ZONEMGR_VALID(zmgr));
@@ -19905,6 +19951,13 @@ dns_zonemgr_getstartupnotifyrate(dns_zonemgr_t *zmgr) {
        return zmgr->startupnotifyrate;
 }
 
+void
+dns__zonemgr_getstartupnotifyrl(dns_zonemgr_t *zmgr, isc_ratelimiter_t **prl) {
+       REQUIRE(DNS_ZONEMGR_VALID(zmgr));
+
+       *prl = zmgr->startupnotifyrl;
+}
+
 unsigned int
 dns_zonemgr_getserialqueryrate(dns_zonemgr_t *zmgr) {
        REQUIRE(DNS_ZONEMGR_VALID(zmgr));
@@ -20320,6 +20373,16 @@ dns_zone_setisself(dns_zone_t *zone, dns_isselffunc_t isself, void *arg) {
        UNLOCK_ZONE(zone);
 }
 
+void
+dns__zone_getisself(dns_zone_t *zone, dns_isselffunc_t *isself, void **arg) {
+       REQUIRE(DNS_ZONE_VALID(zone));
+       REQUIRE(isself != NULL);
+       REQUIRE(arg != NULL && *arg == NULL);
+
+       *isself = zone->isself;
+       *arg = zone->isselfarg;
+}
+
 void
 dns_zone_setnotifydefer(dns_zone_t *zone, uint32_t defer) {
        REQUIRE(DNS_ZONE_VALID(zone));
@@ -24677,8 +24740,9 @@ dns_zonemgr_set_tlsctx_cache(dns_zonemgr_t *zmgr,
        RWUNLOCK(&zmgr->tlsctx_cache_rwlock, isc_rwlocktype_write);
 }
 
-static void
-zmgr_tlsctx_attach(dns_zonemgr_t *zmgr, isc_tlsctx_cache_t **ptlsctx_cache) {
+void
+dns__zonemgr_tlsctx_attach(dns_zonemgr_t *zmgr,
+                          isc_tlsctx_cache_t **ptlsctx_cache) {
        REQUIRE(DNS_ZONEMGR_VALID(zmgr));
        REQUIRE(ptlsctx_cache != NULL && *ptlsctx_cache == NULL);
 
index 3cd21982bcc7647afb498bdde44776a7c5bb6240..aefa74ea3b1b6934d4b99d58a46b77bb2bd114d6 100644 (file)
  *     associated unit tests.
  */
 
+#define UDP_REQUEST_TIMEOUT 5 /*%< 5 seconds */
+#define UDP_REQUEST_RETRIES 2
+#define TCP_REQUEST_TIMEOUT \
+       (UDP_REQUEST_TIMEOUT * (UDP_REQUEST_RETRIES + 1) + 1)
+
 typedef struct {
        dns_diff_t *diff;
        bool offline;
@@ -38,3 +43,145 @@ isc_result_t
 dns__zone_lookup_nsec3param(dns_zone_t *zone, dns_rdata_nsec3param_t *lookup,
                            dns_rdata_nsec3param_t *param,
                            unsigned char saltbuf[255], bool resalt);
+
+void
+dns__zone_lock(dns_zone_t *zone);
+/*%<
+ *      Locks the zone.
+ *
+ * Requires:
+ *\li   'zone' to be a valid zone.
+ */
+
+void
+dns__zone_unlock(dns_zone_t *zone);
+/*%<
+ *      Unlocks the zone.
+ *
+ * Requires:
+ *\li   'zone' to be a valid zone.
+ */
+
+bool
+dns__zone_locked(dns_zone_t *zone);
+/*%<
+ *      Checks if the zone is locked.
+ *
+ * Requires:
+ *\li   'zone' to be a valid zone.
+ *
+ * Returns:
+ *\li   true if the zone is locked, false otherwise.
+ */
+
+bool
+dns__zone_loaded(dns_zone_t *zone);
+/*%<
+ *      Checks if the zone is loaded.
+ *
+ * Requires:
+ *\li   'zone' to be a valid zone.
+ *
+ * Returns:
+ *\li   true if the zone is loaded, false otherwise.
+ */
+
+bool
+dns__zone_exiting(dns_zone_t *zone);
+/*%<
+ *      Checks if the zone is exiting.
+ *
+ * Requires:
+ *\li   'zone' to be a valid zone.
+ *
+ * Returns:
+ *\li   true if the zone is exiting, false otherwise.
+ */
+
+void
+dns__zone_stats_increment(dns_zone_t *zone, isc_statscounter_t counter);
+/*%
+ *      Increment resolver-related statistics counters
+ *
+ * Requires:
+ *\li   'zone' to be a valid zone, and locked.
+ */
+
+dns_notifyctx_t *
+dns__zone_getnotifyctx(dns_zone_t *zone);
+/*%<
+ *     Returns the notify context.
+ *
+ * Require:
+ *\li  'zone' to be a valid zone.
+ */
+
+void
+dns__zonemgr_getnotifyrl(dns_zonemgr_t *zmgr, isc_ratelimiter_t **prl);
+/*%<
+ *     Get the NOTIFY requests rate limiter
+ *
+ * Requires:
+ *\li  'zmgr' to be a valid zone manager
+ */
+
+void
+dns__zonemgr_getstartupnotifyrl(dns_zonemgr_t *zmgr, isc_ratelimiter_t **prl);
+/*%<
+ *     Get the startup NOTIFY requests rate limiter
+ *
+ * Requires:
+ *\li  'zmgr' to be a valid zone manager
+ */
+
+void
+dns__zonemgr_tlsctx_attach(dns_zonemgr_t *zmgr,
+                          isc_tlsctx_cache_t **ptlsctx_cache);
+/*%<
+ *     Attach to TLS client context cache used for zone transfers via
+ *     encrypted transports (e.g. XoT).
+ *
+ *     The obtained reference needs to be detached by a call to
+ *     'isc_tlsctx_cache_detach()' when not needed anymore.
+ *
+ * Requires:
+ *\li  'zmgr' is a valid zone manager.
+ *\li  'ptlsctx_cache' is not 'NULL' and points to 'NULL'.
+ */
+
+void
+dns__zone_getisself(dns_zone_t *zone, dns_isselffunc_t *isself, void **arg);
+/*%<
+ *     Returns the isself callback function and argument.
+ *
+ * Require:
+ *\li  'zone' to be a valid zone.
+ *\li  'isself' is not NULL.
+ *\li  'arg' is not NULL and '*arg' is NULL.
+ */
+
+void
+dns__zone_iattach_locked(dns_zone_t *source, dns_zone_t **target);
+/*%<
+ *      Attach '*target' to 'source' incrementing its internal
+ *      reference count.  This is intended for use by operations
+ *      such as zone transfers that need to prevent the zone
+ *      object from being freed but not from shutting down.
+ *
+ * Require:
+ *\li   The caller is running in the context of the zone's loop.
+ *\li   'zone' to be a valid zone, already locked.
+ *\li   'target' to be non NULL and '*target' to be NULL.
+ */
+
+void
+dns__zone_idetach_locked(dns_zone_t **zonep);
+/*%<
+ *      Detach from a zone decrementing its internal reference count.
+ *      If there are no more internal or external references to the
+ *      zone, it will be freed.
+ *
+ * Require:
+ *\li   The caller is running in the context of the zone's loop.
+ *\li   'zonep' to point to a valid zone, already locked.
+ */
index ec194f297de0c16f669d20bb98ea778eba34821c..b028f6a4d5650c5197478717972a2e8e46093b7f 100644 (file)
@@ -27,6 +27,7 @@
 #include <isc/lib.h>
 #include <isc/result.h>
 #include <isc/string.h>
+#include <isc/tls.h>
 #include <isc/util.h>
 
 #include <dns/db.h>
index 41faca7d76662222ce3439a929e9a338dcc99290..040ca26abda41a151f28cce287d9e929a4cb6604 100644 (file)
@@ -29,6 +29,7 @@
 #include <isc/region.h>
 #include <isc/result.h>
 #include <isc/stdtime.h>
+#include <isc/tls.h>
 #include <isc/types.h>
 #include <isc/util.h>
 
index ec41f3b3dd3a1db6d8e78b24495831cec0826248..eb2abd9b74823fe7cab0008ab42a2b4c88602273 100644 (file)
@@ -40,6 +40,7 @@
 #include <dns/secalg.h>
 #include <dns/skr.h>
 #include <dns/time.h>
+#include <dns/tls.h>
 
 #include "zone_p.h"