From 858ee40105ad145ebf5fcdd50d59562fd8b287c7 Mon Sep 17 00:00:00 2001 From: Juergen Perlinger Date: Sun, 31 May 2020 11:13:45 +0200 Subject: [PATCH] [Bug 3644] Unsynchronized server (minsane not satisfied) selected as candidate bk: 5ed37549ehF1pCNIS3ebj4MQteJUwQ --- ChangeLog | 3 +++ include/ntp.h | 2 +- ntpd/ntp_proto.c | 5 ++--- ntpd/ntp_timer.c | 33 ++++++++++++++++++++++++--------- 4 files changed, 30 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5cd773531..9ae09a309 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +--- +* [Bug 3644] Unsynchronized server [...] selected as candidate + --- (4.2.8p15) 2020/04/xx Released by Harlan Stenn diff --git a/include/ntp.h b/include/ntp.h index 97f0d5f9e..8e0ea2b20 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -128,7 +128,7 @@ typedef char s_char; #define MAX_TTL 8 /* max ttl mapping vector size */ #define BEACON 7200 /* manycast beacon interval */ #define NTP_MAXEXTEN 2048 /* max extension field size */ -#define NTP_ORPHWAIT 300 /* orphan wair (s) */ +#define NTP_ORPHWAIT 300 /* orphan wait (s) */ /* * Miscellaneous stuff diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index a7543f78b..352882b97 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -3972,8 +3972,7 @@ clock_select(void) */ if (typesystem == NULL) { if (osys_peer != NULL) { - if (sys_orphwait > 0) - orphwait = current_time + sys_orphwait; + orphwait = current_time + sys_orphwait; report_event(EVNT_NOPEER, NULL, NULL); } sys_peer = NULL; @@ -5367,7 +5366,7 @@ proto_config( case PROTO_ORPHWAIT: /* orphan wait (orphwait) */ orphwait -= sys_orphwait; - sys_orphwait = (int)dvalue; + sys_orphwait = (dvalue >= 1) ? (int)dvalue : NTP_ORPHWAIT; orphwait += sys_orphwait; break; diff --git a/ntpd/ntp_timer.c b/ntpd/ntp_timer.c index 9725b5bda..42088e16e 100644 --- a/ntpd/ntp_timer.c +++ b/ntpd/ntp_timer.c @@ -350,21 +350,36 @@ 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_peer == NULL && - current_time > orphwait) { - if (sys_leap == LEAP_NOTINSYNC) { - set_sys_leap(LEAP_NOWARNING); + if (sys_peer == NULL && current_time > orphwait) { + if (sys_orphan < STRATUM_UNSPEC) { + if (sys_leap == LEAP_NOTINSYNC) { + set_sys_leap(LEAP_NOWARNING); #ifdef AUTOKEY - if (crypto_flags) - crypto_update(); + if (crypto_flags) + crypto_update(); #endif /* AUTOKEY */ + } + sys_stratum = (u_char)sys_orphan; + } else { + if (sys_leap != LEAP_NOTINSYNC) { + set_sys_leap(LEAP_NOTINSYNC); + msyslog(LOG_WARNING, "%s", + "no peer for too long, server running free now"); + } + sys_stratum = STRATUM_UNSPEC; } - sys_stratum = (u_char)sys_orphan; if (sys_stratum > 1) - sys_refid = htonl(LOOPBACKADR); + sys_refid = htonl(LOOPBACKADR); else - memcpy(&sys_refid, "LOOP", 4); + memcpy(&sys_refid, "LOOP", 4); sys_offset = 0; sys_rootdelay = 0; sys_rootdisp = 0; -- 2.47.3