Commit e3023b9936 for bind

commit e3023b99365760aae8118fbb0a62e40c7cba4703
Author: Matthijs Mekking <matthijs@isc.org>
Date:   Fri Oct 2 16:25:37 2026 +0200

    Add notify-defer and notify-delay for NOTIFY(CDS)

    Generalized DNS notifications now support notify-defer and notify-delay.
    Implement the logic for NOTIFY(CDS).

diff --git a/doc/arm/reference.rst b/doc/arm/reference.rst
index 2d65fac94c..ea4c2e5166 100644
--- a/doc/arm/reference.rst
+++ b/doc/arm/reference.rst
@@ -2134,9 +2134,6 @@ Boolean Options
     `child._dsync.example`.  In addition, the RRtype field of the record must be
     `CDS` and the Scheme field must be 1 (NOTIFY).

-    The :any:`notify-defer` and :any:`notify-delay` options are not applicable
-    to NOTIFY(CDS) messages and they are ignored for that type.
-
     The :namedconf:ref:`notify-cfg` option may also be specified in the
     :any:`zone` statement, in which case it overrides the ``options notify-cfg``
     statement. The only supported types are ``SOA`` and ``CDS``.
@@ -4578,7 +4575,7 @@ Tuning

    .. note::
       An implicit :option:`rndc notify` command for a zone overrides the
-      effects of this option.
+      effects of this option for SOA notifies.

 .. namedconf:statement:: notify-delay
    :tags: transfer, zone
diff --git a/lib/dns/zone.c b/lib/dns/zone.c
index 3d3bb36ac3..9217eb984b 100644
--- a/lib/dns/zone.c
+++ b/lib/dns/zone.c
@@ -333,7 +333,7 @@ secure_db_create_from_raw(dns_zone_t *zone, dns_db_t *rawdb, dns_db_t **dbp);
 static void
 zone_notify(dns_zone_t *zone, isc_time_t *now);
 static void
-zone_notifycds(dns_zone_t *zone);
+zone_notifycds(dns_zone_t *zone, isc_time_t *now);
 static void
 dump_done(void *arg, isc_result_t result);
 static isc_result_t
@@ -9984,7 +9984,7 @@ static void
 zone_maintenance(dns_zone_t *zone) {
 	isc_time_t now;
 	isc_result_t result;
-	bool load_pending, exiting, dumping, viewok = false, notify;
+	bool load_pending, exiting, dumping, viewok = false, notify, notifycds;
 	bool refreshkeys, rekey;
 	bool sign = false, resign = false, chain = false, warn_expire = false;
 	inline_sync_action_t inline_sync = inline_sync_none;
@@ -10069,12 +10069,15 @@ zone_maintenance(dns_zone_t *zone) {
 	 */
 	LOCK_ZONE(zone);
 	dns_notifyctx_defer(&zone->notifysoa, now);
-	notify = (zone->type == dns_zone_secondary ||
-		  zone->type == dns_zone_mirror) &&
-		 dns_notifyctx_notify_needed(&zone->notifysoa, now);
+	notify = dns_notifyctx_notify_needed(&zone->notifysoa, now);
+
+	dns_notifyctx_defer(&zone->notifycds, now);
+	notifycds = dns_notifyctx_notify_needed(&zone->notifycds, now);
 	UNLOCK_ZONE(zone);

-	if (notify) {
+	if (notify &&
+	    (zone->type == dns_zone_secondary || zone->type == dns_zone_mirror))
+	{
 		zone_notify(zone, &now);
 	}

@@ -10133,6 +10136,13 @@ zone_maintenance(dns_zone_t *zone) {
 		break;
 	}

+	/*
+	 * Do we need to send NOTIFY(CDS)?
+	 */
+	if (notifycds) {
+		zone_notifycds(zone, &now);
+	}
+
 	LOCK_ZONE(zone);
 	inline_sync = zone_inline_sync_action(zone);
 	UNLOCK_ZONE(zone);
@@ -13272,6 +13282,12 @@ zone_shutdown(void *arg) {
 	}
 }

+static bool
+notify_needed(dns_notifyctx_t *nctx) {
+	return dns_notifyctx_hasflag(nctx, DNS_NOTIFY_NEEDSEND) ||
+	       dns_notifyctx_hasflag(nctx, DNS_NOTIFY_NEEDSTARTUP);
+}
+
 static void
 zone_timer(void *arg) {
 	dns_zone_t *zone = (dns_zone_t *)arg;
@@ -13334,13 +13350,12 @@ zone__settimer(void *arg) {
 		}
 		FALLTHROUGH;
 	case dns_zone_primary:
-		if (dns_notifyctx_hasflag(&zone->notifysoa,
-					  DNS_NOTIFY_NEEDSEND) ||
-		    dns_notifyctx_hasflag(&zone->notifysoa,
-					  DNS_NOTIFY_NEEDSTARTUP))
-		{
+		if (notify_needed(&zone->notifysoa)) {
 			next = zone->notifysoa.notifytime;
 		}
+		if (notify_needed(&zone->notifycds)) {
+			next = time_min(next, zone->notifycds.notifytime);
+		}
 		if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP) &&
 		    !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING))
 		{
@@ -13368,13 +13383,12 @@ zone__settimer(void *arg) {
 	case dns_zone_secondary:
 	case dns_zone_mirror:
 	treat_as_secondary:
-		if (dns_notifyctx_hasflag(&zone->notifysoa,
-					  DNS_NOTIFY_NEEDSEND) ||
-		    dns_notifyctx_hasflag(&zone->notifysoa,
-					  DNS_NOTIFY_NEEDSTARTUP))
-		{
+		if (notify_needed(&zone->notifysoa)) {
 			next = zone->notifysoa.notifytime;
 		}
+		if (notify_needed(&zone->notifycds)) {
+			next = time_min(next, zone->notifycds.notifytime);
+		}
 		FALLTHROUGH;
 	case dns_zone_stub:
 		if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_REFRESH) &&
@@ -18455,9 +18469,26 @@ done:
 }

 static void
-zone_notifycds(dns_zone_t *zone) {
+zone_notifycds(dns_zone_t *zone, isc_time_t *now) {
 	dns_notifytype_t notifytype = zone->notifycds.notifytype;

+	ENTER;
+
+	LOCK_ZONE(zone);
+	dns_notifyctx_clearflag(&zone->notifycds,
+				DNS_NOTIFY_NEEDSEND | DNS_NOTIFY_NEEDSTARTUP |
+					DNS_NOTIFY_NODEFER |
+					DNS_NOTIFY_DEFERRED);
+	DNS_ZONE_TIME_ADD(now, zone->notifycds.notifydelay,
+			  &zone->notifycds.notifytime);
+	UNLOCK_ZONE(zone);
+
+	if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING) ||
+	    !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED))
+	{
+		return;
+	}
+
 	if (notifytype == dns_notifytype_no) {
 		return;
 	}
@@ -19392,10 +19423,12 @@ zone_rekey(dns_zone_t *zone) {
 	}

 	/*
-	 * If the CDS/CDNSKEY RRset has changed, send NOTIFY(CDS) to endpoints.
+	 * If the CDS/CDNSKEY RRset has changed, send NOTIFY(CDS)
+	 * to endpoints.
 	 */
 	if (notifycds) {
-		zone_notifycds(zone);
+		dns_notifyctx_setflag(&zone->notifycds,
+				      DNS_NOTIFY_NEEDSEND);
 	}

 	result = ISC_R_SUCCESS;