Blame SOURCES/chrony-ipsourcename.patch

9f7b83
commit 33a1fe7a9ce223d6287ab7b11bca3208e9255cdd
9f7b83
Author: Miroslav Lichvar <mlichvar@redhat.com>
9f7b83
Date:   Wed Mar 9 15:30:16 2022 +0100
9f7b83
9f7b83
    ntp: split out conf_id allocation
9f7b83
9f7b83
diff --git a/ntp_sources.c b/ntp_sources.c
9f7b83
index 3cbb2ae7..30770825 100644
9f7b83
--- a/ntp_sources.c
9f7b83
+++ b/ntp_sources.c
9f7b83
@@ -698,21 +698,25 @@ static int get_unused_pool_id(void)
9f7b83
 
9f7b83
 /* ================================================== */
9f7b83
 
9f7b83
-NSR_Status
9f7b83
-NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
9f7b83
-              SourceParameters *params, uint32_t *conf_id)
9f7b83
+static uint32_t
9f7b83
+get_next_conf_id(uint32_t *conf_id)
9f7b83
 {
9f7b83
-  NSR_Status s;
9f7b83
-
9f7b83
-  s = add_source(remote_addr, NULL, type, params, INVALID_POOL, last_conf_id + 1);
9f7b83
-  if (s != NSR_Success)
9f7b83
-    return s;
9f7b83
-
9f7b83
   last_conf_id++;
9f7b83
+
9f7b83
   if (conf_id)
9f7b83
     *conf_id = last_conf_id;
9f7b83
 
9f7b83
-  return s;
9f7b83
+  return last_conf_id;
9f7b83
+}
9f7b83
+
9f7b83
+/* ================================================== */
9f7b83
+
9f7b83
+NSR_Status
9f7b83
+NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
9f7b83
+              SourceParameters *params, uint32_t *conf_id)
9f7b83
+{
9f7b83
+  return add_source(remote_addr, NULL, type, params, INVALID_POOL,
9f7b83
+                    get_next_conf_id(conf_id));
9f7b83
 }
9f7b83
 
9f7b83
 /* ================================================== */
9f7b83
@@ -725,6 +729,7 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
9f7b83
   struct SourcePool *sp;
9f7b83
   NTP_Remote_Address remote_addr;
9f7b83
   int i, new_sources, pool_id;
9f7b83
+  uint32_t cid;
9f7b83
 
9f7b83
   /* If the name is an IP address, add the source with the address directly */
9f7b83
   if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
9f7b83
@@ -770,14 +775,12 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
9f7b83
 
9f7b83
   append_unresolved_source(us);
9f7b83
 
9f7b83
-  last_conf_id++;
9f7b83
-  if (conf_id)
9f7b83
-    *conf_id = last_conf_id;
9f7b83
+  cid = get_next_conf_id(conf_id);
9f7b83
 
9f7b83
   for (i = 0; i < new_sources; i++) {
9f7b83
     if (i > 0)
9f7b83
       remote_addr.ip_addr.addr.id = ++last_address_id;
9f7b83
-    if (add_source(&remote_addr, name, type, params, us->pool_id, last_conf_id) != NSR_Success)
9f7b83
+    if (add_source(&remote_addr, name, type, params, us->pool_id, cid) != NSR_Success)
9f7b83
       return NSR_TooManySources;
9f7b83
   }
9f7b83
 
9f7b83
9f7b83
commit 1219f99935ca9597eb0e4f4c6039e536462cf1a6
9f7b83
Author: Miroslav Lichvar <mlichvar@redhat.com>
9f7b83
Date:   Wed Mar 9 15:34:16 2022 +0100
9f7b83
9f7b83
    ntp: keep original source IP address
9f7b83
    
9f7b83
    When an added source is specified by IP address, save the original
9f7b83
    string instead of formatting a new string from the parsed address, which
9f7b83
    can be different (e.g. compressed vs expanded IPv6 address).
9f7b83
    
9f7b83
    This fixes the chronyc sourcename command and -N option to print the IP
9f7b83
    address exactly as it was specified in the configuration file or chronyc
9f7b83
    add command.
9f7b83
9f7b83
diff --git a/ntp_sources.c b/ntp_sources.c
9f7b83
index 30770825..d46c211d 100644
9f7b83
--- a/ntp_sources.c
9f7b83
+++ b/ntp_sources.c
9f7b83
@@ -353,7 +353,6 @@ add_source(NTP_Remote_Address *remote_addr, char *name, NTP_Source_Type type,
9f7b83
       record_lock = 1;
9f7b83
 
9f7b83
       record = get_record(slot);
9f7b83
-      assert(!name || !UTI_IsStringIP(name));
9f7b83
       record->name = Strdup(name ? name : UTI_IPToString(&remote_addr->ip_addr));
9f7b83
       record->data = NCR_CreateInstance(remote_addr, type, params, record->name);
9f7b83
       record->remote_addr = NCR_GetRemoteAddress(record->data);
9f7b83
@@ -734,7 +733,8 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
9f7b83
   /* If the name is an IP address, add the source with the address directly */
9f7b83
   if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
9f7b83
     remote_addr.port = port;
9f7b83
-    return NSR_AddSource(&remote_addr, type, params, conf_id);
9f7b83
+    return add_source(&remote_addr, name, type, params, INVALID_POOL,
9f7b83
+                      get_next_conf_id(conf_id));
9f7b83
   }
9f7b83
 
9f7b83
   /* Make sure the name is at least printable and has no spaces */