]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
Mark offline sources unreachable
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 2 Apr 2010 13:55:58 +0000 (15:55 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Fri, 2 Apr 2010 13:55:58 +0000 (15:55 +0200)
ntp_core.c
ntp_core.h
ntp_sources.c

index c0eada3d53ab7477c97baf14e3a2ef1af98fb9a2..6e3abf76b9ed881b7c6a4242d24d5c7bdf57f874 100644 (file)
@@ -1709,6 +1709,8 @@ NCR_TakeSourceOffline(NCR_Instance inst)
         SCH_RemoveTimeout(inst->timeout_id);
         inst->timer_running = 0;
         inst->opmode = MD_OFFLINE;
+        /* Mark source unreachable */
+        SRC_UnsetReachable(inst->source);
       }
       break;
     case MD_OFFLINE:
@@ -1923,3 +1925,10 @@ NCR_GetRemoteAddress(NCR_Instance inst)
 }
 
 /* ================================================== */
+
+int NCR_IsSyncPeer(NCR_Instance inst)
+{
+  return SRC_IsSyncPeer(inst->source);
+}
+
+/* ================================================== */
index ee22e466705d17d7fed66e5df71bd21cceaff77a..1a8efcc275bd23ee0571321cecb8f63f2dafaea6 100644 (file)
@@ -104,4 +104,6 @@ extern void NCR_IncrementActivityCounters(NCR_Instance inst, int *online, int *o
 
 extern NTP_Remote_Address *NCR_GetRemoteAddress(NCR_Instance instance);
 
+extern int NCR_IsSyncPeer(NCR_Instance instance);
+
 #endif /* GOT_NTP_CORE_H */
index 9a058f3d0a0cac1fd731a139db44618b95bcc746..eeca7ced1140ff1121cab0dd3461b95cf4365581 100644 (file)
@@ -355,20 +355,29 @@ NSR_TakeSourcesOnline(IPAddr *mask, IPAddr *address)
 int
 NSR_TakeSourcesOffline(IPAddr *mask, IPAddr *address)
 {
-  int i;
-  int any;
+  int i, any, syncpeer;
 
   any = 0;
+  syncpeer = -1;
   for (i=0; i<N_RECORDS; i++) {
     if (records[i].remote_addr) {
       if (address->family == IPADDR_UNSPEC ||
           !UTI_CompareIPs(&records[i].remote_addr->ip_addr, address, mask)) {
         any = 1;
+        if (NCR_IsSyncPeer(records[i].data)) {
+          syncpeer = i;
+          continue;
+        }
         NCR_TakeSourceOffline(records[i].data);
       }
     }
   }
 
+  /* Take sync peer offline as last to avoid reference switching */
+  if (syncpeer >= 0) {
+    NCR_TakeSourceOffline(records[syncpeer].data);
+  }
+
   return any;
 }