diff options
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/ntpd/ntp.c | 24 | ||||
-rw-r--r-- | usr.sbin/ntpd/ntpd.h | 4 |
2 files changed, 24 insertions, 4 deletions
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c index 015aea3631e..4d09f7adcb1 100644 --- a/usr.sbin/ntpd/ntp.c +++ b/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.165 2020/06/22 06:11:34 otto Exp $ */ +/* $OpenBSD: ntp.c,v 1.166 2020/08/30 16:21:29 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -89,6 +89,7 @@ ntp_main(struct ntpd_conf *nconf, struct passwd *pw, int argc, char **argv) struct stat stb; struct ctl_conn *cc; time_t nextaction, last_sensor_scan = 0, now; + time_t last_action = 0, interval; void *newp; if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, PF_UNSPEC, @@ -402,6 +403,7 @@ ntp_main(struct ntpd_conf *nconf, struct passwd *pw, int argc, char **argv) for (; nfds > 0 && j < idx_clients; j++) { if (pfd[j].revents & (POLLIN|POLLERR)) { nfds--; + last_action = now; if (client_dispatch(idx2peer[j - idx_peers], conf->settime, conf->automatic) == -1) { log_warn("pipe write error (settime)"); @@ -417,8 +419,24 @@ ntp_main(struct ntpd_conf *nconf, struct passwd *pw, int argc, char **argv) for (s = TAILQ_FIRST(&conf->ntp_sensors); s != NULL; s = next_s) { next_s = TAILQ_NEXT(s, entry); - if (s->next <= getmonotime()) + if (s->next <= now) { + last_action = now; sensor_query(s); + } + } + + /* + * Compute maximum of scale_interval(INTERVAL_QUERY_NORMAL), + * if we did not process a time message for three times that + * interval, stop advertising we're synced. + */ + interval = INTERVAL_QUERY_NORMAL * conf->scale; + interval += SCALE_INTERVAL(interval) - 1; + if (conf->status.synced && last_action + 3 * interval < now) { + log_info("clock is now unsynced"); + conf->status.synced = 0; + conf->scale = 1; + priv_dns(IMSG_UNSYNCED, NULL, 0); } } @@ -853,7 +871,7 @@ scale_interval(time_t requested) time_t interval, r; interval = requested * conf->scale; - r = arc4random_uniform(MAXIMUM(5, interval / 10)); + r = arc4random_uniform(SCALE_INTERVAL(interval)); return (interval + r); } diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h index 208d19ccdfe..9305cf0cd9c 100644 --- a/usr.sbin/ntpd/ntpd.h +++ b/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.149 2020/02/12 19:14:56 otto Exp $ */ +/* $OpenBSD: ntpd.h,v 1.150 2020/08/30 16:21:29 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> @@ -344,6 +344,8 @@ time_t error_interval(void); extern struct ntpd_conf *conf; extern struct ctl_conns ctl_conns; +#define SCALE_INTERVAL(x) MAXIMUM(5, (x) / 10) + /* parse.y */ int parse_config(const char *, struct ntpd_conf *); |