]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
ntp: split out conf_id allocation
authorMiroslav Lichvar <mlichvar@redhat.com>
Wed, 9 Mar 2022 14:30:16 +0000 (15:30 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 10 Mar 2022 08:53:29 +0000 (09:53 +0100)
ntp_sources.c

index 3cbb2ae7e6553f66605b3fd9a4d57ef355d46cc1..307708256f6cd44b8a53edb8d3d7dee4fe7fb992 100644 (file)
@@ -698,21 +698,25 @@ static int get_unused_pool_id(void)
 
 /* ================================================== */
 
-NSR_Status
-NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
-              SourceParameters *params, uint32_t *conf_id)
+static uint32_t
+get_next_conf_id(uint32_t *conf_id)
 {
-  NSR_Status s;
-
-  s = add_source(remote_addr, NULL, type, params, INVALID_POOL, last_conf_id + 1);
-  if (s != NSR_Success)
-    return s;
-
   last_conf_id++;
+
   if (conf_id)
     *conf_id = last_conf_id;
 
-  return s;
+  return last_conf_id;
+}
+
+/* ================================================== */
+
+NSR_Status
+NSR_AddSource(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
+              SourceParameters *params, uint32_t *conf_id)
+{
+  return add_source(remote_addr, NULL, type, params, INVALID_POOL,
+                    get_next_conf_id(conf_id));
 }
 
 /* ================================================== */
@@ -725,6 +729,7 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
   struct SourcePool *sp;
   NTP_Remote_Address remote_addr;
   int i, new_sources, pool_id;
+  uint32_t cid;
 
   /* If the name is an IP address, add the source with the address directly */
   if (UTI_StringToIP(name, &remote_addr.ip_addr)) {
@@ -770,14 +775,12 @@ NSR_AddSourceByName(char *name, int port, int pool, NTP_Source_Type type,
 
   append_unresolved_source(us);
 
-  last_conf_id++;
-  if (conf_id)
-    *conf_id = last_conf_id;
+  cid = get_next_conf_id(conf_id);
 
   for (i = 0; i < new_sources; i++) {
     if (i > 0)
       remote_addr.ip_addr.addr.id = ++last_address_id;
-    if (add_source(&remote_addr, name, type, params, us->pool_id, last_conf_id) != NSR_Success)
+    if (add_source(&remote_addr, name, type, params, us->pool_id, cid) != NSR_Success)
       return NSR_TooManySources;
   }