diff --git a/src/usr.sbin/ntpd/ntpd.conf.5 b/src/usr.sbin/ntpd/ntpd.conf.5 index ca000971..3e8020ba 100644 --- a/src/usr.sbin/ntpd/ntpd.conf.5 +++ b/src/usr.sbin/ntpd/ntpd.conf.5 @@ -1,4 +1,4 @@ -.\" $OpenBSD: ntpd.conf.5,v 1.23 2011/09/21 15:41:30 phessler Exp $ +.\" $OpenBSD: ntpd.conf.5,v 1.24 2012/09/20 12:43:16 patrick Exp $ .\" .\" Copyright (c) 2003, 2004 Henning Brauer .\" @@ -14,7 +14,7 @@ .\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT .\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" -.Dd $Mdocdate: September 21 2011 $ +.Dd $Mdocdate: September 20 2012 $ .Dt NTPD.CONF 5 .Os .Sh NAME @@ -72,6 +72,7 @@ listen on 127.0.0.1 rtable 4 .Op Ic correction Ar microseconds .Op Ic weight Ar weight-value .Op Ic refid Ar string +.Op Ic stratum Ar stratum-value .Xc Specify a timedelta sensor device .Xr ntpd 8 @@ -124,6 +125,9 @@ For example: .Bd -literal -offset indent sensor nmea0 refid GPS .Ed +.Pp +A stratum value other than the default of 1 can be assigned using +the stratum keyword. .It Xo Ic server Ar address .Op Ic weight Ar weight-value .Op Ic rtable Ar table-id diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index 5e8c242b..80ac7404 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.105 2011/09/21 16:38:05 phessler Exp $ */ +/* $OpenBSD: ntpd.h,v 1.106 2012/09/20 12:43:16 patrick Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -147,6 +147,7 @@ struct ntp_sensor { u_int32_t refid; int sensordevid; int correction; + u_int8_t stratum; u_int8_t weight; u_int8_t shift; }; @@ -156,6 +157,7 @@ struct ntp_conf_sensor { char *device; char *refstr; int correction; + u_int8_t stratum; u_int8_t weight; }; diff --git a/src/usr.sbin/ntpd/parse.y b/src/usr.sbin/ntpd/parse.y index c2ee9df6..ee94a7b8 100644 --- a/src/usr.sbin/ntpd/parse.y +++ b/src/usr.sbin/ntpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.49 2011/12/28 19:32:34 phessler Exp $ */ +/* $OpenBSD: parse.y,v 1.50 2012/09/20 12:43:16 patrick Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer @@ -60,6 +60,7 @@ struct ntpd_conf *conf; struct opts { int weight; int correction; + int stratum; int rtable; char *refstr; } opts; @@ -78,7 +79,7 @@ typedef struct { %} %token LISTEN ON -%token SERVER SERVERS SENSOR CORRECTION RTABLE REFID WEIGHT +%token SERVER SERVERS SENSOR CORRECTION RTABLE REFID STRATUM WEIGHT %token ERROR %token STRING %token NUMBER @@ -89,6 +90,7 @@ typedef struct { %type correction %type rtable %type refid +%type stratum %type weight %% @@ -213,6 +215,7 @@ main : LISTEN ON address listen_opts { s->weight = $3.weight; s->correction = $3.correction; s->refstr = $3.refstr; + s->stratum = $3.stratum; free($2); TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry); } @@ -266,6 +269,7 @@ sensor_opts_l : sensor_opts_l sensor_opt ; sensor_opt : correction | refid + | stratum | weight ; @@ -291,6 +295,16 @@ refid : REFID STRING { } ; +stratum : STRATUM NUMBER { + if ($2 < 1 || $2 > 15) { + yyerror("stratum must be between " + "1 and 15"); + YYERROR; + } + opts.stratum = $2; + } + ; + weight : WEIGHT NUMBER { if ($2 < 1 || $2 > 10) { yyerror("weight must be between 1 and 10"); @@ -315,6 +329,7 @@ opts_default(void) bzero(&opts, sizeof opts); opts.weight = 1; opts.rtable = -1; + opts.stratum = 1; } struct keywords { @@ -357,6 +372,7 @@ lookup(char *s) { "sensor", SENSOR}, { "server", SERVER}, { "servers", SERVERS}, + { "stratum", STRATUM}, { "weight", WEIGHT} }; const struct keywords *p; diff --git a/src/usr.sbin/ntpd/sensors.c b/src/usr.sbin/ntpd/sensors.c index 839f90ab..571b0c9e 100644 --- a/src/usr.sbin/ntpd/sensors.c +++ b/src/usr.sbin/ntpd/sensors.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sensors.c,v 1.45 2010/04/20 20:49:36 deraadt Exp $ */ +/* $OpenBSD: sensors.c,v 1.46 2012/09/20 12:43:16 patrick Exp $ */ /* * Copyright (c) 2006 Henning Brauer @@ -134,6 +134,7 @@ sensor_add(int sensordev, char *dxname) s->next = getmonotime(); s->weight = cs->weight; s->correction = cs->correction; + s->stratum = cs->stratum - 1; if ((s->device = strdup(dxname)) == NULL) fatal("sensor_add strdup"); s->sensordevid = sensordev; @@ -147,8 +148,9 @@ sensor_add(int sensordev, char *dxname) TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry); - log_debug("sensor %s added (weight %d, correction %.6f, refstr %.4s)", - s->device, s->weight, s->correction / 1e6, &s->refid); + log_debug("sensor %s added (weight %d, correction %.6f, refstr %.4s, " + "stratum %d)", s->device, s->weight, s->correction / 1e6, + &s->refid, s->stratum); } void @@ -204,7 +206,8 @@ sensor_query(struct ntp_sensor *s) s->offsets[s->shift].good = 1; s->offsets[s->shift].status.send_refid = s->refid; - s->offsets[s->shift].status.stratum = 0; /* increased when sent out */ + /* stratum increased when sent out */ + s->offsets[s->shift].status.stratum = s->stratum; s->offsets[s->shift].status.rootdelay = 0; s->offsets[s->shift].status.rootdispersion = 0; s->offsets[s->shift].status.reftime = sensor.tv.tv_sec;