]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Add dns_zone_getzoneversion
authorMark Andrews <marka@isc.org>
Thu, 29 Aug 2024 01:05:09 +0000 (11:05 +1000)
committerMark Andrews <marka@isc.org>
Mon, 24 Mar 2025 22:16:09 +0000 (22:16 +0000)
Returns the EDNS ZONEVERSION for the zone.  Return the database
specific version otherwise return a type 0 version (serial).

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

index b000f27e10352ceb46b5faa63e3de5ed27ae03c7..cec638fe64aa6e30120679d3f2f1b34259b0acc3 100644 (file)
@@ -2785,6 +2785,24 @@ dns_zone_getrad(dns_zone_t *zone, dns_name_t *name);
  * \li 'name' is a valid name with a buffer.
  */
 
+isc_result_t
+dns_zone_getzoneversion(dns_zone_t *zone, isc_buffer_t *b);
+/**<
+ * Return the EDNS ZONEVERSION for this zone.
+ *
+ * Note: For type SERIAL a buffer of at least 6 octets is required.
+ *
+ * Requires:
+ * \li 'zone' to be a valid zone.
+ * \li 'b' to be a valid buffer.
+ *
+ * Returns
+ * \li ISC_R_SUCCESS if the zone is loaded and supports ZONEVERSION.
+ * \li ISC_R_NOSPACE if the buffer is too small.
+ * \li DNS_R_NOTLOADED if the database is not loaded.
+ * \li ISC_R_FAILURE other failure.
+ */
+
 #if DNS_ZONE_TRACE
 #define dns_zone_ref(ptr)   dns_zone__ref(ptr, __func__, __FILE__, __LINE__)
 #define dns_zone_unref(ptr) dns_zone__unref(ptr, __func__, __FILE__, __LINE__)
index 1ec93ef51c734c0bd40ed21738b9c0e539c5ccd9..8d4c101f32d385c7556ea8cfe03f349ac676115f 100644 (file)
@@ -1497,6 +1497,46 @@ dns_zone_getserial(dns_zone_t *zone, uint32_t *serialp) {
        return result;
 }
 
+isc_result_t
+dns_zone_getzoneversion(dns_zone_t *zone, isc_buffer_t *b) {
+       isc_result_t result = DNS_R_NOTLOADED;
+       unsigned int soacount;
+       uint32_t serial;
+
+       REQUIRE(DNS_ZONE_VALID(zone));
+       REQUIRE(b != NULL);
+
+       LOCK_ZONE(zone);
+       ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read);
+       if (zone->db != NULL) {
+               result = dns_db_getzoneversion(zone->db, b);
+               if (result == ISC_R_NOTIMPLEMENTED) {
+                       result = zone_get_from_db(zone, zone->db, NULL,
+                                                 &soacount, NULL, &serial,
+                                                 NULL, NULL, NULL, NULL, NULL);
+                       if (result == ISC_R_SUCCESS && soacount == 0) {
+                               result = ISC_R_FAILURE;
+                       }
+                       if (result == ISC_R_SUCCESS) {
+                               if (isc_buffer_availablelength(b) >= 6) {
+                                       isc_buffer_putuint8(
+                                               b, dns_name_countlabels(
+                                                          &zone->origin) -
+                                                          1);
+                                       isc_buffer_putuint8(b, 0);
+                                       isc_buffer_putuint32(b, serial);
+                               } else {
+                                       result = ISC_R_NOSPACE;
+                               }
+                       }
+               }
+       }
+       ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read);
+       UNLOCK_ZONE(zone);
+
+       return result;
+}
+
 /*
  *     Single shot.
  */