]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3646] Avoid sync with unsync orphan
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 5 Apr 2020 08:10:12 +0000 (10:10 +0200)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 5 Apr 2020 08:10:12 +0000 (10:10 +0200)
bk: 5e899264Q-E6lY8_HHNxues2Ptu6Kg

ChangeLog
ntpd/ntp_proto.c

index 35d5d36c2faf434a0bbc79ed85afe3473cc63039..a90ba834a6c02493d4da7bdcd703104d114d8a07 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+---
+* [Bug 3646] Avoid sync with unsync orphan <perlinger@ntp.org>
+  - patch by Gerry Garvey
+
 ---
 (4.2.8p14) 2020/03/03 Released by Harlan Stenn <stenn@ntp.org>
 
index 33e97ef9d9893a2108bff8304b4b8c4fbfee529c..b95670577c9e345c56b3848a507b2f6014655c7c 100644 (file)
@@ -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;
                }
        }