]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: don't replace source instance when changing address
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 1 Dec 2014 17:01:11 +0000 (18:01 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 1 Dec 2014 17:40:47 +0000 (18:40 +0100)
Add new functions to change source's reference ID/address and reset the
instance. Use that instead of destroying and creating a new instance
when the NTP address is changed.

ntp_core.c
sources.c
sources.h
sourcestats.c
sourcestats.h

index 68d929f54ddffa714bd0d831da4efc018744399f..686f6402bdb8c13f5d5bd86e629e3df370240777 100644 (file)
@@ -541,8 +541,6 @@ NCR_ResetInstance(NCR_Instance instance)
 void
 NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr)
 {
-  SRC_SelectOption sel_option;
-
   inst->remote_addr = *remote_addr;
   inst->tx_count = 0;
   inst->presend_done = 0;
@@ -552,11 +550,10 @@ NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr)
   else
     inst->local_addr.sock_fd = NIO_GetServerSocket(remote_addr);
 
-  /* Replace sources and sourcestats instances */
-  sel_option = SRC_GetSelectOption(inst->source);
-  SRC_DestroyInstance(inst->source);
-  inst->source = SRC_CreateNewInstance(UTI_IPToRefid(&remote_addr->ip_addr), SRC_NTP,
-                                       sel_option, &inst->remote_addr.ip_addr);
+  /* Update the reference ID and reset the source/sourcestats instances */
+  SRC_SetRefid(inst->source, UTI_IPToRefid(&remote_addr->ip_addr),
+               &inst->remote_addr.ip_addr);
+  SRC_ResetInstance(inst->source);
 }
 
 /* ================================================== */
index e88fc472d5c2cba53e7af26998f9f72f870b50ed..ba18bb593c5019488bf597c250ff6d183ac2748a 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -231,20 +231,14 @@ SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, SRC_SelectOpt
   }
 
   sources[n_sources] = result;
+
   result->index = n_sources;
-  result->leap_status = LEAP_Normal;
-  result->ref_id = ref_id;
-  result->ip_addr = addr;
-  result->active = 0;
-  result->updates = 0;
-  result->reachability = 0;
-  result->reachability_size = 0;
-  result->distant = 0;
-  result->status = SRC_BAD_STATS;
   result->type = type;
-  result->sel_score = 1.0;
   result->sel_option = sel_option;
 
+  SRC_SetRefid(result, ref_id, addr);
+  SRC_ResetInstance(result);
+
   n_sources++;
 
   return result;
@@ -278,6 +272,33 @@ void SRC_DestroyInstance(SRC_Instance instance)
     --selected_source_index;
 }
 
+/* ================================================== */
+
+void
+SRC_ResetInstance(SRC_Instance instance)
+{
+  instance->leap_status = LEAP_Normal;
+  instance->active = 0;
+  instance->updates = 0;
+  instance->reachability = 0;
+  instance->reachability_size = 0;
+  instance->distant = 0;
+  instance->status = SRC_BAD_STATS;
+  instance->sel_score = 1.0;
+
+  SST_ResetInstance(instance->stats);
+}
+
+/* ================================================== */
+
+void
+SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr)
+{
+  instance->ref_id = ref_id;
+  instance->ip_addr = addr;
+  SST_SetRefid(instance->stats, ref_id, addr);
+}
+
 /* ================================================== */
 /* Function to get the range of frequencies, relative to the given
    source, that we believe the local clock lies within.  The return
@@ -1318,10 +1339,3 @@ SRC_Samples(SRC_Instance inst)
 }
 
 /* ================================================== */
-
-SRC_SelectOption SRC_GetSelectOption(SRC_Instance inst)
-{
-  return inst->sel_option;
-}
-
-/* ================================================== */
index d9a031526fd21badfc655a9ee9ba34caf80ac9ef..654b3c1c2ecd88d985f9d16b99756779e4d51bd7 100644 (file)
--- a/sources.h
+++ b/sources.h
@@ -74,6 +74,11 @@ extern SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, SRC_Se
 
 extern void SRC_DestroyInstance(SRC_Instance instance);
 
+/* Function to reset a source */
+extern void SRC_ResetInstance(SRC_Instance instance);
+
+/* Function to change the sources's reference ID and IP address */
+extern void SRC_SetRefid(SRC_Instance instance, uint32_t ref_id, IPAddr *addr);
 
 /* Function to get the range of frequencies, relative to the given
    source, that we believe the local clock lies within.  The return
@@ -174,7 +179,5 @@ extern SRC_Type SRC_GetType(int index);
 
 extern int SRC_Samples(SRC_Instance inst);
 
-extern SRC_SelectOption SRC_GetSelectOption(SRC_Instance inst);
-
 #endif /* GOT_SOURCES_H */
 
index 537e62ca206df0fdc3bbf90ec113d55db9b50239..de5f312c7a499f843d2449e8f20db94cb4cd1571 100644 (file)
@@ -182,9 +182,8 @@ SST_CreateInstance(uint32_t refid, IPAddr *addr)
 {
   SST_Stats inst;
   inst = MallocNew(struct SST_Stats_Record);
-  inst->refid = refid;
-  inst->ip_addr = addr;
 
+  SST_SetRefid(inst, refid, addr);
   SST_ResetInstance(inst);
 
   return inst;
@@ -220,6 +219,15 @@ SST_ResetInstance(SST_Stats inst)
   inst->nruns = 0;
 }
 
+/* ================================================== */
+
+void
+SST_SetRefid(SST_Stats inst, uint32_t refid, IPAddr *addr)
+{
+  inst->refid = refid;
+  inst->ip_addr = addr;
+}
+
 /* ================================================== */
 /* This function is called to prune the register down when it is full.
    For now, just discard the oldest sample.  */
index e080f9768547dcdc0fc4a504ea27f3e0f1180151..ad9f5d83c7a0831df35681bdd99728c3af83ac4b 100644 (file)
@@ -46,6 +46,9 @@ extern void SST_DeleteInstance(SST_Stats inst);
 /* This function resets an instance */
 extern void SST_ResetInstance(SST_Stats inst);
 
+/* This function changes the reference ID and IP address */
+extern void SST_SetRefid(SST_Stats inst, uint32_t refid, IPAddr *addr);
+
 /* This function accumulates a single sample into the statistics handler
 
    sample_time is the epoch at which the sample is to be considered to