From: Juergen Perlinger Date: Sun, 5 Apr 2020 08:10:12 +0000 (+0200) Subject: [Bug 3646] Avoid sync with unsync orphan X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=650919e3c588d6653af3b06a0347787484b5fc5f;p=thirdparty%2Fntp.git [Bug 3646] Avoid sync with unsync orphan bk: 5e899264Q-E6lY8_HHNxues2Ptu6Kg --- diff --git a/ChangeLog b/ChangeLog index 35d5d36c2..a90ba834a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +--- +* [Bug 3646] Avoid sync with unsync orphan + - patch by Gerry Garvey + --- (4.2.8p14) 2020/03/03 Released by Harlan Stenn diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 33e97ef9d..b95670577 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -3455,11 +3455,13 @@ clock_select(void) double d, e, f, g; double high, low; double speermet; + double lastresort_dist = MAXDISPERSE; double orphmet = 2.0 * U_INT32_MAX; /* 2x is greater than */ struct endpoint endp; struct peer *osys_peer; struct peer *sys_prefer = NULL; /* prefer peer */ struct peer *typesystem = NULL; + struct peer *typelastresort = NULL; struct peer *typeorphan = NULL; #ifdef REFCLOCK struct peer *typeacts = NULL; @@ -3523,6 +3525,22 @@ clock_select(void) continue; } + /* + * If we have never been synchronised, look for any peer + * which has ever been synchronised and pick the one which + * has the lowest root distance. This can be used as a last + * resort if all else fails. Once we get an initial sync + * with this peer, sys_reftime gets set and so this + * function becomes disabled. + */ + if (L_ISZERO(&sys_reftime)) { + d = root_distance(peer); + if (!L_ISZERO(&peer->reftime) && d < lastresort_dist) { + typelastresort = peer; + lastresort_dist = d; + } + } + /* * If this peer is an orphan parent, elect the * one with the lowest metric defined as the @@ -3756,6 +3774,9 @@ clock_select(void) if (typeorphan != NULL) { peers[0].peer = typeorphan; nlist = 1; + } else if (typelastresort != NULL) { + peers[0].peer = typelastresort; + nlist = 1; } }