Fix handling of stratum zero.

Further to the discussion with John Hasler, here are new diffs which
handles the incoming stratum 0 claim of a remote server by redefining the
incoming stratum as one bigger than the Max if it is zero, as per the NTP
version 4 documentation.

If the incoming stratum is zero it sets it to NTP_MAX_STRATUM+1 . If our
current stratum is larger than the NTP_MAX_STRATUM, the outgoing stratum is
also set to zero as per the suggestions in the NTP docs.
Introduces the new NTP_INVALID_STRATUM of 0 for doing these tests or
setting the outgoing stratum.

It is unclear whether chrony wants to follow NTP in setting the outgoing
stratum to zero if it is unknown or invalid, rather than a number larger
than the max stratum. Setting it to zero seems silly, since zero is already
used to define the stratum of a hardware clock (GPS, atomic, etc). This
seems ripe for confusion. But the fact that the ntp docs state to do this,
and that ntp servers (eg ntp.ubc.ca) are already doing this (using 0 to
mean invalid) means that chrony has to handle it on the incoming packets
from the servers.
This commit is contained in:
Bill Unruh 2007-06-26 23:46:33 +01:00 committed by Richard P. Curnow
parent 8022874a47
commit 75a7af9edc

View file

@ -196,6 +196,9 @@ struct NCR_Instance_Record {
/* Maximum allowed stratum */
#define NTP_MAX_STRATUM 15
/* INVALID or Unkown stratum from external server as per the NTP 4 docs */
#define NTP_INVALID_STRATUM 0
/* ================================================== */
static ADF_AuthTable access_auth_table;
@ -539,7 +542,9 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
/* Generate transmit packet */
message.lvm = ((leap << 6) &0xc0) | ((version << 3) & 0x38) | (my_mode & 0x07);
message.stratum = our_stratum;
if(our_stratum<=NTP_MAX_STRATUM)message.stratum = our_stratum;
else message.stratum=NTP_INVALID_STRATUM; //(WGU) to handle NTP "Invalid" stratum as per the NTP V4 documents.
message.poll = my_poll;
message.precision = LCL_GetSysPrecisionAsLog();
@ -983,6 +988,9 @@ receive_packet(NTP_Packet *message, struct timeval *now, NCR_Instance inst, int
test6 = 1; /* Succeeded */
}
/* (WGU) Set stratum to greater than any valid if incoming is 0 */
/* as per the NPT v4 documentation*/
if (message->stratum<=NTP_INVALID_STRATUM)message->stratum=NTP_MAX_STRATUM+1;
/* Test 7 checks that the stratum in the packet is appropriate */
if ((message->stratum > REF_GetOurStratum()) ||
(message->stratum > NTP_MAX_STRATUM)) {