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.
This commit is contained in:
Miroslav Lichvar 2015-06-22 11:09:31 +02:00
parent b9b896d8e7
commit ab1f01bacd
2 changed files with 10 additions and 8 deletions

1
ntp.h
View file

@ -112,5 +112,6 @@ typedef struct {
/* Special NTP reference IDs */ /* Special NTP reference IDs */
#define NTP_REFID_UNSYNC 0x0UL #define NTP_REFID_UNSYNC 0x0UL
#define NTP_REFID_LOCAL 0x7F7F0101UL /* 127.127.1.1 */ #define NTP_REFID_LOCAL 0x7F7F0101UL /* 127.127.1.1 */
#define NTP_REFID_SMOOTH 0x7F7F01FFUL /* 127.127.1.255 */
#endif /* GOT_NTP_H */ #endif /* GOT_NTP_H */

View file

@ -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 */ /* Get current smoothing offset when sending packet to a client */
if (SMT_IsEnabled() && (my_mode == MODE_SERVER || my_mode == MODE_BROADCAST)) { if (SMT_IsEnabled() && (my_mode == MODE_SERVER || my_mode == MODE_BROADCAST)) {
smooth_time = 1;
smooth_offset = SMT_GetOffset(&local_transmit); smooth_offset = SMT_GetOffset(&local_transmit);
smooth_time = fabs(smooth_offset) > LCL_GetSysPrecisionAsQuantum();
/* Suppress leap second when smoothing and slew mode are enabled */ /* Suppress leap second when smoothing and slew mode are enabled */
if (REF_GetLeapMode() == REF_LeapModeSlew && 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; 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) { if (are_we_synchronised) {
leap = (int) leap_status; leap = (int) leap_status;
} else { } else {
@ -828,13 +836,6 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
/* Now fill in timestamps */ /* 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); UTI_TimevalToInt64(&our_ref_time, &message.reference_ts, 0);
/* Originate - this comes from the last packet the source sent us */ /* Originate - this comes from the last packet the source sent us */