[Git][NTPsec/ntpsec][master] Fix NTPsec not declaring itself out of sync

Hal Murray (@hal.murray) gitlab at mg.gitlab.com
Sat Jun 28 10:00:05 UTC 2025



Hal Murray pushed to branch master at NTPsec / ntpsec


Commits:
117b47ba by rszymanski at 2025-06-28T02:57:07-07:00
Fix NTPsec not declaring itself out of sync

This is a port of the fix for bug 3644 from NTP project.
https://bugs.ntp.org/show_bug.cgi?id=3646

Fixes #856.

- - - - -


2 changed files:

- ntpd/ntp_proto.c
- ntpd/ntp_timer.c


Changes:

=====================================
ntpd/ntp_proto.c
=====================================
@@ -2055,8 +2055,7 @@ clock_select(void)
 	 */
 	if (typesystem == NULL) {
 		if (osys_peer != NULL) {
-			if (sys_orphwait > 0)
-			    orphwait = current_time + (unsigned long)sys_orphwait;
+			orphwait = current_time + (unsigned long)sys_orphwait;
 			report_event(EVNT_NOPEER, NULL, NULL);
 		}
 		sys_vars.sys_peer = NULL;
@@ -2839,7 +2838,7 @@ proto_config(
 
 	case PROTO_ORPHWAIT:	/* orphan wait (orphwait) */
 		orphwait -= (unsigned long)sys_orphwait;
-		sys_orphwait = (int)dvalue;
+		sys_orphwait = (dvalue >= 1) ? (int)dvalue : NTP_ORPHWAIT;
 		orphwait += (unsigned long)sys_orphwait;
 		break;
 


=====================================
ntpd/ntp_timer.c
=====================================
@@ -222,13 +222,28 @@ timer(void)
 	 * than the orphan stratum are available. A server with no other
 	 * synchronization source is an orphan. It shows offset zero and
 	 * reference ID the loopback address.
+	 *
+	 * [bug 3644] If the orphan stratum is >= STRATUM_UNSPEC, we
+	 * have to do it a bit different. 'clock_select()' simply
+	 * tiptoed home, but since we're unsync'd and have no peer, we
+	 * should eventually declare we're out of sync. Otherwise we
+	 * would persistently claim we're good, and we're everything but
+	 * that...
 	 */
-	if (sys_orphan < STRATUM_UNSPEC && sys_vars.sys_peer == NULL &&
-	    current_time > orphwait) {
-		if (sys_vars.sys_leap == LEAP_NOTINSYNC) {
-			set_sys_leap(LEAP_NOWARNING);
+	if (sys_vars.sys_peer == NULL && current_time > orphwait) {
+		if (sys_orphan < STRATUM_UNSPEC) {
+			if (sys_vars.sys_leap == LEAP_NOTINSYNC) {
+				set_sys_leap(LEAP_NOWARNING);
+			}
+			sys_vars.sys_stratum = (uint8_t)sys_orphan;
+		}
+		else {
+			if (sys_vars.sys_leap != LEAP_NOTINSYNC) {
+				set_sys_leap(LEAP_NOTINSYNC);
+				msyslog(LOG_WARNING, "no peer for too long, server running free now");
+			}
+			sys_vars.sys_stratum = STRATUM_UNSPEC;
 		}
-		sys_vars.sys_stratum = (uint8_t)sys_orphan;
 		if (sys_vars.sys_stratum > 1)
 			sys_vars.sys_refid = htonl(LOOPBACKADR);
 		else



View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/117b47bacd88aa00dee1c0367b0767fbcb4ef378

-- 
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/-/commit/117b47bacd88aa00dee1c0367b0767fbcb4ef378
You're receiving this email because of your account on gitlab.com.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20250628/ce8d01ad/attachment-0003.htm>


More information about the vc mailing list