]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
fixes from Dave Mills
authorHarlan Stenn <stenn@ntp.org>
Tue, 4 Oct 2005 06:52:27 +0000 (02:52 -0400)
committerHarlan Stenn <stenn@ntp.org>
Tue, 4 Oct 2005 06:52:27 +0000 (02:52 -0400)
bk: 434226abVqAO9zPmWPdoV_oZYWKN3A

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

index ed9dcb62b56d8c08678ec2162ffaf5511363ba89..0543674b1a49c093bcc99e5f9160fb250a9348bd 100644 (file)
@@ -219,7 +219,8 @@ struct interface {
 #define TEST7          0x0040  /* bad header data */
 #define TEST8          0x0080  /* autokey error */
 #define TEST9          0x0100  /* crypto error */
-
+#define        PKT_TEST_MASK   (TEST1 | TEST2 | TEST3 | TEST4 | TEST5 |\
+                       TEST6 | TEST7 | TEST8 | TEST9)
 /*
  * Peer errors
  */
@@ -227,6 +228,7 @@ struct interface {
 #define        TEST11          0x0400  /* peer distance exceeded */
 #define TEST12         0x0800  /* peer synchronization loop */
 #define TEST13         0x1000  /* peer unreacable */
+#define        PEER_TEST_MASK  (TEST10 | TEST11 | TEST12 | TEST13)
 
 /*
  * Authentication codes
index 9baa9ff7ca2adee2df16db65df8be278c9eff20f..980a6845268fbbaa033f84da3fa677339faee0cf 100644 (file)
@@ -164,7 +164,6 @@ extern      void    peer_clear      P((struct peer *, char *));
 extern void    process_packet  P((struct peer *, struct pkt *));
 extern void    clock_select    P((void));
 extern void    kod_proto       P((void));
-extern int     peer_unfit      P((struct peer *));
 
 /*
  * there seems to be a bug in the IRIX 4 compiler which prevents
index 0e6fb706b52effcbd3f75e70e46508a1a3735b95..71c19d8445671e289ccb2b87dcf6bba561a32b98 100644 (file)
@@ -1583,7 +1583,7 @@ ctl_putpeer(
                break;
 
        case CP_FLASH:
-               temp = peer->flash | peer_unfit(peer);
+               temp = peer->flash;
                ctl_puthex(peer_var[CP_FLASH].text, temp);
                break;
 
index 4789021d1160bc9d2499f63aeaafd965e42e4654..4daf2efd297665aee0f627d745b11bf8176a2ae5 100644 (file)
@@ -1,4 +1,4 @@
-y/*
+/*
  * ntp_proto.c - NTP version 4 protocol machinery
  *
  * ATTENTION: Get approval from Dave Mills on all changes to this file!
@@ -111,6 +111,7 @@ static      void    fast_xmit       P((struct recvbuf *, int, keyid_t,
                                    int));
 static void    clock_update    P((void));
 static int     default_get_precision   P((void));
+static int     peer_unfit      P((struct peer *));
 
 
 /*
@@ -895,7 +896,7 @@ receive(
        default:
                return;
        }
-       peer->flash = 0;
+       peer->flash &= ~PKT_TEST_MASK;
 
        /*
         * Next comes a rigorous schedule of timestamp checking. If the
@@ -932,7 +933,7 @@ receive(
         */
        peer->org = p_xmt;
        peer->rec = rbufp->recv_time;
-       if (peer->flash) {
+       if (peer->flash & PKT_TEST_MASK) {
 #ifdef OPENSSL
                if (crypto_flags && (peer->flags & FLAG_SKEY)) {
                        rval = crypto_recv(peer, rbufp);
@@ -1143,7 +1144,7 @@ process_packet(
         * Note that some flashers may have already been set in the
         * receive() routine.
         */
-       if (peer->flash) {
+       if (peer->flash & PKT_TEST_MASK) {
 #ifdef DEBUG
                if (debug)
                        printf("packet: flash header %04x\n",
@@ -1292,11 +1293,8 @@ clock_update(void)
         */
        case 1:
                sys_leap = leap_next;
-               sys_stratum = sys_peer->stratum + 1;
-               if (sys_stratum == 1 || sys_stratum == STRATUM_UNSPEC)
-                       sys_refid = sys_peer->refid;
-               else
-                       sys_refid = addr2refid(&sys_peer->srcadr);
+               sys_stratum = min(sys_peer->stratum + 1,
+                   STRATUM_UNSPEC);
                sys_reftime = sys_peer->rec;
 
                /*
@@ -1970,7 +1968,7 @@ clock_select(void)
         * Clustering algorithm. Construct candidate list in order first
         * by stratum then by root distance, but keep only the best
         * NTP_MAXASSOC of them. Scan the list to find falsetickers, who
-        * leave the island immediately. The TRUE peer is alwasy a
+        * leave the island immediately. The TRUE peer is always a
         * truechimer. We must leave at least one peer to collect the
         * million bucks. If in orphan mode, rascals found with lower
         * stratum are guaranteed a seat on the bus.
@@ -2114,10 +2112,6 @@ clock_select(void)
         * stratum. Note that the head of the list is at the lowest
         * stratum and that unsynchronized peers cannot survive this
         * far.
-        *
-        * In orphan mode the prefer peer is determined as the minimum
-        * root delay of the available peers. In normal mode the prefer
-        * peer is designated in the configuration file.
         */
        leap_next = 0;
        for (i = 0; i < nlist; i++) {
@@ -2155,12 +2149,33 @@ 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 (3) the head of the
+        * peers that can be selected here: (1) orphan, (2) prefer peer
+        * (flag FLAG_PREFER) (3) pps peers (type REFCLK_ATOM_PPS), (4)
+        * the existing system peer, if any, and (5) the head of the
         * survivor list.
         */
-       if (sys_prefer) {
+       if (typesystem->stratum >= sys_orphan) {
+
+               /*
+                * If in orphan mode, choose the system peer. If the
+                * lowest distance, the offset is zero.
+                */
+               sys_peer = typesystem;
+               sys_peer->status = CTL_PST_SEL_SYSPEER;
+               if (sys_orphandelay < sys_peer->rootdelay) {
+                       sys_offset = 0;
+                       sys_refid = htonl(LOOPBACKADR);
+               } else {
+                       sys_offset = sys_peer->offset;
+                       sys_refid = sys_peer->refid;
+               }
+               sys_jitter = LOGTOD(sys_precision);
+#ifdef DEBUG
+               if (debug > 1)
+                       printf("select: orphan offset %.6f\n",
+                           sys_offset);
+#endif
+       } else if (sys_prefer) {
 
                /*
                 * If a pps peer is present, choose it; otherwise,
@@ -2170,7 +2185,6 @@ clock_select(void)
                        sys_peer = sys_pps;
                        sys_peer->status = CTL_PST_SEL_PPS;
                        sys_offset = sys_peer->offset;
-                       sys_jitter = sys_peer->jitter;
                        if (!pps_control)
                                NLOG(NLOG_SYSEVENT)
                                    msyslog(LOG_INFO,
@@ -2184,18 +2198,19 @@ clock_select(void)
                } else {
                        sys_peer = sys_prefer;
                        sys_peer->status = CTL_PST_SEL_SYSPEER;
-                       if (peer->stratum >= sys_orphan &&
-                           sys_orphandelay < sys_peer->rootdelay)
-                               sys_offset = 0;
-                       else
-                               sys_offset = sys_peer->offset;
-                       sys_jitter = sys_peer->jitter;
+                       sys_offset = sys_peer->offset;
 #ifdef DEBUG
                        if (debug > 1)
                                printf("select: prefer offset %.6f\n",
                                    sys_offset);
 #endif
                }
+               if (sys_peer->stratum == STRATUM_REFCLOCK ||
+                   sys_peer->stratum == STRATUM_UNSPEC)
+                       sys_refid = sys_peer->refid;
+               else
+                       sys_refid = addr2refid(&sys_peer->srcadr);
+               sys_jitter = sys_peer->jitter;
        } else {
 
                /*
@@ -2204,6 +2219,11 @@ clock_select(void)
                sys_peer = typesystem;
                sys_peer->status = CTL_PST_SEL_SYSPEER;
                clock_combine(peer_list, nlist);
+               if (sys_stratum == STRATUM_REFCLOCK || sys_stratum ==
+                   STRATUM_UNSPEC)
+                       sys_refid = sys_peer->refid;
+               else
+                       sys_refid = addr2refid(&sys_peer->srcadr);
                sys_jitter = SQRT(SQUARE(sys_peer->jitter) +
                    SQUARE(sys_jitter));
 #ifdef DEBUG
@@ -2876,7 +2896,7 @@ key_expire(
  * A peer is unfit for synchronization if
  * > TEST10 bad leap or stratum below floor or at or above ceiling
  * > TEST11 root distance exceeded
- * > TEST12 a direct or indirect synchronization loop would form
+ * > TEST12 a direct synchronization loop would form
  * > TEST13 unreachable or noselect
  */
 int                            /* FALSE if fit, TRUE if unfit */
@@ -2895,14 +2915,14 @@ peer_unfit(
            ULOGTOD(sys_poll))
                rval |= TEST11;         /* distance exceeded */
 
-       if (peer->stratum > 1 && (peer->refid ==
-           peer->dstadr->addr_refid || peer->refid == sys_refid))
+       if (peer->stratum > 1 && peer->refid ==
+           peer->dstadr->addr_refid)
                rval |= TEST12;         /* synch loop */
 
        if (!peer->reach || peer->flags & FLAG_NOSELECT)
                rval |= TEST13;         /* unreachable */
 
-       peer->flash &= ~(TEST10 | TEST11 | TEST12 | TEST13);
+       peer->flash &= ~PEER_TEST_MASK;
        peer->flash |= rval;
        return (rval);
 }
index 3478f43838e6f0552b7bac39a8c6709b245cbee3..3d4d1dd6bc6d51f1120674866a856611f6d77489 100644 (file)
@@ -72,7 +72,7 @@
  *
  * The stratum for this driver set at 5 by default, but it can be
  * changed by the fudge command and/or the ntpdc utility. The reference
- * ID is "LCL" by default, but can be changed using the same mechanism.
+ * ID is 127.0.0.1 by default, but can be changed using the same mechanism.
  * *NEVER* configure this driver to operate at a stratum which might
  * possibly disrupt a client with access to a bona fide primary server,
  * unless the local clock oscillator is reliably disciplined by another
  * Local interface definitions
  */
 #define PRECISION      (-7)    /* about 10 ms precision */
-#if defined(VMS) && defined(VMS_LOCALUNIT)
-#define REFID          "LCLv"  /* reference ID */
-#else /* VMS VMS_LOCALUNIT */
-#define REFID          "LCL\0" /* reference ID */
-#endif /* VMS VMS_LOCALUNIT */
 #define DESCRIPTION "Undisciplined local clock" /* WRU */
-
 #define STRATUM        5       /* default stratum */
 #define DISPERSION     .01     /* default dispersion (10 ms) */
 
@@ -168,7 +162,7 @@ local_start(
        peer->stratum = STRATUM;
        pp->stratum = STRATUM;
        pp->clockdesc = DESCRIPTION;
-       memcpy(&pp->refid, "INIT", 4);
+       pp->refid = htonl(LOOPBACKADR);
        poll_time = current_time;
        return (1);
 }