Browse Source

Simplify interval scaling and randomize query intervals; ok henning@

OPENBSD_3_7
dtucker 20 years ago
parent
commit
21a049e79f
3 changed files with 21 additions and 14 deletions
  1. +3
    -3
      src/usr.sbin/ntpd/client.c
  2. +17
    -9
      src/usr.sbin/ntpd/ntp.c
  3. +1
    -2
      src/usr.sbin/ntpd/ntpd.h

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

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.54 2005/01/28 12:01:32 dtucker Exp $ */
/* $OpenBSD: client.c,v 1.55 2005/01/28 12:37:20 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -242,9 +242,9 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
p->reply[p->shift].status.stratum = msg.stratum;
if (p->trustlevel < TRUSTLEVEL_PATHETIC)
interval = INTERVAL_QUERY_PATHETIC;
interval = scale_interval(INTERVAL_QUERY_PATHETIC);
else if (p->trustlevel < TRUSTLEVEL_AGRESSIVE)
interval = INTERVAL_QUERY_AGRESSIVE;
interval = scale_interval(INTERVAL_QUERY_AGRESSIVE);
else
interval = scale_interval(INTERVAL_QUERY_NORMAL);


+ 17
- 9
src/usr.sbin/ntpd/ntp.c View File

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.48 2005/01/27 14:44:00 dtucker Exp $ */
/* $OpenBSD: ntp.c,v 1.49 2005/01/28 12:37:20 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -143,7 +143,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
b = 1000000000 / tp.tv_nsec; /* convert to Hz */
for (a = 0; b > 1; a--, b >>= 1);
conf->status.precision = a;
conf->scale = QSCALE_FACTOR;
conf->scale = 1;
log_info("ntp engine ready");
@ -465,22 +465,30 @@ update_scale(double offset)
offset = -offset;
if (offset > QSCALE_OFF_MAX)
conf->scale = QSCALE_FACTOR;
conf->scale = 1;
else if (offset < QSCALE_OFF_MIN)
conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
conf->scale = QSCALE_OFF_MAX / QSCALE_OFF_MIN;
else
conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / offset;
conf->scale = QSCALE_OFF_MAX / offset;
}
time_t
scale_interval(time_t requested)
{
return (requested * conf->scale / QSCALE_FACTOR);
time_t interval, r;
interval = requested * conf->scale;
r = arc4random() % MAX(5, interval / 10);
return (interval + r);
}
time_t
error_interval(void)
error_interval(void)
{
return (INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN);
time_t interval, r;
interval = INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
r = arc4random() % (interval / 10);
return (interval + r);
}

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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.50 2005/01/27 14:44:00 dtucker Exp $ */
/* $OpenBSD: ntpd.h,v 1.51 2005/01/28 12:37:20 dtucker Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -51,7 +51,6 @@
#define QSCALE_OFF_MIN 0.05
#define QSCALE_OFF_MAX 0.50
#define QSCALE_FACTOR 1000
#define QUERYTIME_MAX 15 /* single query might take n secs max */
#define OFFSET_ARRAY_SIZE 8


Loading…
Cancel
Save