Browse Source

Allow outgoing replies from sensor-driven servers to have a

user-configurable reference ID, eg. "GPS" or "DCF"...
ok mbalmer
OPENBSD_4_4
ckuethe 16 years ago
parent
commit
e6e5dc66c8
4 changed files with 50 additions and 13 deletions
  1. +15
    -2
      src/usr.sbin/ntpd/ntpd.conf.5
  2. +3
    -1
      src/usr.sbin/ntpd/ntpd.h
  3. +19
    -2
      src/usr.sbin/ntpd/parse.y
  4. +13
    -8
      src/usr.sbin/ntpd/sensors.c

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

@ -1,4 +1,4 @@
.\" $OpenBSD: ntpd.conf.5,v 1.19 2007/09/13 07:28:32 jmc Exp $
.\" $OpenBSD: ntpd.conf.5,v 1.20 2008/06/09 16:37:35 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: September 13 2007 $
.Dd $Mdocdate: June 9 2008 $
.Dt NTPD.CONF 5
.Os
.Sh NAME
@ -73,6 +73,7 @@ listen on ::1
.It Xo Ic sensor Ar device
.Op Ic correction Ar microseconds
.Op Ic weight Ar weight-value
.Op Ic refid Ar string
.Xc
Specify a timedelta sensor device
.Xr ntpd 8
@ -102,6 +103,18 @@ actual time:
.Bd -literal -offset indent
sensor udcf0 correction 15000
.Ed
.Pp
An optional reference ID string - up to 4 ASCII characters - can be
given to publish the sensor type to clients.
RFC 2030 suggests some common reference identifiers, but new identifiers
"can be contrived as appropriate."
If an ID string is not given,
.Xr ntpd 8
will use a generic reference ID.
For example:
.Bd -literal -offset indent
sensor msts0 refid GPS
.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.92 2008/05/16 06:13:25 ckuethe Exp $ */
/* $OpenBSD: ntpd.h,v 1.93 2008/06/09 16:37:35 ckuethe Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -140,6 +140,7 @@ struct ntp_sensor {
time_t next;
time_t last;
char *device;
u_int32_t refstr;
int sensordevid;
int correction;
u_int8_t weight;
@ -149,6 +150,7 @@ struct ntp_sensor {
struct ntp_conf_sensor {
TAILQ_ENTRY(ntp_conf_sensor) entry;
char *device;
char *refstr;
int correction;
u_int8_t weight;
};


+ 19
- 2
src/usr.sbin/ntpd/parse.y View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.42 2008/02/26 10:09:58 mpf Exp $ */
/* $OpenBSD: parse.y,v 1.43 2008/06/09 16:37:35 ckuethe 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;
char *refstr;
} opts;
void opts_default(void);
@ -76,7 +77,7 @@ typedef struct {
%}
%token LISTEN ON
%token SERVER SERVERS SENSOR CORRECTION WEIGHT
%token SERVER SERVERS SENSOR CORRECTION REFID WEIGHT
%token ERROR
%token <v.string> STRING
%token <v.number> NUMBER
@ -84,6 +85,7 @@ typedef struct {
%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> refid
%type <v.opts> weight
%%
@ -203,6 +205,7 @@ main : LISTEN ON address {
s = new_sensor($2);
s->weight = $3.weight;
s->correction = $3.correction;
s->refstr = $3.refstr;
free($2);
TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry);
}
@ -243,6 +246,7 @@ sensor_opts_l : sensor_opts_l sensor_opt
| sensor_opt
;
sensor_opt : correction
| refid
| weight
;
@ -256,6 +260,18 @@ correction : CORRECTION NUMBER {
}
;
refid : REFID STRING {
size_t l;
l = strlen($2);
if (l < 1 || l > 4) {
yyerror("refid must be a string of 1 to 4 "
"characters");
YYERROR;
}
opts.refstr = $2;
}
;
weight : WEIGHT NUMBER {
if ($2 < 1 || $2 > 10) {
yyerror("weight must be between 1 and 10");
@ -309,6 +325,7 @@ lookup(char *s)
{ "correction", CORRECTION},
{ "listen", LISTEN},
{ "on", ON},
{ "refid", REFID},
{ "sensor", SENSOR},
{ "server", SERVER},
{ "servers", SERVERS},


+ 13
- 8
src/usr.sbin/ntpd/sensors.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sensors.c,v 1.35 2008/03/02 20:36:42 ckuethe Exp $ */
/* $OpenBSD: sensors.c,v 1.36 2008/06/09 16:37:35 ckuethe Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -25,6 +25,7 @@
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
@ -108,7 +109,7 @@ sensor_add(int sensordev, char *dxname)
if (!strcmp(s->device, dxname))
return;
/* check wether it is requested in the config file */
/* check whether it is requested in the config file */
for (cs = TAILQ_FIRST(&conf->ntp_conf_sensors); cs != NULL &&
strcmp(cs->device, dxname) && strcmp(cs->device, "*");
cs = TAILQ_NEXT(cs, entry))
@ -126,10 +127,16 @@ sensor_add(int sensordev, char *dxname)
fatal("sensor_add strdup");
s->sensordevid = sensordev;
if (cs->refstr == NULL)
memcpy(&s->refstr, "HARD", sizeof(s->refstr));
else
memcpy(&s->refstr, cs->refstr, sizeof(s->refstr));
TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry);
log_debug("sensor %s added (weight %d, correction %.6f)",
s->device, s->weight, s->correction / 1e6);
log_debug("sensor %s added (weight %d, correction %.6f, refstr %-4s)",
s->device, s->weight, s->correction / 1e6, &s->refstr);
s->refstr = htonl(s->refstr);
}
void
@ -145,7 +152,6 @@ sensor_query(struct ntp_sensor *s)
{
char dxname[MAXDEVNAMLEN];
struct sensor sensor;
u_int32_t refid;
s->next = getmonotime() + SENSOR_QUERY_INTERVAL;
@ -171,7 +177,6 @@ sensor_query(struct ntp_sensor *s)
return;
s->last = sensor.tv.tv_sec;
memcpy(&refid, "HARD", sizeof(refid));
/*
* TD = device time
* TS = system time
@ -183,8 +188,8 @@ sensor_query(struct ntp_sensor *s)
s->offsets[s->shift].rcvd = sensor.tv.tv_sec;
s->offsets[s->shift].good = 1;
s->offsets[s->shift].status.refid = htonl(refid);
s->offsets[s->shift].status.refid4 = htonl(refid);
s->offsets[s->shift].status.refid = s->refstr;
s->offsets[s->shift].status.refid4 = s->refstr;
s->offsets[s->shift].status.stratum = 0; /* increased when sent out */
s->offsets[s->shift].status.rootdelay = 0;
s->offsets[s->shift].status.rootdispersion = 0;


Loading…
Cancel
Save