diff --git a/conf.c b/conf.c index 232a890..363e8b8 100644 --- a/conf.c +++ b/conf.c @@ -681,7 +681,7 @@ static void parse_refclock(char *line) { int n, poll, dpoll, filter_length, pps_rate, min_samples, max_samples, sel_options; - int max_lock_age, pps_forced; + int max_lock_age, pps_forced, stratum; uint32_t ref_id, lock_ref_id; double offset, delay, precision, max_dispersion, pulse_width; char *p, *cmd, *name, *param; @@ -704,6 +704,7 @@ parse_refclock(char *line) ref_id = 0; max_lock_age = 2; lock_ref_id = 0; + stratum = 0; if (!*line) { command_parse_error(); @@ -774,6 +775,10 @@ parse_refclock(char *line) } else if (!strcasecmp(cmd, "maxdispersion")) { if (sscanf(line, "%lf%n", &max_dispersion, &n) != 1) break; + } else if (!strcasecmp(cmd, "stratum")) { + if (sscanf(line, "%d%n", &stratum, &n) != 1 || + stratum >= NTP_MAX_STRATUM || stratum < 0) + break; } else if (!strcasecmp(cmd, "width")) { if (sscanf(line, "%lf%n", &pulse_width, &n) != 1) break; @@ -811,6 +816,7 @@ parse_refclock(char *line) refclock->min_samples = min_samples; refclock->max_samples = max_samples; refclock->sel_options = sel_options; + refclock->stratum = stratum; refclock->offset = offset; refclock->delay = delay; refclock->precision = precision; diff --git a/doc/chrony.conf.adoc b/doc/chrony.conf.adoc index 5c85959..82c56c1 100644 --- a/doc/chrony.conf.adoc +++ b/doc/chrony.conf.adoc @@ -516,6 +516,9 @@ is included in the maximum assumed error which is used in the source selection algorithm. Increasing the delay is useful to avoid having no majority in the source selection or to make it prefer other sources. The default is 1e-9 (1 nanosecond). +*stratum* _stratum_::: +This option sets the NTP stratum of the refclock. This can be useful when the +refclock provides time with a stratum other than 0. The default is 0. *precision* _precision_::: This option sets the precision of the reference clock (in seconds). The default value is the estimated precision of the system clock. diff --git a/refclock.c b/refclock.c index 6ca9118..bcb3064 100644 --- a/refclock.c +++ b/refclock.c @@ -79,6 +79,7 @@ struct RCL_Instance_Record { int pps_rate; int pps_active; int max_lock_age; + int stratum; struct MedianFilter filter; uint32_t ref_id; uint32_t lock_ref; @@ -200,6 +201,7 @@ RCL_AddRefclock(RefclockParameters *params) inst->pps_rate = params->pps_rate; inst->pps_active = 0; inst->max_lock_age = params->max_lock_age; + inst->stratum = params->stratum; inst->lock_ref = params->lock_ref_id; inst->offset = params->offset; inst->delay = params->delay; @@ -635,7 +637,7 @@ poll_timeout(void *arg) /* Handle special case when PPS is used with local stratum */ stratum = pps_stratum(inst, &sample_time); else - stratum = 0; + stratum = inst->stratum; SRC_UpdateReachability(inst->source, 1); SRC_AccumulateSample(inst->source, &sample_time, offset, diff --git a/refclock.h b/refclock.h index 40ce12d..7508f3d 100644 --- a/refclock.h +++ b/refclock.h @@ -43,6 +43,7 @@ typedef struct { int max_samples; int sel_options; int max_lock_age; + int stratum; uint32_t ref_id; uint32_t lock_ref_id; double offset;