From ab1f01bacd35a6e3876c914faa3aaba55af0464f Mon Sep 17 00:00:00 2001 From: Miroslav Lichvar Date: Mon, 22 Jun 2015 11:09:31 +0200 Subject: [PATCH] ntp: use specific reference ID when smoothing served time Set refid in server/broadcast packets to 127.127.1.255 when a time smoothing offset is applied to the timestamps. This allows the clients and administrators to detect that the server is not serving its best estimate of the true time. --- ntp.h | 1 + ntp_core.c | 17 +++++++++-------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/ntp.h b/ntp.h index a61dd02..5a377ef 100644 --- a/ntp.h +++ b/ntp.h @@ -112,5 +112,6 @@ typedef struct { /* Special NTP reference IDs */ #define NTP_REFID_UNSYNC 0x0UL #define NTP_REFID_LOCAL 0x7F7F0101UL /* 127.127.1.1 */ +#define NTP_REFID_SMOOTH 0x7F7F01FFUL /* 127.127.1.255 */ #endif /* GOT_NTP_H */ diff --git a/ntp_core.c b/ntp_core.c index 103d7c1..b477666 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -789,8 +789,8 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */ /* Get current smoothing offset when sending packet to a client */ if (SMT_IsEnabled() && (my_mode == MODE_SERVER || my_mode == MODE_BROADCAST)) { - smooth_time = 1; smooth_offset = SMT_GetOffset(&local_transmit); + smooth_time = fabs(smooth_offset) > LCL_GetSysPrecisionAsQuantum(); /* Suppress leap second when smoothing and slew mode are enabled */ if (REF_GetLeapMode() == REF_LeapModeSlew && @@ -801,6 +801,14 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */ smooth_offset = 0.0; } + if (smooth_time) { + our_ref_id = NTP_REFID_SMOOTH; + UTI_AddDoubleToTimeval(&our_ref_time, smooth_offset, &our_ref_time); + UTI_AddDoubleToTimeval(local_rx, smooth_offset, &local_receive); + } else { + local_receive = *local_rx; + } + if (are_we_synchronised) { leap = (int) leap_status; } else { @@ -828,13 +836,6 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */ /* Now fill in timestamps */ - if (smooth_time) { - UTI_AddDoubleToTimeval(&our_ref_time, smooth_offset, &our_ref_time); - UTI_AddDoubleToTimeval(local_rx, smooth_offset, &local_receive); - } else { - local_receive = *local_rx; - } - UTI_TimevalToInt64(&our_ref_time, &message.reference_ts, 0); /* Originate - this comes from the last packet the source sent us */