From: Matthijs Mekking Date: Fri, 17 Oct 2025 14:14:09 +0000 (+0200) Subject: Export zone functions X-Git-Tag: v9.21.15~14^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=090a451e66569300280f4b9430ffad0c5c988216;p=thirdparty%2Fbind9.git Export zone functions Make some zone functions available that we are going to need in the notify code. --- diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 7a7a8325cf8..acde98421b1 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -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); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 918489e4eef..e7ea558681b 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -158,10 +158,6 @@ #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(¬ify->zone); - } else { - dns_zone_idetach(¬ify->zone); - } + dns_zone_idetach(¬ify->zone, locked); } if (notify->find != NULL) { dns_adb_destroyfind(¬ify->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); diff --git a/lib/dns/zone_p.h b/lib/dns/zone_p.h index 3cd21982bcc..aefa74ea3b1 100644 --- a/lib/dns/zone_p.h +++ b/lib/dns/zone_p.h @@ -22,6 +22,11 @@ * 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. + */ diff --git a/tests/dns/nsec3param_test.c b/tests/dns/nsec3param_test.c index ec194f297de..b028f6a4d56 100644 --- a/tests/dns/nsec3param_test.c +++ b/tests/dns/nsec3param_test.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include diff --git a/tests/dns/sigs_test.c b/tests/dns/sigs_test.c index 41faca7d766..040ca26abda 100644 --- a/tests/dns/sigs_test.c +++ b/tests/dns/sigs_test.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/tests/dns/skr_test.c b/tests/dns/skr_test.c index ec41f3b3dd3..eb2abd9b748 100644 --- a/tests/dns/skr_test.c +++ b/tests/dns/skr_test.c @@ -40,6 +40,7 @@ #include #include #include +#include #include "zone_p.h"