sources: ignore noselect sources when updating selection options

Ignore any sources specified with the noselect option with respect to
the auth selection mode.
This commit is contained in:
Miroslav Lichvar 2020-05-18 12:06:27 +02:00
parent 4f5343f086
commit a6ec6ec3ac
3 changed files with 18 additions and 3 deletions

View 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*:::

View file

@ -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;

View 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);