diff options
-rw-r--r-- | usr.sbin/ntpd/ntpd.conf.5 | 14 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.h | 4 | ||||
-rw-r--r-- | usr.sbin/ntpd/parse.y | 21 | ||||
-rw-r--r-- | usr.sbin/ntpd/sensors.c | 9 |
4 files changed, 39 insertions, 9 deletions
diff --git a/usr.sbin/ntpd/ntpd.conf.5 b/usr.sbin/ntpd/ntpd.conf.5 index c33c5e90ee4..72c87ce6aa4 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.16 2007/05/31 19:20:26 jmc Exp $ +.\" $OpenBSD: ntpd.conf.5,v 1.17 2007/09/12 21:08:45 ckuethe 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: May 31 2007 $ +.Dd $Mdocdate: September 12 2007 $ .Dt NTPD.CONF 5 .Os .Sh NAME @@ -71,6 +71,7 @@ listen on 127.0.0.1 listen on ::1 .Ed .It Xo Ic sensor Ar device +.Op Ic correction Ar microseconds .Op Ic weight Ar weight-value .Xc Specify a timedelta sensor device @@ -92,6 +93,15 @@ For example: sensor * sensor udcf0 .Ed +.Pp +An optional correction in microseconds can be given to compensate +for the sensor's offset. +The maximum correction is 127 seconds. +For example, if your DCF77 receiver is lagging 15 ms behind +actual time: +.Bd -literal -offset indent +sensor udcf0 correction 15000 +.Ed .It Xo Ic server Ar address .Op Ic weight Ar weight-value .Xc diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index daf17772670..9b841d79d81 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.85 2007/08/04 02:58:02 ckuethe Exp $ */ +/* $OpenBSD: ntpd.h,v 1.86 2007/09/12 21:08:46 ckuethe Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -141,6 +141,7 @@ struct ntp_sensor { time_t last; char *device; int sensordevid; + int correction; u_int8_t weight; u_int8_t shift; }; @@ -148,6 +149,7 @@ struct ntp_sensor { struct ntp_conf_sensor { TAILQ_ENTRY(ntp_conf_sensor) entry; char *device; + int correction; u_int8_t weight; }; diff --git a/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y index 2deaa62dba4..310440cd611 100644 --- a/usr.sbin/ntpd/parse.y +++ b/usr.sbin/ntpd/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.32 2007/09/12 18:32:54 deraadt Exp $ */ +/* $OpenBSD: parse.y,v 1.33 2007/09/12 21:08:46 ckuethe Exp $ */ /* * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -53,6 +53,7 @@ int yylex(void); struct opts { int weight; + int correction; } opts; typedef struct { @@ -68,13 +69,14 @@ typedef struct { %} %token LISTEN ON -%token SERVER SERVERS SENSOR WEIGHT +%token SERVER SERVERS SENSOR CORRECTION WEIGHT %token ERROR %token <v.string> STRING %token <v.number> NUMBER %type <v.addr> address %type <v.opts> server_opts server_opts_l server_opt %type <v.opts> sensor_opts sensor_opts_l sensor_opt +%type <v.opts> correction %type <v.opts> weight %% @@ -193,6 +195,7 @@ conf_main : LISTEN ON address { s = new_sensor($2); s->weight = $3.weight; + s->correction = $3.correction; free($2); TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry); } @@ -232,7 +235,18 @@ sensor_opts : { bzero(&opts, sizeof opts); opts.weight = 1; } sensor_opts_l : sensor_opts_l sensor_opt | sensor_opt ; -sensor_opt : weight +sensor_opt : correction + | weight + ; + +correction : CORRECTION NUMBER { + if ($2 < -127000000 || $2 > 127000000) { + yyerror("correction must be between " + "-127000000 and 127000000 microseconds"); + YYERROR; + } + opts.correction = $2; + } ; weight : WEIGHT NUMBER { @@ -278,6 +292,7 @@ lookup(char *s) { /* this has to be sorted always */ static const struct keywords keywords[] = { + { "correction", CORRECTION}, { "listen", LISTEN}, { "on", ON}, { "sensor", SENSOR}, diff --git a/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c index dde110f8f72..0e0c69f63ff 100644 --- a/usr.sbin/ntpd/sensors.c +++ b/usr.sbin/ntpd/sensors.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sensors.c,v 1.33 2007/08/04 02:58:02 ckuethe Exp $ */ +/* $OpenBSD: sensors.c,v 1.34 2007/09/12 21:08:46 ckuethe Exp $ */ /* * Copyright (c) 2006 Henning Brauer <henning@openbsd.org> @@ -121,13 +121,15 @@ sensor_add(int sensordev, char *dxname) s->next = getmonotime(); s->weight = cs->weight; + s->correction = cs->correction; if ((s->device = strdup(dxname)) == NULL) fatal("sensor_add strdup"); s->sensordevid = sensordev; TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry); - log_debug("sensor %s added", s->device); + log_debug("sensor %s added (weight %d, correction %.6f)", + s->device, s->weight, s->correction / 1e6); } void @@ -176,7 +178,8 @@ sensor_query(struct ntp_sensor *s) * sensor.value = TS - TD in ns * if value is positive, system time is ahead */ - s->offsets[s->shift].offset = (sensor.value / -1e9) - getoffset(); + s->offsets[s->shift].offset = (sensor.value / -1e9) - getoffset() + + (s->correction / 1e6); s->offsets[s->shift].rcvd = sensor.tv.tv_sec; s->offsets[s->shift].good = 1; |