]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: use specific reference ID when smoothing served time
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 22 Jun 2015 09:09:31 +0000 (11:09 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 22 Jun 2015 10:54:50 +0000 (12:54 +0200)
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
ntp_core.c

diff --git a/ntp.h b/ntp.h
index a61dd02af16d6d7551793aaef7f858445bf85541..5a377ef18b3b062b1149422efc59cc941cd5d8d8 100644 (file)
--- 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 */
index 103d7c1b58dddeca6ba9f3de8ad5fbdcc8c7eb91..b47766619531a2554cb237fffb30b63bdcba60cc 100644 (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 */
   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 */