Browse Source

Allow ntpd.conf to assign a stratum to a sensor with the syntax stratum <level>.

OK markus@ henning@ phessler@ jmc@
OPENBSD_5_3
patrick 12 years ago
parent
commit
bb4b345cc6
4 changed files with 34 additions and 9 deletions
  1. +6
    -2
      src/usr.sbin/ntpd/ntpd.conf.5
  2. +3
    -1
      src/usr.sbin/ntpd/ntpd.h
  3. +18
    -2
      src/usr.sbin/ntpd/parse.y
  4. +7
    -4
      src/usr.sbin/ntpd/sensors.c

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

@ -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> .\" Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
.\" .\"
@ -14,7 +14,7 @@
.\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT .\" AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
.\" OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. .\" 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 .Dt NTPD.CONF 5
.Os .Os
.Sh NAME .Sh NAME
@ -72,6 +72,7 @@ listen on 127.0.0.1 rtable 4
.Op Ic correction Ar microseconds .Op Ic correction Ar microseconds
.Op Ic weight Ar weight-value .Op Ic weight Ar weight-value
.Op Ic refid Ar string .Op Ic refid Ar string
.Op Ic stratum Ar stratum-value
.Xc .Xc
Specify a timedelta sensor device Specify a timedelta sensor device
.Xr ntpd 8 .Xr ntpd 8
@ -124,6 +125,9 @@ For example:
.Bd -literal -offset indent .Bd -literal -offset indent
sensor nmea0 refid GPS sensor nmea0 refid GPS
.Ed .Ed
.Pp
A stratum value other than the default of 1 can be assigned using
the stratum keyword.
.It Xo Ic server Ar address .It Xo Ic server Ar address
.Op Ic weight Ar weight-value .Op Ic weight Ar weight-value
.Op Ic rtable Ar table-id .Op Ic rtable Ar table-id


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

@ -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> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -147,6 +147,7 @@ struct ntp_sensor {
u_int32_t refid; u_int32_t refid;
int sensordevid; int sensordevid;
int correction; int correction;
u_int8_t stratum;
u_int8_t weight; u_int8_t weight;
u_int8_t shift; u_int8_t shift;
}; };
@ -156,6 +157,7 @@ struct ntp_conf_sensor {
char *device; char *device;
char *refstr; char *refstr;
int correction; int correction;
u_int8_t stratum;
u_int8_t weight; u_int8_t weight;
}; };


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

@ -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> * Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -60,6 +60,7 @@ struct ntpd_conf *conf;
struct opts { struct opts {
int weight; int weight;
int correction; int correction;
int stratum;
int rtable; int rtable;
char *refstr; char *refstr;
} opts; } opts;
@ -78,7 +79,7 @@ typedef struct {
%} %}
%token LISTEN ON %token LISTEN ON
%token SERVER SERVERS SENSOR CORRECTION RTABLE REFID WEIGHT
%token SERVER SERVERS SENSOR CORRECTION RTABLE REFID STRATUM WEIGHT
%token ERROR %token ERROR
%token <v.string> STRING %token <v.string> STRING
%token <v.number> NUMBER %token <v.number> NUMBER
@ -89,6 +90,7 @@ typedef struct {
%type <v.opts> correction %type <v.opts> correction
%type <v.opts> rtable %type <v.opts> rtable
%type <v.opts> refid %type <v.opts> refid
%type <v.opts> stratum
%type <v.opts> weight %type <v.opts> weight
%% %%
@ -213,6 +215,7 @@ main : LISTEN ON address listen_opts {
s->weight = $3.weight; s->weight = $3.weight;
s->correction = $3.correction; s->correction = $3.correction;
s->refstr = $3.refstr; s->refstr = $3.refstr;
s->stratum = $3.stratum;
free($2); free($2);
TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry); TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry);
} }
@ -266,6 +269,7 @@ sensor_opts_l : sensor_opts_l sensor_opt
; ;
sensor_opt : correction sensor_opt : correction
| refid | refid
| stratum
| weight | 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 { weight : WEIGHT NUMBER {
if ($2 < 1 || $2 > 10) { if ($2 < 1 || $2 > 10) {
yyerror("weight must be between 1 and 10"); yyerror("weight must be between 1 and 10");
@ -315,6 +329,7 @@ opts_default(void)
bzero(&opts, sizeof opts); bzero(&opts, sizeof opts);
opts.weight = 1; opts.weight = 1;
opts.rtable = -1; opts.rtable = -1;
opts.stratum = 1;
} }
struct keywords { struct keywords {
@ -357,6 +372,7 @@ lookup(char *s)
{ "sensor", SENSOR}, { "sensor", SENSOR},
{ "server", SERVER}, { "server", SERVER},
{ "servers", SERVERS}, { "servers", SERVERS},
{ "stratum", STRATUM},
{ "weight", WEIGHT} { "weight", WEIGHT}
}; };
const struct keywords *p; const struct keywords *p;


+ 7
- 4
src/usr.sbin/ntpd/sensors.c View File

@ -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> * Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -134,6 +134,7 @@ sensor_add(int sensordev, char *dxname)
s->next = getmonotime(); s->next = getmonotime();
s->weight = cs->weight; s->weight = cs->weight;
s->correction = cs->correction; s->correction = cs->correction;
s->stratum = cs->stratum - 1;
if ((s->device = strdup(dxname)) == NULL) if ((s->device = strdup(dxname)) == NULL)
fatal("sensor_add strdup"); fatal("sensor_add strdup");
s->sensordevid = sensordev; s->sensordevid = sensordev;
@ -147,8 +148,9 @@ sensor_add(int sensordev, char *dxname)
TAILQ_INSERT_TAIL(&conf->ntp_sensors, s, entry); 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 void
@ -204,7 +206,8 @@ sensor_query(struct ntp_sensor *s)
s->offsets[s->shift].good = 1; s->offsets[s->shift].good = 1;
s->offsets[s->shift].status.send_refid = s->refid; 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.rootdelay = 0;
s->offsets[s->shift].status.rootdispersion = 0; s->offsets[s->shift].status.rootdispersion = 0;
s->offsets[s->shift].status.reftime = sensor.tv.tv_sec; s->offsets[s->shift].status.reftime = sensor.tv.tv_sec;


Loading…
Cancel
Save