]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp+refclock: add functions to modify offset option
authorMiroslav Lichvar <mlichvar@redhat.com>
Thu, 7 Mar 2024 15:19:04 +0000 (16:19 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 7 Mar 2024 15:19:04 +0000 (16:19 +0100)
ntp_core.c
ntp_core.h
ntp_sources.c
ntp_sources.h
refclock.c
refclock.h
stubs.c

index 44682ec4a75ff76842e9b67d52831ad87543612f..99360dec62eafc81645f1ac5996300abcb76373d 100644 (file)
@@ -3024,6 +3024,16 @@ NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum)
 
 /* ================================================== */
 
+void
+NCR_ModifyOffset(NCR_Instance inst, double new_offset)
+{
+  inst->offset_correction = new_offset;
+  LOG(LOGS_INFO, "Source %s new offset %f",
+      UTI_IPToString(&inst->remote_addr.ip_addr), new_offset);
+}
+
+/* ================================================== */
+
 void
 NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target)
 {
index 5c5a6141e207a91858349a40634e702a54eed819..67971ead5d4a59e01186cdad9bed9630830bfe07 100644 (file)
@@ -113,6 +113,8 @@ extern void NCR_ModifyMaxdelaydevratio(NCR_Instance inst, double new_max_delay_d
 
 extern void NCR_ModifyMinstratum(NCR_Instance inst, int new_min_stratum);
 
+extern void NCR_ModifyOffset(NCR_Instance inst, double new_offset);
+
 extern void NCR_ModifyPolltarget(NCR_Instance inst, int new_poll_target);
 
 extern void NCR_InitiateSampleBurst(NCR_Instance inst, int n_good_samples, int n_total_samples);
index 590e5e054c1e486b5e871627da256e829242c112..0dfdefb3dc53456b1ff8fb02d866150610591a6b 100644 (file)
@@ -1444,6 +1444,20 @@ NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum)
 
 /* ================================================== */
 
+int
+NSR_ModifyOffset(IPAddr *address, double new_offset)
+{
+  int slot;
+
+  if (!find_slot(address, &slot))
+    return 0;
+
+  NCR_ModifyOffset(get_record(slot)->data, new_offset);
+  return 1;
+}
+
+/* ================================================== */
+
 int
 NSR_ModifyPolltarget(IPAddr *address, int new_poll_target)
 {
index 79daf1db5d507b97053c21221ceb3a00afc028e9..89a322e9d06fc190a8833ddf318442b4100e87a6 100644 (file)
@@ -140,6 +140,8 @@ extern int NSR_ModifyMaxdelaydevratio(IPAddr *address, double new_max_delay_rati
 
 extern int NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum);
 
+extern int NSR_ModifyOffset(IPAddr *address, double new_offset);
+
 extern int NSR_ModifyPolltarget(IPAddr *address, int new_poll_target);
 
 extern int NSR_InitiateSampleBurst(int n_good_samples, int n_total_samples, IPAddr *mask, IPAddr *address);
index 44ba6d5c663795795e8f42ded172fafe6300f8a8..22d775a5e7829a7927ced663c5d67c5e3b7eefc9 100644 (file)
@@ -321,6 +321,22 @@ RCL_ReportSource(RPT_SourceReport *report, struct timespec *now)
   }
 }
 
+int
+RCL_ModifyOffset(uint32_t ref_id, double offset)
+{
+  unsigned int i;
+
+  for (i = 0; i < ARR_GetSize(refclocks); i++) {
+    RCL_Instance inst = get_refclock(i);
+    if (inst->ref_id == ref_id) {
+      inst->offset = offset;
+      LOG(LOGS_INFO, "Source %s new offset %f", UTI_RefidToString(ref_id), offset);
+      return 1;
+    }
+  }
+  return 0;
+}
+
 void
 RCL_SetDriverData(RCL_Instance instance, void *data)
 {
index 7947b6279037b7edde54db297a573b8220ae995b..40c852deb5dd2f4051a1d6c801b50310db8bc3e8 100644 (file)
@@ -68,6 +68,7 @@ extern void RCL_Finalise(void);
 extern int RCL_AddRefclock(RefclockParameters *params);
 extern void RCL_StartRefclocks(void);
 extern void RCL_ReportSource(RPT_SourceReport *report, struct timespec *now);
+extern int RCL_ModifyOffset(uint32_t ref_id, double offset);
 
 /* functions used by drivers */
 extern void RCL_SetDriverData(RCL_Instance instance, void *data);
diff --git a/stubs.c b/stubs.c
index 044d17ed9081b6ba638df9da275194ffc0429fc9..9d0f848109ee9c19b024456daea74b81c997796a 100644 (file)
--- a/stubs.c
+++ b/stubs.c
@@ -320,6 +320,12 @@ NSR_ModifyMinstratum(IPAddr *address, int new_min_stratum)
   return 0;
 }
 
+int
+NSR_ModifyOffset(IPAddr *address, double new_offset)
+{
+  return 0;
+}
+
 int
 NSR_ModifyPolltarget(IPAddr *address, int new_poll_target)
 {
@@ -419,6 +425,12 @@ RCL_ReportSource(RPT_SourceReport *report, struct timespec *now)
   memset(report, 0, sizeof (*report));
 }
 
+int
+RCL_ModifyOffset(uint32_t ref_id, double offset)
+{
+  return 0;
+}
+
 #endif /* !FEAT_REFCLOCK */
 
 #ifndef FEAT_SIGND