]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
Changes from Dave Mills
authorHarlan Stenn <stenn@ntp.org>
Mon, 18 Apr 2005 05:01:32 +0000 (01:01 -0400)
committerHarlan Stenn <stenn@ntp.org>
Mon, 18 Apr 2005 05:01:32 +0000 (01:01 -0400)
bk: 42633f2c1pwYi_XG_55o_849Jna3ng

include/ntp.h
include/ntp_control.h
ntpd/ntp_control.c
ntpd/ntp_peer.c
ntpd/ntp_proto.c

index 588fcdf3c9fc69f5a0dcbb97e3304ba7724214a7..9167bd47511c4cbe482c16c5427a00878110fce4 100644 (file)
@@ -226,6 +226,7 @@ struct interface {
 #define        TEST11          0x0400  /* peer distance exceeded */
 #define TEST12         0x0800  /* peer synchronization loop */
 #define TEST13         0x1000  /* peer unfit for synchronization */
+#define        TEST14          0x2000  /* peer stratum out of bounds */
 
 /*
  * Authentication codes
@@ -364,9 +365,8 @@ struct peer {
        u_long  badauth;        /* packets cryptosum failed */
        u_long  bogusorg;       /* packets bogus origin */
        u_long  oldpkt;         /* packets duplicate packet */
-       u_long  seldisptoolarge; /* packets dispersion to large*/
+       u_long  seldisptoolarge; /* packets dispersion too large */
        u_long  selbroken;      /* not used */
-       u_long  rank;   /* number of times selected or in cluster */
 };
 
 /*
index 86f38100e17fdbf2218cd98d05c83db3980e3230..2d225c954f1c8ba3bb778e38e5b63c0e151b2903 100644 (file)
@@ -218,17 +218,16 @@ struct ntp_control {
 #define        CP_FILTERROR    34
 #define        CP_FLASH        35
 #define CP_TTL         36
-#define        CP_RANK         37
-#define CP_VARLIST     38
+#define CP_VARLIST     37
 #ifdef OPENSSL
-#define CP_FLAGS       39
-#define CP_HOST                40
-#define CP_VALID       41
-#define        CP_INITSEQ      42
-#define        CP_INITKEY      43
-#define        CP_INITTSP      44
-#define        CP_DIGEST       45
-#define CP_IDENT       46
+#define CP_FLAGS       38
+#define CP_HOST                39
+#define CP_VALID       40
+#define        CP_INITSEQ      41
+#define        CP_INITKEY      42
+#define        CP_INITTSP      43
+#define        CP_DIGEST       44
+#define CP_IDENT       45
 #define        CP_MAXCODE      CP_IDENT
 #else
 #define        CP_MAXCODE      CP_VARLIST
index fbe9ff4601f6c26f8050043c1c22485c22abc0cd..5fd54a3e2279f97f68d2515c3f782cc8deb03864 100644 (file)
@@ -206,19 +206,18 @@ static struct ctl_var peer_var[] = {
        { CP_FILTERROR, RO, "filtdisp=" },      /* 34 */
        { CP_FLASH,     RO, "flash" },          /* 35 */
        { CP_TTL,       RO, "ttl" },            /* 36 */
-       { CP_RANK,      RO, "rank" },           /* 37 */
-       { CP_VARLIST,   RO, "peer_var_list" },  /* 38 */
+       { CP_VARLIST,   RO, "peer_var_list" },  /* 37 */
 #ifdef OPENSSL
-       { CP_FLAGS,     RO, "flags" },          /* 39 */
-       { CP_HOST,      RO, "hostname" },       /* 40 */
-       { CP_VALID,     RO, "valid" },          /* 41 */
-       { CP_INITSEQ,   RO, "initsequence" },   /* 42 */
-       { CP_INITKEY,   RO, "initkey" },        /* 43 */
-       { CP_INITTSP,   RO, "timestamp" },      /* 44 */
-       { CP_DIGEST,    RO, "signature" },      /* 45 */
-       { CP_IDENT,     RO, "identity" },       /* 46 */
+       { CP_FLAGS,     RO, "flags" },          /* 38 */
+       { CP_HOST,      RO, "hostname" },       /* 39 */
+       { CP_VALID,     RO, "valid" },          /* 40 */
+       { CP_INITSEQ,   RO, "initsequence" },   /* 41 */
+       { CP_INITKEY,   RO, "initkey" },        /* 42 */
+       { CP_INITTSP,   RO, "timestamp" },      /* 43 */
+       { CP_DIGEST,    RO, "signature" },      /* 44 */
+       { CP_IDENT,     RO, "identity" },       /* 45 */
 #endif /* OPENSSL */
