diff options
author | Chris Kuethe <ckuethe@cvs.openbsd.org> | 2008-06-09 16:37:36 +0000 |
---|---|---|
committer | Chris Kuethe <ckuethe@cvs.openbsd.org> | 2008-06-09 16:37:36 +0000 |
commit | 06cbd28a8803f79ee46baf228b998ff7482ec318 (patch) | |
tree | 42f53f5b7de6a649bef8f280c2c84e5dc4eeb91d /usr.sbin/ntpd | |
parent | b77829a82ea87b9804631ca7a4ff3c3e6d3ac074 (diff) |
Allow outgoing replies from sensor-driven servers to have a
user-configurable reference ID, eg. "GPS" or "DCF"...
ok mbalmer
Diffstat (limited to 'usr.sbin/ntpd')
-rw-r--r-- | usr.sbin/ntpd/ntpd.conf.5 | 17 | ||||
-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 | 21 |
4 files changed, 50 insertions, 13 deletions
diff --git a/usr.sbin/ntpd/ntpd.conf.5 b/usr.sbin/ntpd/ntpd.conf.5 index 576c3f964fa..fae3457e1c0 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.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 diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index 2c076fa777b..f438ec5bcf6 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -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; }; diff --git a/usr.sbin/ntpd/parse.y b/usr.sbin/ntpd/parse.y index ea9357a8b19..252ee7e87e1 100644 --- a/usr.sbin/ntpd/parse.y +++ b/usr.sbin/ntpd/parse.y @@ -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}, diff --git a/usr.sbin/ntpd/sensors.c b/usr.sbin/ntpd/sensors.c index 65b3534b9fb..debd510481a 100644 --- a/usr.sbin/ntpd/sensors.c +++ b/usr.sbin/ntpd/sensors.c @@ -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; |