Browse Source

Add a knob to compensate for a refclock that is early or late. Based on a


OPENBSD_4_3
ckuethe 17 years ago
parent
commit
4f75588722
4 changed files with 39 additions and 9 deletions
  1. +12
    -2
      src/usr.sbin/ntpd/ntpd.conf.5
  2. +3
    -1
      src/usr.sbin/ntpd/ntpd.h
  3. +18
    -3
      src/usr.sbin/ntpd/parse.y
  4. +6
    -3
      src/usr.sbin/ntpd/sensors.c

+ 12
- 2
src/usr.sbin/ntpd/ntpd.conf.5 View File

@ -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


+ 3
- 1
src/usr.sbin/ntpd/ntpd.h View File

@ -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;
};


+ 18
- 3
src/usr.sbin/ntpd/parse.y View File

@ -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},


+ 6
- 3
src/usr.sbin/ntpd/sensors.c View File

@ -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;


Loading…
Cancel
Save