]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
reference: return real sync status in REF_GetReferenceParams()
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 8 Apr 2016 14:10:02 +0000 (16:10 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 8 Apr 2016 14:29:09 +0000 (16:29 +0200)
If local reference is active, return normal leap, but unsynchronised
status. Update the callers of the function to work with the leap
directly and not change their behaviour.

REF_IsLocalActive() is no longer needed.

ntp_core.c
refclock.c
reference.c
reference.h

index 8f3c3e827eac7605a66497d3bb33319a1e781d36..3d3a61236ed0cb592d17971ac4ffbbdc3976239b 100644 (file)
@@ -801,7 +801,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
                 )
 {
   NTP_Packet message;
-  int leap, auth_len, length, ret, precision;
+  int auth_len, length, ret, precision;
   struct timeval local_receive, local_transmit;
   NTP_int64 ts_fuzz;
 
@@ -823,7 +823,7 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
   if (my_mode == MODE_CLIENT) {
     /* Don't reveal local time or state of the clock in client packets */
     precision = 32;
-    are_we_synchronised = leap_status = our_stratum = our_ref_id = 0;
+    leap_status = our_stratum = our_ref_id = 0;
     our_ref_time.tv_sec = our_ref_time.tv_usec = 0;
     our_root_delay = our_root_dispersion = 0.0;
   } else {
@@ -859,14 +859,8 @@ transmit_packet(NTP_Mode my_mode, /* The mode this machine wants to be */
     local_receive = *local_rx;
   }
 
-  if (are_we_synchronised) {
-    leap = (int) leap_status;
-  } else {
-    leap = LEAP_Unsynchronised;
-  }
-
   /* Generate transmit packet */
-  message.lvm = NTP_LVM(leap, version, my_mode);
+  message.lvm = NTP_LVM(leap_status, version, my_mode);
   /* Stratum 16 and larger are invalid */
   if (our_stratum < NTP_MAX_STRATUM) {
     message.stratum = our_stratum;
index 86c0de2f500ef610f1037d255e146bc92663a790..59765f81764393df6f4fb933d2e66d92d89ed13a 100644 (file)
@@ -470,15 +470,16 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
     double root_delay, root_dispersion, distance;
     uint32_t ref_id;
 
-    /* Ignore the pulse if we are not well synchronized */
+    /* Ignore the pulse if we are not well synchronized and the local
+       reference is not active */
 
     REF_GetReferenceParams(&cooked_time, &is_synchronised, &leap, &stratum,
         &ref_id, &ref_time, &root_delay, &root_dispersion);
     distance = fabs(root_delay) / 2 + root_dispersion;
 
-    if (!is_synchronised || distance >= 0.5 / rate) {
+    if (leap == LEAP_Unsynchronised || distance >= 0.5 / rate) {
       DEBUG_LOG(LOGF_Refclock, "refclock pulse ignored second=%.9f sync=%d dist=%.9f",
-          second, is_synchronised, distance);
+          second, leap != LEAP_Unsynchronised, distance);
       /* Drop also all stored samples */
       filter_reset(&instance->filter);
       return 0;
@@ -528,9 +529,10 @@ pps_stratum(RCL_Instance instance, struct timeval *tv)
   REF_GetReferenceParams(tv, &is_synchronised, &leap, &stratum,
       &ref_id, &ref_time, &root_delay, &root_dispersion);
 
-  /* Don't change our stratum if local stratum is active
+  /* Don't change our stratum if the local reference is active
      or this is the current source */
-  if (ref_id == instance->ref_id || REF_IsLocalActive())
+  if (ref_id == instance->ref_id ||
+      (!is_synchronised && leap != LEAP_Unsynchronised))
     return stratum - 1;
 
   /* Or the current source is another PPS refclock */ 
index dfc851d33d8bf6f4e98ca4045c752852fe3195c5..ff73dbbea8141b117ed7fdea28313d6e0b3e6533 100644 (file)
@@ -1223,7 +1223,7 @@ REF_GetReferenceParams
 
   } else if (enable_local_stratum) {
 
-    *is_synchronised = 1;
+    *is_synchronised = 0;
 
     *stratum = local_stratum;
     *ref_id = NTP_REFID_LOCAL;
@@ -1331,14 +1331,6 @@ REF_DisableLocal(void)
 
 /* ================================================== */
 
-int
-REF_IsLocalActive(void)
-{
-  return !are_we_synchronised && enable_local_stratum;
-}
-
-/* ================================================== */
-
 #define LEAP_SECOND_CLOSE 5
 
 int REF_IsLeapSecondClose(void)
index d146ec50638a3a8c7a4ca7fb548c6614dd5b56b4..e4387b07b0b1f5abf18e680b3fbb6c7531b0800b 100644 (file)
@@ -179,7 +179,6 @@ extern void REF_ModifyMakestep(int limit, double threshold);
 
 extern void REF_EnableLocal(int stratum, double distance, int orphan);
 extern void REF_DisableLocal(void);
-extern int REF_IsLocalActive(void);
 
 /* Check if current raw or cooked time is close to a leap second
    and is better to discard any measurements */