diff options
author | Otto Moerbeek <otto@cvs.openbsd.org> | 2020-08-30 16:21:30 +0000 |
---|---|---|
committer | Otto Moerbeek <otto@cvs.openbsd.org> | 2020-08-30 16:21:30 +0000 |
commit | ebbde33acb2bfe0527992108f1d2a48fca7f74e7 (patch) | |
tree | 7b7ec5e8dd108d2c24b60fcd5edea11f7dd1b608 | |
parent | 2dcd8cc6adea7198dce2883d16cf1c8c6687e78a (diff) |
If no replies are received for a while due to connectivity issues
go into unsynced mode. The existing code to check if we're unsycned
is only done on receiving an ntp packet which does not happen if
there are connectivity issues. Prodded by naddy@ ok @florian
-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 *); |