From f31cfdaa2742aebbcba132af501fbf25da2c081d Mon Sep 17 00:00:00 2001 From: dtucker <> Date: Wed, 10 Aug 2005 13:48:36 +0000 Subject: [PATCH] Propogate server's leap indicator flags to clients; ok henning@ --- src/usr.sbin/ntpd/client.c | 4 ++-- src/usr.sbin/ntpd/ntp.c | 13 +++++++------ src/usr.sbin/ntpd/ntpd.h | 3 ++- src/usr.sbin/ntpd/server.c | 8 ++++++-- 4 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/usr.sbin/ntpd/client.c b/src/usr.sbin/ntpd/client.c index d7c535c7..0f186d97 100644 --- a/src/usr.sbin/ntpd/client.c +++ b/src/usr.sbin/ntpd/client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: client.c,v 1.64 2005/07/11 08:04:28 dtucker Exp $ */ +/* $OpenBSD: client.c,v 1.65 2005/08/10 13:48:36 dtucker Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -246,7 +246,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime) p->reply[p->shift].rcvd = time(NULL); p->reply[p->shift].good = 1; - p->reply[p->shift].status.leap = (msg.status & LIMASK) >> 6; + p->reply[p->shift].status.leap = (msg.status & LIMASK); p->reply[p->shift].status.precision = msg.precision; p->reply[p->shift].status.rootdelay = sfp_to_d(msg.rootdelay); p->reply[p->shift].status.rootdispersion = sfp_to_d(msg.dispersion); diff --git a/src/usr.sbin/ntpd/ntp.c b/src/usr.sbin/ntpd/ntp.c index 8a011037..7393717d 100644 --- a/src/usr.sbin/ntpd/ntp.c +++ b/src/usr.sbin/ntpd/ntp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ntp.c,v 1.66 2005/08/08 14:42:32 henning Exp $ */ +/* $OpenBSD: ntp.c,v 1.67 2005/08/10 13:48:36 dtucker Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -138,7 +138,7 @@ ntp_main(int pipe_prnt[2], struct ntpd_conf *nconf) client_peer_init(p); bzero(&conf->status, sizeof(conf->status)); - conf->status.leap = LI_ALARM; + conf->status.synced = 0; clock_getres(CLOCK_REALTIME, &tp); b = 1000000000 / tp.tv_nsec; /* convert to Hz */ for (a = 0; b > 1; a--, b >>= 1) @@ -308,12 +308,12 @@ ntp_dispatch_imsg(void) switch (imsg.hdr.type) { case IMSG_ADJTIME: memcpy(&n, imsg.data, sizeof(n)); - if (n == 1 && conf->status.leap == LI_ALARM) { + if (n == 1 && !conf->status.synced) { log_info("clock is now synced"); - conf->status.leap = LI_NOWARNING; - } else if (n == 0 && conf->status.leap != LI_ALARM) { + conf->status.synced = 1; + } else if (n == 0 && conf->status.synced) { log_info("clock is now unsynced"); - conf->status.leap = LI_ALARM; + conf->status.synced = 0; } break; case IMSG_HOST_DNS: @@ -433,6 +433,7 @@ priv_adjtime(void) conf->status.stratum = peers[offset_cnt / 2]->update.status.stratum; } + conf->status.leap = peers[offset_cnt / 2]->update.status.leap; imsg_compose(ibuf_main, IMSG_ADJTIME, 0, 0, &offset_median, sizeof(offset_median)); diff --git a/src/usr.sbin/ntpd/ntpd.h b/src/usr.sbin/ntpd/ntpd.h index 6b898b1d..58b787bf 100644 --- a/src/usr.sbin/ntpd/ntpd.h +++ b/src/usr.sbin/ntpd/ntpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: ntpd.h,v 1.59 2005/07/15 03:37:15 henning Exp $ */ +/* $OpenBSD: ntpd.h,v 1.60 2005/08/10 13:48:36 dtucker Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -90,6 +90,7 @@ struct ntp_status { double reftime; u_int32_t refid; u_int32_t refid4; + u_int8_t synced; u_int8_t leap; int8_t precision; u_int8_t poll; diff --git a/src/usr.sbin/ntpd/server.c b/src/usr.sbin/ntpd/server.c index d8b78151..e580fb0d 100644 --- a/src/usr.sbin/ntpd/server.c +++ b/src/usr.sbin/ntpd/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.24 2005/07/22 08:58:56 dtucker Exp $ */ +/* $OpenBSD: server.c,v 1.25 2005/08/10 13:48:36 dtucker Exp $ */ /* * Copyright (c) 2003, 2004 Henning Brauer @@ -131,7 +131,11 @@ server_dispatch(int fd, struct ntpd_conf *conf) version = (query.status & VERSIONMASK) >> 3; bzero(&reply, sizeof(reply)); - reply.status = conf->status.leap | (query.status & VERSIONMASK); + if (conf->status.synced) + reply.status = conf->status.leap; + else + reply.status = LI_ALARM; + reply.status |= (query.status & VERSIONMASK); if ((query.status & MODEMASK) == MODE_CLIENT) reply.status |= MODE_SERVER; else