From: Aram Sargsyan Date: Tue, 30 May 2023 14:39:02 +0000 (+0000) Subject: Implement dns_zone_getxfr() X-Git-Tag: v9.19.18~70^2~7 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=826392f8c8f37730f29bb4797f5b7cd1ab332720;p=thirdparty%2Fbind9.git Implement dns_zone_getxfr() The function is needed to get an attached xfrin and its current state in statschannel.c for providing xfrin information in the statistics channel. --- diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index b7084676db6..233793cc244 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -35,6 +35,7 @@ #include #include #include +#include #include /* Define to 1 for detailed reference tracing */ @@ -1789,6 +1790,28 @@ dns_zonemgr_getcount(dns_zonemgr_t *zmgr, int state); *\li 'state' to be a valid DNS_ZONESTATE_ constant. */ +isc_result_t +dns_zone_getxfr(dns_zone_t *zone, dns_xfrin_t **xfrp, bool *is_running, + bool *is_deferred, bool *is_pending, bool *needs_refresh); +/*%< + * Returns the xfrin associated with the zone (if any) with the current + * transfer states (as booleans). When no longer needed, the returned xfrin + * must be detached. + * + * Requires: + *\li 'zone' to be a valid zone. + *\li 'xfrp' to be non NULL and '*xfrp' to be NULL. + *\li 'is_running' to be non NULL. + *\li 'is_deferred' to be non NULL. + *\li 'is_pending' to be non NULL. + *\li 'needs_refresh' to be non NULL. + * + * Returns: + * ISC_R_SUCCESS xfrin exists and the information was returned. + * ISC_R_NOTFOUND no xfrin was found for the zone. + * ISC_R_FAILED error while trying to get the xfrin information + */ + void dns_zonemgr_unreachableadd(dns_zonemgr_t *zmgr, isc_sockaddr_t *remote, isc_sockaddr_t *local, isc_time_t *now); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index 9a87540586d..8e9c4ca5d66 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -19164,6 +19164,45 @@ dns_zonemgr_getcount(dns_zonemgr_t *zmgr, int state) { return (count); } +isc_result_t +dns_zone_getxfr(dns_zone_t *zone, dns_xfrin_t **xfrp, bool *is_running, + bool *is_deferred, bool *is_pending, bool *needs_refresh) { + REQUIRE(DNS_ZONE_VALID(zone)); + REQUIRE(xfrp != NULL && *xfrp == NULL); + + if (zone->zmgr == NULL) { + return (ISC_R_NOTFOUND); + } + + RWLOCK(&zone->zmgr->rwlock, isc_rwlocktype_read); + LOCK_ZONE(zone); + if (zone->xfr != NULL) { + dns_xfrin_attach(zone->xfr, xfrp); + } + if (zone->statelist == &zone->zmgr->xfrin_in_progress) { + *is_running = true; + *is_deferred = false; + *is_pending = false; + } else if (zone->statelist == &zone->zmgr->waiting_for_xfrin) { + *is_running = false; + *is_deferred = true; + *is_pending = false; + } else if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_REFRESH)) { + *is_running = false; + *is_deferred = false; + *is_pending = true; + } else { + *is_running = false; + *is_deferred = false; + *is_pending = false; + } + *needs_refresh = DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDREFRESH); + UNLOCK_ZONE(zone); + RWUNLOCK(&zone->zmgr->rwlock, isc_rwlocktype_read); + + return (ISC_R_SUCCESS); +} + void dns_zone_lock_keyfiles(dns_zone_t *zone) { REQUIRE(DNS_ZONE_VALID(zone));