]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: allow modifications of selection options
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 4 May 2020 09:09:39 +0000 (11:09 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Thu, 14 May 2020 13:37:38 +0000 (15:37 +0200)
Refactor the code to allow the selection options of the current sources
to be modified when other sources are added and removed. Also, make the
authentication status of each source available to the code which makes
the modifications.

ntp_core.c
refclock.c
sources.c
sources.h
test/unit/sources.c

index 8c92175d0218888303dd414fc64b7a4ab648d590..f2a3138edb56974b819b8292acde8c6c01683ded 100644 (file)
@@ -582,8 +582,8 @@ NCR_CreateInstance(NTP_Remote_Address *remote_addr, NTP_Source_Type type,
 
   /* Create a source instance for this NTP source */
   result->source = SRC_CreateNewInstance(UTI_IPToRefid(&remote_addr->ip_addr),
-                                         SRC_NTP, params->sel_options,
-                                         &result->remote_addr.ip_addr,
+                                         SRC_NTP, NAU_IsAuthEnabled(result->auth),
+                                         params->sel_options, &result->remote_addr.ip_addr,
                                          params->min_samples, params->max_samples,
                                          params->min_delay, params->asymmetry);
 
index 1a78bfe8055bf9aa46b311b7c95ee708d69d21ef..44df2c6992c57aaf0a469cb48d8912b0af4125cd 100644 (file)
@@ -253,8 +253,9 @@ RCL_AddRefclock(RefclockParameters *params)
   inst->filter = SPF_CreateInstance(MIN(params->filter_length, 4), params->filter_length,
                                     params->max_dispersion, 0.6);
 
-  inst->source = SRC_CreateNewInstance(inst->ref_id, SRC_REFCLOCK, params->sel_options, NULL,
-                                       params->min_samples, params->max_samples, 0.0, 0.0);
+  inst->source = SRC_CreateNewInstance(inst->ref_id, SRC_REFCLOCK, 0, params->sel_options,
+                                       NULL, params->min_samples, params->max_samples,
+                                       0.0, 0.0);
 
   DEBUG_LOG("refclock %s refid=%s poll=%d dpoll=%d filter=%d",
       params->driver_name, UTI_RefidToString(inst->ref_id),
index 685eee6d2497a2b5b71d59b3fc8cc2a2f07aeed8..4ea64d69d56b0307c1b67b624cc22b61b4e06658 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -118,7 +118,13 @@ struct SRC_Instance_Record {
   /* Type of the source */
   SRC_Type type;
 
-  /* Options used when selecting sources */ 
+  /* Flag indicating that the source is authenticated */
+  int authenticated;
+
+  /* Configured selection options */
+  int conf_sel_options;
+
+  /* Effective selection options */
   int sel_options;
 
   /* Score against currently selected source */
@@ -172,6 +178,7 @@ static double combine_limit;
 /* ================================================== */
 /* Forward prototype */
 
+static void update_sel_options(void);
 static void slew_sources(struct timespec *raw, struct timespec *cooked, double dfreq,
                          double doffset, LCL_ChangeType change_type, void *anything);
 static void add_dispersion(double dispersion, void *anything);
@@ -215,9 +222,9 @@ void SRC_Finalise(void)
 /* Function to create a new instance.  This would be called by one of
    the individual source-type instance creation routines. */
 
-SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int sel_options,
-                                   IPAddr *addr, int min_samples, int max_samples,
-                                   double min_delay, double asymmetry)
+SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int authenticated,
+                                   int sel_options, IPAddr *addr, int min_samples,
+                                   int max_samples, double min_delay, double asymmetry)
 {
   SRC_Instance result;
 
@@ -250,6 +257,8 @@ SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int sel_optio
 
   result->index = n_sources;
   result->type = type;
+  result->authenticated = authenticated;
+  result->conf_sel_options = sel_options;
   result->sel_options = sel_options;
   result->active = 0;
 
@@ -258,6 +267,8 @@ SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int sel_optio
 
   n_sources++;
 
+  update_sel_options();
+
   return result;
 }
 
@@ -282,6 +293,8 @@ void SRC_DestroyInstance(SRC_Instance instance)
   --n_sources;
   Free(instance);
 
+  update_sel_options();
+
   /* If this was the previous reference source, we have to reselect! */
   if (selected_source_index == dead_index)
     SRC_ReselectSource();
@@ -479,6 +492,18 @@ SRC_ResetReachability(SRC_Instance inst)
 
 /* ================================================== */
 
+static void
+update_sel_options(void)
+{
+  int i;
+
+  for (i = 0; i < n_sources; i++) {
+    sources[i]->sel_options = sources[i]->conf_sel_options;
+  }
+}
+
+/* ================================================== */
+
 static void
 log_selection_message(const char *format, const char *arg)
 {
index 6d97ee49a4ddceb6ad8bafd8f6eb565059cb3e7f..6a6b870d680983cc4672a90ee9ce1308e9cf2da5 100644 (file)
--- a/sources.h
+++ b/sources.h
@@ -59,9 +59,9 @@ typedef enum {
 /* Function to create a new instance.  This would be called by one of
    the individual source-type instance creation routines. */
 
-extern SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int sel_options,
-                                          IPAddr *addr, int min_samples, int max_samples,
-                                          double min_delay, double asymmetry);
+extern SRC_Instance SRC_CreateNewInstance(uint32_t ref_id, SRC_Type type, int authenticated,
+                                          int sel_options, IPAddr *addr, int min_samples,
+                                          int max_samples, double min_delay, double asymmetry);
 
 /* Function to get rid of a source when it is being unconfigured.
    This may cause the current reference source to be reselected, if this
index ce7dc008a2c758b4a653b46594a48c0128060eec..6f7f3d57fe07390568aea0e0090247adf2850436 100644 (file)
@@ -51,7 +51,7 @@ test_unit(void)
                                     SRC_SELECT_TRUST | SRC_SELECT_REQUIRE);
 
       DEBUG_LOG("added source %d options %d", j, sel_options);
-      srcs[j] = SRC_CreateNewInstance(UTI_IPToRefid(&addr), SRC_NTP, sel_options, &addr,
+      srcs[j] = SRC_CreateNewInstance(UTI_IPToRefid(&addr), SRC_NTP, 0, sel_options, &addr,
                                       SRC_DEFAULT_MINSAMPLES, SRC_DEFAULT_MAXSAMPLES,
                                       0.0, 1.0);
       SRC_UpdateReachability(srcs[j], 1);