]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: add function to update source NTP address
authorMiroslav Lichvar <mlichvar@redhat.com>
Sat, 23 Mar 2019 14:49:06 +0000 (15:49 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 5 Mar 2020 15:02:15 +0000 (16:02 +0100)
This will allow a source to have its address changed due to NTS-KE
server negotiation, which allows the NTS-KE server to have a different
address than the NTP server.

ntp_core.c
ntp_core.h
ntp_sources.c
ntp_sources.h

index 7f48d9a58599ca47ae7b7a4f02db755ab5c30b6c..9ce0426b3160c70e50a1c530cb128f909a4c9673 100644 (file)
@@ -691,7 +691,7 @@ NCR_ResetPoll(NCR_Instance instance)
 /* ================================================== */
 
 void
-NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr)
+NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr, int ntp_only)
 {
   memset(&inst->report, 0, sizeof (inst->report));
   NCR_ResetInstance(inst);
index 522d59b2a2d0dd15bc6d16934f6b6c1e720ec1f2..78b6ede1472503fd9b2c93dcd9075c6d7375d478 100644 (file)
@@ -74,7 +74,8 @@ extern void NCR_ResetInstance(NCR_Instance inst);
 extern void NCR_ResetPoll(NCR_Instance instance);
 
 /* Change the remote address of an instance */
-extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr);
+extern void NCR_ChangeRemoteAddress(NCR_Instance inst, NTP_Remote_Address *remote_addr,
+                                    int ntp_only);
 
 /* This routine is called when a new packet arrives off the network,
    and it relates to a source we have an ongoing protocol exchange with */
index 6d10463b7ffcd98bcab798828b1f8be9c043a05b..2b1240c3cf9406948eaab6ba5bf8e1d4272aa84e 100644 (file)
@@ -343,7 +343,8 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type, So
 /* ================================================== */
 
 static NSR_Status
-replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
+change_source_address(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr,
+                      int replacement)
 {
   int slot1, slot2, found;
   SourceRecord *record;
@@ -361,7 +362,7 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
     return NSR_AlreadyInUse;
 
   record = get_record(slot1);
-  NCR_ChangeRemoteAddress(record->data, new_addr);
+  NCR_ChangeRemoteAddress(record->data, new_addr, !replacement);
   record->remote_addr = NCR_GetRemoteAddress(record->data);
   if (!UTI_IsIPReal(&old_addr->ip_addr) && UTI_IsIPReal(&new_addr->ip_addr)) {
     if (auto_start_sources)
@@ -384,7 +385,8 @@ replace_source(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
     /* The hash table must be rebuilt for the changed address */
     rehash_records();
 
-    LOG(severity, "Source %s replaced with %s (%s)", UTI_IPToString(&old_addr->ip_addr),
+    LOG(severity, "Source %s %s %s (%s)", UTI_IPToString(&old_addr->ip_addr),
+        replacement ? "replaced with" : "changed to",
         UTI_IPToString(&new_addr->ip_addr), name ? name : "");
   } else {
     LOG(severity, "Source %s (%s) changed port to %d",
@@ -404,7 +406,7 @@ replace_source_connectable(NTP_Remote_Address *old_addr, NTP_Remote_Address *new
     return 0;
   }
 
-  if (replace_source(old_addr, new_addr) == NSR_AlreadyInUse)
+  if (change_source_address(old_addr, new_addr, 1) == NSR_AlreadyInUse)
     return 0;
 
   return 1;
@@ -864,6 +866,17 @@ NSR_RefreshAddresses(void)
 
 /* ================================================== */
 
+NSR_Status
+NSR_UpdateSourceNtpAddress(NTP_Remote_Address *old_addr, NTP_Remote_Address *new_addr)
+{
+  if (new_addr->ip_addr.family == IPADDR_UNSPEC)
+    return NSR_InvalidAF;
+
+  return change_source_address(old_addr, new_addr, 0);
+}
+
+/* ================================================== */
+
 static void remove_pool_sources(int pool, int tentative, int unresolved)
 {
   SourceRecord *record;
index 686678e841b001bad474f72212fffe2c10873aae..ce50a680143b2460d778ff2b309fcb57b1ea0c6c 100644 (file)
@@ -87,6 +87,10 @@ extern void NSR_HandleBadSource(IPAddr *address);
 /* Procedure to resolve all names again */
 extern void NSR_RefreshAddresses(void);
 
+/* Procedure to update the address of a source */
+extern NSR_Status NSR_UpdateSourceNtpAddress(NTP_Remote_Address *old_addr,
+                                             NTP_Remote_Address *new_addr);
+
 /* Procedure to get local reference ID corresponding to a source */
 extern uint32_t NSR_GetLocalRefid(IPAddr *address);