diff --git a/ntp_core.c b/ntp_core.c index 8c92175..f2a3138 100644 --- a/ntp_core.c +++ b/ntp_core.c @@ -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); diff --git a/refclock.c b/refclock.c index 1a78bfe..44df2c6 100644 --- a/refclock.c +++ b/refclock.c @@ -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), diff --git a/sources.c b/sources.c index 685eee6..4ea64d6 100644 --- 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) { diff --git a/sources.h b/sources.h index 6d97ee4..6a6b870 100644 --- 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 diff --git a/test/unit/sources.c b/test/unit/sources.c index ce7dc00..6f7f3d5 100644 --- a/test/unit/sources.c +++ b/test/unit/sources.c @@ -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);