Commit 2544ac0e19 for bind

commit 2544ac0e19f8c0c5c7ba44754975b1939f1d10ed
Author: Matthijs Mekking <matthijs@isc.org>
Date:   Fri Oct 2 10:38:09 2026 +0200

    Move notify defer code to notify.c file

    Introduce functions that the zone can access to defer sending out the
    notifies, and check whether it is time to send out notifies.

diff --git a/lib/dns/include/dns/notify.h b/lib/dns/include/dns/notify.h
index 570b2068d7..3832792556 100644
--- a/lib/dns/include/dns/notify.h
+++ b/lib/dns/include/dns/notify.h
@@ -187,3 +187,26 @@ dns_notifyctx_hasflag(dns_notifyctx_t *nctx, unsigned int flag);
  *		true if the flag is set
  *		false otherwise
  */
+
+void
+dns_notifyctx_defer(dns_notifyctx_t *nctx, isc_time_t now);
+/*%<
+ *	Defer a notify. The corresponding zone must be locked.
+ *
+ *	Requires:
+ *		'nctx' is not NULL
+ */
+
+bool
+dns_notifyctx_notify_needed(dns_notifyctx_t *nctx, isc_time_t now);
+/*%<
+ *	Returns if it is time to send out notifies. If the NEEDSEND or
+ *	NEEDSTARTUP flag is set, and the notifytime is in the past,
+ *	then it is time to do the notifies.
+ *
+ *	Requires:
+ *		'nctx' is not NULL
+ *      Returns:
+ *		true if we need to send out notifies
+ *		false otherwise
+ */
diff --git a/lib/dns/notify.c b/lib/dns/notify.c
index 57da082a5d..c57f6e7c2f 100644
--- a/lib/dns/notify.c
+++ b/lib/dns/notify.c
@@ -39,6 +39,16 @@
 #define NOTIFY_SETFLAG(n, f) atomic_fetch_or(&(n)->flags, (f))
 #define NOTIFY_CLRFLAG(n, f) atomic_fetch_and(&(n)->flags, ~(f))

+#define TIME_ADD(a, b, c)                                           \
+	do {                                                        \
+		isc_interval_t _i;                                  \
+		isc_interval_set(&_i, (b), 0);                      \
+		if (isc_time_add((a), &_i, (c)) != ISC_R_SUCCESS) { \
+			isc_interval_set(&_i, (b) / 2, 0);          \
+			(void)isc_time_add((a), &_i, (c));          \
+		}                                                   \
+	} while (0)
+
 static void
 notify_log(dns_notify_t *notify, int level, const char *fmt, ...) {
 	va_list ap;
@@ -825,3 +835,29 @@ dns_notifyctx_hasflag(dns_notifyctx_t *nctx, unsigned int flag) {
 	REQUIRE(nctx != NULL);
 	return NOTIFY_FLAG(nctx, flag);
 }
+
+void
+dns_notifyctx_defer(dns_notifyctx_t *nctx, isc_time_t now) {
+	REQUIRE(nctx != NULL);
+
+	if (nctx->notifydefer != 0 &&
+	    !dns_notifyctx_hasflag(nctx, DNS_NOTIFY_NODEFER) &&
+	    !dns_notifyctx_hasflag(nctx, DNS_NOTIFY_DEFERRED))
+	{
+		if (isc_time_compare(&now, &nctx->notifytime) > 0) {
+			nctx->notifytime = now;
+		}
+		dns_notifyctx_setflag(nctx, DNS_NOTIFY_DEFERRED);
+		TIME_ADD(&nctx->notifytime, nctx->notifydefer,
+			 &nctx->notifytime);
+	}
+}
+
+bool
+dns_notifyctx_notify_needed(dns_notifyctx_t *nctx, isc_time_t now) {
+	REQUIRE(nctx != NULL);
+
+	return (dns_notifyctx_hasflag(nctx, DNS_NOTIFY_NEEDSEND) ||
+		dns_notifyctx_hasflag(nctx, DNS_NOTIFY_NEEDSTARTUP)) &&
+	       isc_time_compare(&now, &nctx->notifytime) >= 0;
+}
diff --git a/lib/dns/zone.c b/lib/dns/zone.c
index 397e03147e..3d3bb36ac3 100644
--- a/lib/dns/zone.c
+++ b/lib/dns/zone.c
@@ -10068,25 +10068,10 @@ zone_maintenance(dns_zone_t *zone) {
 	 * primaries after.
 	 */
 	LOCK_ZONE(zone);
-	if (zone->notifysoa.notifydefer != 0 &&
-	    !dns_notifyctx_hasflag(&zone->notifysoa, DNS_NOTIFY_NODEFER) &&
-	    !dns_notifyctx_hasflag(&zone->notifysoa, DNS_NOTIFY_DEFERRRED))
-	{
-		if (isc_time_compare(&now, &zone->notifysoa.notifytime) > 0) {
-			zone->notifysoa.notifytime = now;
-		}
-		dns_notifyctx_setflag(&zone->notifysoa, DNS_NOTIFY_DEFERRED);
-		DNS_ZONE_TIME_ADD(&zone->notifysoa.notifytime,
-				  zone->notifysoa.notifydefer,
-				  &zone->notifysoa.notifytime);
-	}
-	notify =
-		(zone->type == dns_zone_secondary ||
-		 zone->type == dns_zone_mirror) &&
-		(dns_notifyctx_hasflag(&zone->notifysoa, DNS_NOTIFY_NEEDSEND) ||
-		 dns_notifyctx_hasflag(&zone->notifysoa,
-				       DNS_NOTIFY_NEEDSTARTUP)) &&
-		isc_time_compare(&now, &zone->notifysoa.notifytime) >= 0;
+	dns_notifyctx_defer(&zone->notifysoa, now);
+	notify = (zone->type == dns_zone_secondary ||
+		  zone->type == dns_zone_mirror) &&
+		 dns_notifyctx_notify_needed(&zone->notifysoa, now);
 	UNLOCK_ZONE(zone);

 	if (notify) {