]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: keep original source IP address
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Mar 2022 14:34:16 +0000 (15:34 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 10 Mar 2022 08:54:31 +0000 (09:54 +0100)
When an added source is specified by IP address, save the original
string instead of formatting a new string from the parsed address, which
can be different (e.g. compressed vs expanded IPv6 address).

This fixes the chronyc sourcename command and -N option to print the IP
address exactly as it was specified in the configuration file or chronyc
add command.

ntp_sources.c

index 307708256f6cd44b8a53edb8d3d7dee4fe7fb992..d46c211dd0537b0fcbd40a0d35f86f32c943e7bb 100644 (file)
@@ -353,7 +353,6 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type,
       record_lock = 1;
 
       record = get_record(slot);
-      assert(!name || !UTI_IsStringIP(name));
       record->name = Strdup(name ? name : UTI_IPToString(&remote_addr->ip_addr));
       record->data = NCR_CreateInstance(remote_addr, type, params, record->name);
       record->remote_addr = NCR_GetRemoteAddress(record->data);
@@ -734,7 +733,8 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
   /* If the name is an IP address, add the source with the address directly */
   if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
     remote_addr.port = port;
-    return NSR_AddSource(&remote_addr, type, params, conf_id);
+    return add_source(&remote_addr, name, type, params, INVALID_POOL,
+                      get_next_conf_id(conf_id));
   }
 
   /* Make sure the name is at least printable and has no spaces */