diff options
author | Patrick Wildt <patrick@cvs.openbsd.org> | 2012-09-20 12:43:17 +0000 |
---|---|---|
committer | Patrick Wildt <patrick@cvs.openbsd.org> | 2012-09-20 12:43:17 +0000 |
commit | 9759a4bd398b4827fe9a4abb3c00fda6e5972413 (patch) | |
tree | 2c35a1f38f27085b5655f39a4b0f3a4de2b4b4b4 | |
parent | 1a362664c74f5dff3886e0e6e93e56c347204b90 (diff) |
Allow ntpd.conf to assign a stratum to a sensor with the syntax stratum <level>.
OK markus@ henning@ phessler@ jmc@
-rw-r--r-- | usr.sbin/ntpd/ntpd.conf.5 | 8 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.h | 4 | ||||
-rw-r--r-- | usr.sbin/ntpd/parse.y | 20 | ||||
-rw-r--r-- | usr.sbin/ntpd/sensors.c | 11 |
4 files changed, 34 insertions, 9 deletions
diff --git a/usr.sbin/ntpd/ntpd.conf.5 b/usr.sbin/ntpd/ntpd.conf.5 index ca000971133..3e8020ba41b 100644 --- a/usr.sbin/ntpd/ntpd.conf.5 +++ b/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 <henning@openbsd.org> .\" @@ -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/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index 5e8c242b4e8..80ac74042ba 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/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 <henning@openbsd.org> @@ -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/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y index c2ee9df6741..ee94a7b847c 100644 --- a/usr.sbin/ntpd/parse.y +++ b/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 <henning@openbsd.org> @@ -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 <v.string> STRING %token <v.number> NUMBER @@ -89,6 +90,7 @@ typedef struct { %type <v.opts> correction %type <v.opts> rtable %type <v.opts> refid +%type <v.opts> stratum %type <v.opts> 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/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c index 839f90abd09..571b0c9ea0a 100644 --- a/usr.sbin/ntpd/sensors.c +++ b/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 <henning@openbsd.org> @@ -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; |