From: Harlan Stenn Date: Tue, 4 Oct 2005 06:52:27 +0000 (-0400) Subject: fixes from Dave Mills X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dcb31b77ad70d2a09ae248e9155205f19082f078;p=thirdparty%2Fntp.git fixes from Dave Mills bk: 434226abVqAO9zPmWPdoV_oZYWKN3A --- diff --git a/include/ntp.h b/include/ntp.h index ed9dcb62b5..0543674b1a 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -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 diff --git a/include/ntpd.h b/include/ntpd.h index 9baa9ff7ca..980a684526 100644 --- a/include/ntpd.h +++ b/include/ntpd.h @@ -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 diff --git a/ntpd/ntp_control.c b/ntpd/ntp_control.c index 0e6fb706b5..71c19d8445 100644 --- a/ntpd/ntp_control.c +++ b/ntpd/ntp_control.c @@ -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; diff --git a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c index 4789021d11..4daf2efd29 100644 --- a/ntpd/ntp_proto.c +++ b/ntpd/ntp_proto.c @@ -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); } diff --git a/ntpd/refclock_local.c b/ntpd/refclock_local.c index 3478f43838..3d4d1dd6bc 100644 --- a/ntpd/refclock_local.c +++ b/ntpd/refclock_local.c @@ -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 @@ -93,13 +93,7 @@ * 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); }