Browse Source

allow for weight to be added to sensors or servers, so that one can

weight timedelta sensors higher than ntp peers, for example
ok deraadt mbalmer
OPENBSD_4_0
henning 18 years ago
parent
commit
52daf64bf5
4 changed files with 50 additions and 14 deletions
  1. +8
    -6
      src/usr.sbin/ntpd/ntp.c
  2. +4
    -1
      src/usr.sbin/ntpd/ntpd.h
  3. +36
    -6
      src/usr.sbin/ntpd/parse.y
  4. +2
    -1
      src/usr.sbin/ntpd/sensors.c

+ 8
- 6
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.76 2006/05/28 18:47:25 henning Exp $ */
/* $OpenBSD: ntp.c,v 1.77 2006/05/28 20:39:16 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -422,7 +422,7 @@ priv_adjtime(void)
{
struct ntp_peer *p;
struct ntp_sensor *s;
int offset_cnt = 0, i = 0;
int offset_cnt = 0, i = 0, j;
struct ntp_offset **offsets;
double offset_median;
@ -431,13 +431,13 @@ priv_adjtime(void)
continue;
if (!p->update.good)
return;
offset_cnt++;
offset_cnt += p->weight;
}
TAILQ_FOREACH(s, &conf->ntp_sensors, entry) {
if (!s->update.good)
continue;
offset_cnt++;
offset_cnt += p->weight;
}
if ((offsets = calloc(offset_cnt, sizeof(struct ntp_offset *))) == NULL)
@ -446,13 +446,15 @@ priv_adjtime(void)
TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
if (p->trustlevel < TRUSTLEVEL_BADPEER)
continue;
offsets[i++] = &p->update;
for (j = 0; j < p->weight; j++)
offsets[i++] = &p->update;
}
TAILQ_FOREACH(s, &conf->ntp_sensors, entry) {
if (!s->update.good)
continue;
offsets[i++] = &s->update;
for (j = 0; j < s->weight; j++)
offsets[i++] = &s->update;
}
qsort(offsets, offset_cnt, sizeof(struct ntp_offset *), offset_compare);


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.68 2006/05/28 18:47:25 henning Exp $ */
/* $OpenBSD: ntpd.h,v 1.69 2006/05/28 20:39:16 henning Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -124,6 +124,7 @@ struct ntp_peer {
u_int32_t id;
u_int8_t shift;
u_int8_t trustlevel;
u_int8_t weight;
int lasterror;
};
@ -133,11 +134,13 @@ struct ntp_sensor {
time_t next;
char *device;
int sensorid;
u_int8_t weight;
};
struct ntp_conf_sensor {
TAILQ_ENTRY(ntp_conf_sensor) entry;
char *device;
u_int8_t weight;
};
struct ntpd_conf {


+ 36
- 6
src/usr.sbin/ntpd/parse.y View File

@ -1,4 +1,4 @@
/* $OpenBSD: parse.y,v 1.27 2006/05/27 17:01:07 henning Exp $ */
/* $OpenBSD: parse.y,v 1.28 2006/05/28 20:39:16 henning Exp $ */
/*
* Copyright (c) 2002, 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -62,10 +62,11 @@ typedef struct {
%}
%token LISTEN ON
%token SERVER SERVERS SENSOR
%token SERVER SERVERS SENSOR WEIGHT
%token ERROR
%token <v.string> STRING
%type <v.addr> address
%type <v.number> number weight
%%
grammar : /* empty */
@ -106,7 +107,7 @@ conf_main : LISTEN ON address {
free($3->name);
free($3);
}
| SERVERS address {
| SERVERS address weight {
struct ntp_peer *p;
struct ntp_addr *h, *next;
@ -128,6 +129,7 @@ conf_main : LISTEN ON address {
next = NULL;
p = new_peer();
p->weight = $3;
p->addr = h;
p->addr_head.a = h;
p->addr_head.pool = 1;
@ -144,7 +146,7 @@ conf_main : LISTEN ON address {
free($2->name);
free($2);
}
| SERVER address {
| SERVER address weight {
struct ntp_peer *p;
struct ntp_addr *h, *next;
@ -165,6 +167,7 @@ conf_main : LISTEN ON address {
p->addr = h;
}
p->weight = $3;
p->addr_head.a = p->addr;
p->addr_head.pool = 0;
p->addr_head.name = strdup($2->name);
@ -176,10 +179,11 @@ conf_main : LISTEN ON address {
free($2->name);
free($2);
}
| SENSOR STRING {
| SENSOR STRING weight {
struct ntp_conf_sensor *s;
s = new_sensor($2);
s->weight = $3;
free($2);
TAILQ_INSERT_TAIL(&conf->ntp_conf_sensors, s, entry);
}
@ -200,6 +204,31 @@ address : STRING {
}
;
number : STRING {
u_long ulval;
const char *errstr;
ulval = strtonum($1, 0, ULONG_MAX, &errstr);
if (errstr) {
yyerror("\"%s\" invalid: %s", $1, errstr);
free($1);
YYERROR;
} else
$$ = ulval;
free($1);
}
;
weight : /* empty */ { $$ = 1; }
| WEIGHT number {
if ($2 < 1 || $2 > 10) {
yyerror("weight must be between 1 and 10");
YYERROR;
}
$$ = $2;
}
;
%%
struct keywords {
@ -238,7 +267,8 @@ lookup(char *s)
{ "on", ON},
{ "sensor", SENSOR},
{ "server", SERVER},
{ "servers", SERVERS}
{ "servers", SERVERS},
{ "weight", WEIGHT}
};
const struct keywords *p;


+ 2
- 1
src/usr.sbin/ntpd/sensors.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: sensors.c,v 1.14 2006/05/28 19:04:37 henning Exp $ */
/* $OpenBSD: sensors.c,v 1.15 2006/05/28 20:39:16 henning Exp $ */
/*
* Copyright (c) 2006 Henning Brauer <henning@openbsd.org>
@ -101,6 +101,7 @@ sensor_add(struct sensor *sensor)
fatal("sensor_add calloc");
s->next = time(NULL);
s->weight = cs->weight;
if ((s->device = strdup(sensor->device)) == NULL)
fatal("sensor_add strdup");
s->sensorid = sensor->num;


Loading…
Cancel
Save