Browse Source

Scale query interval by the overall offset not per-peer offset, so we

don't query outliers more often than any other server.  ok henning@
OPENBSD_3_7
dtucker 20 years ago
parent
commit
270c434643
3 changed files with 43 additions and 27 deletions
  1. +6
    -22
      src/usr.sbin/ntpd/client.c
  2. +31
    -3
      src/usr.sbin/ntpd/ntp.c
  3. +6
    -2
      src/usr.sbin/ntpd/ntpd.h

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

@ -1,4 +1,4 @@
/* $OpenBSD: client.c,v 1.52 2005/01/27 10:32:29 dtucker Exp $ */
/* $OpenBSD: client.c,v 1.53 2005/01/27 14:44:00 dtucker Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -43,20 +43,6 @@ set_deadline(struct ntp_peer *p, time_t t)
p->next = 0; p->next = 0;
} }
time_t
scale_interval(time_t requested, double offset)
{
if (offset < 0)
offset = -offset;
if (offset > QSCALE_OFF_MAX)
return (requested);
else if (offset < QSCALE_OFF_MIN)
return (requested * (QSCALE_OFF_MAX / QSCALE_OFF_MIN));
else
return (requested * (QSCALE_OFF_MAX / offset));
}
int int
client_peer_init(struct ntp_peer *p) client_peer_init(struct ntp_peer *p)
{ {
@ -128,7 +114,7 @@ client_query(struct ntp_peer *p)
int tos = IPTOS_LOWDELAY; int tos = IPTOS_LOWDELAY;
if (p->addr == NULL && client_nextaddr(p) == -1) { if (p->addr == NULL && client_nextaddr(p) == -1) {
set_next(p, INTERVAL_QUERY_PATHETIC);
set_next(p, error_interval());
return (-1); return (-1);
} }
@ -142,7 +128,7 @@ client_query(struct ntp_peer *p)
if (errno == ECONNREFUSED || errno == ENETUNREACH || if (errno == ECONNREFUSED || errno == ENETUNREACH ||
errno == EHOSTUNREACH) { errno == EHOSTUNREACH) {
client_nextaddr(p); client_nextaddr(p);
set_next(p, INTERVAL_QUERY_PATHETIC);
set_next(p, error_interval());
return (-1); return (-1);
} else } else
fatal("client_query connect"); fatal("client_query connect");
@ -197,8 +183,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
errno == ENETDOWN || errno == ECONNREFUSED) { errno == ENETDOWN || errno == ECONNREFUSED) {
log_warn("recvfrom %s", log_warn("recvfrom %s",
log_sockaddr((struct sockaddr *)&p->addr->ss)); log_sockaddr((struct sockaddr *)&p->addr->ss));
interval = scale_interval(INTERVAL_QUERY_PATHETIC, 0.0);
set_next(p, interval);
set_next(p, error_interval());
return (0); return (0);
} else } else
fatal("recvfrom"); fatal("recvfrom");
@ -214,7 +199,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
if ((msg.status & LI_ALARM) == LI_ALARM || msg.stratum == 0 || if ((msg.status & LI_ALARM) == LI_ALARM || msg.stratum == 0 ||
msg.stratum > NTP_MAXSTRATUM) { msg.stratum > NTP_MAXSTRATUM) {
interval = scale_interval(INTERVAL_QUERY_PATHETIC, 0.0);
interval = error_interval();
set_next(p, interval); set_next(p, interval);
log_info("reply from %s: not synced, next query %ds", log_info("reply from %s: not synced, next query %ds",
log_sockaddr((struct sockaddr *)&p->addr->ss), interval); log_sockaddr((struct sockaddr *)&p->addr->ss), interval);
@ -260,8 +245,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
else if (p->trustlevel < TRUSTLEVEL_AGRESSIVE) else if (p->trustlevel < TRUSTLEVEL_AGRESSIVE)
interval = INTERVAL_QUERY_AGRESSIVE; interval = INTERVAL_QUERY_AGRESSIVE;
else else
interval = scale_interval(INTERVAL_QUERY_NORMAL,
p->reply[p->shift].offset);
interval = scale_interval(INTERVAL_QUERY_NORMAL);
set_next(p, interval); set_next(p, interval);
p->state = STATE_REPLY_RECEIVED; p->state = STATE_REPLY_RECEIVED;


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

@ -1,4 +1,4 @@
/* $OpenBSD: ntp.c,v 1.47 2005/01/27 10:32:29 dtucker Exp $ */
/* $OpenBSD: ntp.c,v 1.48 2005/01/27 14:44:00 dtucker Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -143,6 +143,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
b = 1000000000 / tp.tv_nsec; /* convert to Hz */ b = 1000000000 / tp.tv_nsec; /* convert to Hz */
for (a = 0; b > 1; a--, b >>= 1); for (a = 0; b > 1; a--, b >>= 1);
conf->status.precision = a; conf->status.precision = a;
conf->scale = QSCALE_FACTOR;
log_info("ntp engine ready"); log_info("ntp engine ready");
@ -199,8 +200,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf)
if (p->deadline > 0 && p->deadline < nextaction) if (p->deadline > 0 && p->deadline < nextaction)
nextaction = p->deadline; nextaction = p->deadline;
if (p->deadline > 0 && p->deadline <= time(NULL)) { if (p->deadline > 0 && p->deadline <= time(NULL)) {
timeout = scale_interval(
INTERVAL_QUERY_PATHETIC, 0.0);
timeout = error_interval();
log_debug("no reply from %s received in time, " log_debug("no reply from %s received in time, "
"next query %ds", log_sockaddr( "next query %ds", log_sockaddr(
(struct sockaddr *)&p->addr->ss), timeout); (struct sockaddr *)&p->addr->ss), timeout);
@ -412,6 +412,7 @@ priv_adjtime(void)
conf->status.reftime = gettime(); conf->status.reftime = gettime();
conf->status.leap = LI_NOWARNING; conf->status.leap = LI_NOWARNING;
conf->status.stratum++; /* one more than selected peer */ conf->status.stratum++; /* one more than selected peer */
update_scale(offset_median);
if (peers[offset_cnt / 2]->addr->ss.ss_family == AF_INET) if (peers[offset_cnt / 2]->addr->ss.ss_family == AF_INET)
conf->status.refid = ((struct sockaddr_in *) conf->status.refid = ((struct sockaddr_in *)
@ -456,3 +457,30 @@ priv_host_dns(char *name, u_int32_t peerid)
dlen = strlen(name) + 1; dlen = strlen(name) + 1;
imsg_compose(ibuf_main, IMSG_HOST_DNS, peerid, 0, name, dlen); imsg_compose(ibuf_main, IMSG_HOST_DNS, peerid, 0, name, dlen);
} }
void
update_scale(double offset)
{
if (offset < 0)
offset = -offset;
if (offset > QSCALE_OFF_MAX)
conf->scale = QSCALE_FACTOR;
else if (offset < QSCALE_OFF_MIN)
conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / QSCALE_OFF_MIN;
else
conf->scale = QSCALE_FACTOR * QSCALE_OFF_MAX / offset;
}
time_t
scale_interval(time_t requested)
{
return (requested * conf->scale / QSCALE_FACTOR);
}
time_t
error_interval(void)
{
return (INTERVAL_QUERY_PATHETIC * QSCALE_OFF_MAX / QSCALE_OFF_MIN);
}

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

@ -1,4 +1,4 @@
/* $OpenBSD: ntpd.h,v 1.49 2005/01/27 10:32:29 dtucker Exp $ */
/* $OpenBSD: ntpd.h,v 1.50 2005/01/27 14:44:00 dtucker Exp $ */
/* /*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@ -51,6 +51,7 @@
#define QSCALE_OFF_MIN 0.05 #define QSCALE_OFF_MIN 0.05
#define QSCALE_OFF_MAX 0.50 #define QSCALE_OFF_MAX 0.50
#define QSCALE_FACTOR 1000
#define QUERYTIME_MAX 15 /* single query might take n secs max */ #define QUERYTIME_MAX 15 /* single query might take n secs max */
#define OFFSET_ARRAY_SIZE 8 #define OFFSET_ARRAY_SIZE 8
@ -122,6 +123,7 @@ struct ntpd_conf {
u_int8_t listen_all; u_int8_t listen_all;
u_int8_t settime; u_int8_t settime;
u_int8_t debug; u_int8_t debug;
u_int32_t scale;
}; };
struct buf { struct buf {
@ -237,7 +239,9 @@ int client_addr_init(struct ntp_peer *);
int client_nextaddr(struct ntp_peer *); int client_nextaddr(struct ntp_peer *);
int client_query(struct ntp_peer *); int client_query(struct ntp_peer *);
int client_dispatch(struct ntp_peer *, u_int8_t); int client_dispatch(struct ntp_peer *, u_int8_t);
time_t scale_interval(time_t, double);
void update_scale(double);
time_t scale_interval(time_t);
time_t error_interval(void);
void set_next(struct ntp_peer *, time_t); void set_next(struct ntp_peer *, time_t);
/* util.c */ /* util.c */


Loading…
Cancel
Save