]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Implement dns_zone_getxfr()
authorAram Sargsyan <aram@isc.org>
Tue, 30 May 2023 14:39:02 +0000 (14:39 +0000)
committerAram Sargsyan <aram@isc.org>
Fri, 22 Sep 2023 08:51:45 +0000 (08:51 +0000)
The function is needed to get an attached xfrin and its current
state in statschannel.c for providing xfrin information in the
statistics channel.

lib/dns/include/dns/zone.h
lib/dns/zone.c

index b7084676db6944d745a4f820b710bf23bf0e5ed0..233793cc2448c700f04fc75b2b3b21ac143b0fec 100644 (file)
@@ -35,6 +35,7 @@
 #include <dns/rdatastruct.h>
 #include <dns/rpz.h>
 #include <dns/types.h>
+#include <dns/xfrin.h>
 #include <dns/zt.h>
 
 /* 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);
index 9a87540586d490e6cac307dcb4da025b3415f8cb..8e9c4ca5d664b0d14679f74d60c124eb852edaee 100644 (file)
@@ -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));