From c1869dec59c83af486cad7e688928d02f873b62a Mon Sep 17 00:00:00 2001 From: otto <> Date: Wed, 12 Feb 2020 19:14:56 +0000 Subject: [PATCH] If constraints are configured but do not work for whatever reason ntpd does not work. Make that more clear in the log and ntpdctl -s status. report by and ok benno@ --- src/usr.sbin/ntpd/constraint.c | 16 +++++++++++++--- src/usr.sbin/ntpd/control.c | 3 ++- src/usr.sbin/ntpd/ntp.c | 4 ++-- src/usr.sbin/ntpd/ntpd.c | 5 +++-- src/usr.sbin/ntpd/ntpd.h | 11 ++++++----- 5 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/usr.sbin/ntpd/constraint.c b/src/usr.sbin/ntpd/constraint.c index 656142ae..3df3a1aa 100644 --- a/src/usr.sbin/ntpd/constraint.c +++ b/src/usr.sbin/ntpd/constraint.c @@ -1,4 +1,4 @@ -/* $OpenBSD: constraint.c,v 1.48 2019/07/16 14:15:40 otto Exp $ */ +/* $OpenBSD: constraint.c,v 1.49 2020/02/12 19:14:56 otto Exp $ */ /* * Copyright (c) 2015 Reyk Floeter @@ -695,8 +695,9 @@ constraint_msg_result(u_int32_t id, u_int8_t *data, size_t len) void constraint_msg_close(u_int32_t id, u_int8_t *data, size_t len) { - struct constraint *cstr; - int fail; + struct constraint *cstr, *tmp; + int fail, cnt; + static int total_fails; if ((cstr = constraint_byid(id)) == NULL) { log_warnx("IMSG_CONSTRAINT_CLOSE with invalid constraint id"); @@ -715,6 +716,15 @@ constraint_msg_close(u_int32_t id, u_int8_t *data, size_t len) " received in time, next query %ds", log_sockaddr((struct sockaddr *) &cstr->addr->ss), CONSTRAINT_SCAN_INTERVAL); + + cnt = 0; + TAILQ_FOREACH(tmp, &conf->constraints, entry) + cnt++; + if (cnt > 0 && ++total_fails >= cnt && + conf->constraint_median == 0) { + log_warnx("constrainst configured but none available"); + total_fails = 0; + } } if (fail || cstr->state < STATE_QUERY_SENT) { diff --git a/src/usr.sbin/ntpd/control.c b/src/usr.sbin/ntpd/control.c index 7c1f0e1c..751e9cb4 100644 --- a/src/usr.sbin/ntpd/control.c +++ b/src/usr.sbin/ntpd/control.c @@ -1,4 +1,4 @@ -/* $OpenBSD: control.c,v 1.17 2019/07/10 05:53:37 otto Exp $ */ +/* $OpenBSD: control.c,v 1.18 2020/02/12 19:14:56 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -329,6 +329,7 @@ build_show_status(struct ctl_show_status *cs) cs->synced = conf->status.synced; cs->stratum = conf->status.stratum; cs->clock_offset = getoffset() * 1000.0; + cs->constraints = !TAILQ_EMPTY(&conf->constraints); cs->constraint_median = conf->constraint_median; cs->constraint_last = conf->constraint_last; cs->constraint_errors = conf->constraint_errors; diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index 02c5b6bd..ea9a4e92 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.162 2019/11/11 06:32:52 otto Exp $ */ +/* $OpenBSD: ntp.c,v 1.163 2020/02/12 19:14:56 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -228,7 +228,7 @@ ntp_main(struct ntpd_conf *nconf, struct passwd *pw, int argc, char **argv) memset(pfd, 0, sizeof(*pfd) * pfd_elms); memset(idx2peer, 0, sizeof(*idx2peer) * idx2peer_elms); - nextaction = getmonotime() + 3600; + nextaction = getmonotime() + 900; pfd[PFD_PIPE_MAIN].fd = ibuf_main->fd; pfd[PFD_PIPE_MAIN].events = POLLIN; pfd[PFD_PIPE_DNS].fd = ibuf_dns->fd; diff --git a/src/usr.sbin/ntpd/ntpd.c b/src/usr.sbin/ntpd/ntpd.c index d54d35c8..e015d1d0 100644 --- a/src/usr.sbin/ntpd/ntpd.c +++ b/src/usr.sbin/ntpd/ntpd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.c,v 1.128 2019/11/11 06:32:52 otto Exp $ */ +/* $OpenBSD: ntpd.c,v 1.129 2020/02/12 19:14:56 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -810,7 +810,8 @@ show_status_msg(struct imsg *imsg) printf(" (%d errors)", cstatus->constraint_errors); printf(", "); - } + } else if (cstatus->constraints) + printf("constraints configured but none available, "); if (cstatus->peercnt + cstatus->sensorcnt == 0) printf("no peers and no sensors configured\n"); diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index 04940e76..208d19cc 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.148 2019/11/11 06:32:52 otto Exp $ */ +/* $OpenBSD: ntpd.h,v 1.149 2020/02/12 19:14:56 otto Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -254,16 +254,17 @@ struct ntpd_conf { }; struct ctl_show_status { + time_t constraint_median; + time_t constraint_last; + double clock_offset; u_int peercnt; u_int sensorcnt; u_int valid_peers; u_int valid_sensors; + u_int constraint_errors; u_int8_t synced; u_int8_t stratum; - double clock_offset; - time_t constraint_median; - time_t constraint_last; - u_int constraint_errors; + u_int8_t constraints; }; struct ctl_show_peer {