]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
sources: ignore noselect sources when updating selection options
authorMiroslav Lichvar <mlichvar@redhat.com>
Mon, 18 May 2020 10:06:27 +0000 (12:06 +0200)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 18 May 2020 15:38:09 +0000 (17:38 +0200)
Ignore any sources specified with the noselect option with respect to
the auth selection mode.

doc/chrony.conf.adoc
sources.c
test/unit/sources.c

index c7989b8f8d5d1044184cd8d14259f8fe25f8dab9..26c4d0bb925312d7f36d3b68b51df0c3d1ef21df 100644 (file)
@@ -763,6 +763,10 @@ This directive determines the default selection options for authenticated and
 unauthenticated sources in order to simplify the configuration with the
 configuration file and *chronyc* commands. It sets a policy for authentication.
 +
+Sources specified with the *noselect* option are ignored (not counted as either
+authenticated or unauthenticated), and they always have only the selection
+options specified in the configuration.
++
 There are four modes:
 +
 *require*:::
index b5f06819431c19157af102fe7a10f462178a25fa..bd16ea4f24d0ddef4e28e67a13e116089b6bac62 100644 (file)
--- a/sources.c
+++ b/sources.c
@@ -501,6 +501,8 @@ update_sel_options(void)
   auth_ntp_sources = unauth_ntp_sources = 0;
 
   for (i = 0; i < n_sources; i++) {
+    if (sources[i]->conf_sel_options & SRC_SELECT_NOSELECT)
+      continue;
     if (sources[i]->type != SRC_NTP)
       continue;
     if (sources[i]->authenticated)
@@ -535,6 +537,9 @@ update_sel_options(void)
   for (i = 0; i < n_sources; i++) {
     options = sources[i]->conf_sel_options;
 
+    if (options & SRC_SELECT_NOSELECT)
+      continue;
+
     switch (sources[i]->type) {
       case SRC_NTP:
         options |= sources[i]->authenticated ? auth_ntp_options : unauth_ntp_options;
index 3d97a992287b0700987d9591ffd386a755569cfe..1c666297506630582f5699f49751d4660c9a4f18 100644 (file)
@@ -40,7 +40,7 @@ test_unit(void)
   SRC_Instance srcs[16];
   RPT_SourceReport report;
   NTP_Sample sample;
-  int i, j, k, l, n1, n2, n3, samples, sel_options;
+  int i, j, k, l, n1, n2, n3, n4, samples, sel_options;
   char conf[128];
 
   CNF_Initialise(0, 0);
@@ -168,12 +168,12 @@ test_unit(void)
     CNF_ParseLine(NULL, 0, conf);
     TEST_CHECK(CNF_GetAuthSelectMode() == sel_mode);
 
-    sel_options = random() & (SRC_SELECT_NOSELECT | SRC_SELECT_PREFER |
-                              SRC_SELECT_TRUST | SRC_SELECT_REQUIRE);
+    sel_options = random() & (SRC_SELECT_PREFER | SRC_SELECT_TRUST | SRC_SELECT_REQUIRE);
 
     n1 = random() % 3;
     n2 = random() % 3;
     n3 = random() % 3;
+    n4 = random() % 3;
     assert(n1 + n2 + n3 < sizeof (srcs) / sizeof (srcs[0]));
 
     for (j = 0; j < n1; j++)
@@ -182,6 +182,9 @@ test_unit(void)
       srcs[j] = create_source(SRC_NTP, 1, sel_options);
     for (; j < n1 + n2 + n3; j++)
       srcs[j] = create_source(SRC_NTP, 0, sel_options);
+    for (; j < n1 + n2 + n3 + n4; j++)
+      srcs[j] = create_source(random() % 2 ? SRC_REFCLOCK : SRC_NTP,
+                              random() % 2, sel_options | SRC_SELECT_NOSELECT);
 
     switch (sel_mode) {
       case SRC_AUTHSELECT_IGNORE:
@@ -211,6 +214,9 @@ test_unit(void)
         assert(0);
     }
 
+    for (j = n1 + n2 + n3; j < n1 + n2 + n3 + n4; j++)
+      TEST_CHECK(srcs[j]->sel_options == (sel_options | SRC_SELECT_NOSELECT));
+
     for (j = n1 + n2 + n3 - 1; j >= 0; j--) {
       if (j < n1 + n2)
         TEST_CHECK(srcs[j]->sel_options == sel_options);