-       { 0,            EOV, "" }               /* 39/47 */
+       { 0,            EOV, "" }               /* 38/46 */
 };
 
 
@@ -1543,10 +1542,6 @@ ctl_putpeer(
                ctl_putuint(peer_var[CP_UNREACH].text, peer->unreach);
                break;
 
-       case CP_RANK:
-               ctl_putuint(peer_var[CP_RANK].text, peer->rank);
-               break;
-
        case CP_TIMER:
                ctl_putuint(peer_var[CP_TIMER].text,
                    peer->nextdate - current_time);
index 154626a97f03ee48053446498d5bc883b4156b1a..7afd65ad732cf3ef19e7c90a9f10e8cc63620e2f 100644 (file)
@@ -766,8 +766,6 @@ peer_reset(
        peer->bogusorg = 0;
        peer->oldpkt = 0;
        peer->seldisptoolarge = 0;
-       peer->selbroken = 0;
-       peer->rank = 0;
        peer->timereset = current_time;
 }
 
index 4adb761cd1843884b50a401e0970288383ab0887..1b09f264e1d69db1d4eea1cabbd85fcff6b257f8 100644 (file)
@@ -63,7 +63,7 @@ int   sys_authenticate;       /* requre authentication for config */
 l_fp   sys_authdelay;          /* authentication delay */
 static u_long sys_authdly[2];  /* authentication delay shift reg */
 static u_char leap_consensus;  /* consensus of survivor leap bits */
-static double sys_mindist = MINDISTANCE; /* selection floor (s) */
+static double sys_mindist = MINDISTANCE; /* selection threshold (s) */
 static double sys_maxdist = MAXDISTANCE; /* selection ceiling (s) */
 double sys_jitter;             /* system jitter (s) */
 keyid_t        sys_private;            /* private value for session seed */
@@ -77,8 +77,8 @@ char  *sys_hostname;          /* gethostname() name */
 /*
  * TOS and multicast mapping stuff
  */
-int    sys_floor = 1;          /* cluster stratum floor */
-int    sys_ceiling = STRATUM_UNSPEC; /* cluster stratum ceiling*/
+int    sys_floor = 0;          /* cluster stratum floor */
+int    sys_ceiling = STRATUM_UNSPEC; /* cluster stratum ceiling */
 int    sys_minsane = 1;        /* minimum candidates */
 int    sys_minclock = NTP_MINCLOCK; /* minimum survivors */
 int    sys_cohort = 0;         /* cohort switch */
@@ -1558,7 +1558,7 @@ clock_filter(
                        dst[i] = MAXDISPERSE;
                else if (peer->update - peer->filter_epoch[j] >
                    allan_xpt)
-                       dst[i] = MAXDISTANCE + peer->filter_disp[j];
+                       dst[i] = sys_maxdist + peer->filter_disp[j];
                else
                        dst[i] = peer->filter_delay[j];
                ord[i] = j;
@@ -1584,14 +1584,14 @@ clock_filter(
        /*
         * Copy the index list to the association structure so ntpq
         * can see it later. Prune the distance list to samples less
-        * than MAXDISTANCE, but keep at least two valid samples for
+        * than max distance, but keep at least two valid samples for
         * jitter calculation.
         */
        m = 0;
        for (i = 0; i < NTP_SHIFT; i++) {
                peer->filter_order[i] = (u_char) ord[i];
                if (dst[i] >= MAXDISPERSE || (m >= 2 && dst[i] >=
-                   MAXDISTANCE))
+                   sys_maxdist))
                        continue;
                m++;
        }
@@ -1951,17 +1951,12 @@ clock_select(void)
 
                /*
                 * The order metric is formed from the stratum times
-                * MAXDISTANCE (1.) plus the root distance. It strongly
+                * max distance (1.) plus the root distance. It strongly
                 * favors the lowest stratum, but a higher stratum peer
                 * can capture the clock if the low stratum dominant
                 * hasn't been heard for awhile.
                 */
-               d = peer->stratum;
-               if (d < sys_floor)
-                       d += sys_floor;
-               if (d > sys_ceiling)
-                       d = STRATUM_UNSPEC;
-               d = root_distance(peer) + d * MAXDISTANCE;
+               d = root_distance(peer) + peer->stratum * sys_maxdist;
                d *= 1. - peer->hyst;
                if (j >= NTP_MAXCLOCK) {
                        if (d >= synch[j - 1])
@@ -1972,6 +1967,7 @@ clock_select(void)
                for (k = j; k > 0; k--) {
                        if (d >= synch[k - 1])
                                break;
+
                        peer_list[k] = peer_list[k - 1];
                        error[k] = error[k - 1];
                        synch[k] = synch[k - 1];
@@ -2104,33 +2100,24 @@ clock_select(void)
         * Manycast is sooo complicated.
         */
        leap_consensus = 0;
+       typesystem = peer_list[0];
        for (i = nlist - 1; i >= 0; i--) {
                peer = peer_list[i];
                leap_consensus |= peer->leap;
                peer->status = CTL_PST_SEL_SYNCCAND;
-               peer->rank++;
-               peer->flags |= FLAG_SYSPEER;
-               if (peer->stratum >= sys_floor && osurv >= sys_minclock)
-                       peer->hyst = HYST;
-               else
-                       peer->hyst = 0;
-               if (peer->stratum <= sys_ceiling)
-                       sys_survivors++;
+               sys_survivors++;
                if (peer->flags & FLAG_PREFER)
                        sys_prefer = peer;
 #ifdef REFCLOCK
                if (peer->refclktype == REFCLK_ATOM_PPS)
                        sys_pps = peer;
 #endif /* REFCLOCK */
-
-               /*
-                * If this is the old system peer and it's stratum is
-                * the same as the head of the list, don't hop the
-                * clock.
-                */
-               if (peer == osys_peer && peer->stratum ==
-                   peer_list[0]->stratum)
-                       typesystem = peer;
+#if DEBUG
+               if (debug > 1)
+                       printf("cluster: survivor %s metric %.6f hyst %.6f\n",
+                           ntoa(&peer_list[i]->srcadr), synch[i],
+                           peer_list[i]->hyst);
+#endif
        }
 
        /*
@@ -2149,10 +2136,8 @@ clock_select(void)
         * Mitigation rules of the game. There are several types of
         * peers that can be selected here: (1) prefer peer (flag
         * FLAG_PREFER) (2) pps peers (type REFCLK_ATOM_PPS), (3) the
-        * existing system peer, if any, and (4) the head of the
-        * survivor list. Note that only one peer can be declared
-        * prefer. Note that all of these must be at the lowest stratum,
-        * i.e., the stratum of the head of the survivor list.
+        * existing system peer, if any, and (3) the head of the
+        * survivor list.
         */
        if (sys_prefer) {
 
@@ -2189,15 +2174,10 @@ clock_select(void)
        } else {
 
                /*
-                * If a system peer has been identified, choose it;
-                * otherwise choose the head of the survivor list.
+                * Otherwise, choose the head of the survivor list.
                 */ 
-               if (typesystem)
-                       sys_peer = typesystem;
-               else
-                       sys_peer = peer_list[0];
+               sys_peer = peer_list[0];
                sys_peer->status = CTL_PST_SEL_SYSPEER;
-               sys_peer->rank++;
                clock_combine(peer_list, nlist);
                sys_jitter = SQRT(SQUARE(sys_peer->jitter) +
                    SQUARE(sys_jitter));
@@ -2207,6 +2187,16 @@ clock_select(void)
                           sys_offset);
 #endif
        }
+
+       /*
+        * We have found the alpha male. Mark its scent and ding the
+        * anticlockhop hysteresis.
+        */
+       sys_peer->flags |= FLAG_SYSPEER;
+       if (osurv >= sys_minclock)
+               sys_peer->hyst = HYST;
+       else
+               sys_peer->hyst = 0;
        if (osys_peer != sys_peer) {
                char *src;
 
@@ -2831,7 +2821,8 @@ key_expire(
  * Determine if the peer is unfit for synchronization
  *
  * A peer is unfit for synchronization if
- * > unreachable or bad leap or bad stratum or noselect
+ * > unreachable or bad leap ornoselect
+ * > stratum below the floor or at or above the ceiling
  * > root distance exceeded
  * > a synchronization loop would form
  */
@@ -2842,12 +2833,15 @@ peer_unfit(
 {
        int     rval = 0;
 
-       peer->flash &= ~(TEST11 | TEST12 | TEST13);
+       peer->flash &= ~(TEST11 | TEST12 | TEST13 | TEST14);
        if (!peer->reach || peer->leap == LEAP_NOTINSYNC ||
            peer->stratum >= STRATUM_UNSPEC || peer->flags &
            FLAG_NOSELECT)
                rval |= TEST13;         /* unfit */
 
+       if (peer->stratum < sys_floor || peer->stratum >= sys_ceiling)
+               rval |= TEST14;         /* stratum out of bounds */
+
        if (root_distance(peer) >= sys_maxdist + clock_phi *
            ULOGTOD(sys_poll))
                rval |= TEST11;         /* distance exceeded */