summaryrefslogtreecommitdiff
path: root/usr.sbin
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2006-06-07 06:29:04 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2006-06-07 06:29:04 +0000
commitb3297db76a0d82f09e6418259693beff1b99b895 (patch)
treec65c41f365e0bb3dc1cbc84f616919f33b8b4fb9 /usr.sbin
parentc406fbe0f0bbe6acad773e991b8c334e7297f4c2 (diff)
Compensate old offsets with the amount of adjustment done, avoiding
overcompensating. From DragonFly, uses recent adjtime(2) changes, so you'll need a recent kernel. ok henning@
Diffstat (limited to 'usr.sbin')
-rw-r--r--usr.sbin/ntpd/client.c6
-rw-r--r--usr.sbin/ntpd/ntp.c8
-rw-r--r--usr.sbin/ntpd/ntpd.c3
-rw-r--r--usr.sbin/ntpd/ntpd.h4
-rw-r--r--usr.sbin/ntpd/server.c6
-rw-r--r--usr.sbin/ntpd/util.c17
6 files changed, 33 insertions, 11 deletions
diff --git a/usr.sbin/ntpd/client.c b/usr.sbin/ntpd/client.c
index 65fad7139b4..60ffcd17f95 100644
--- a/usr.sbin/ntpd/client.c
+++ b/usr.sbin/ntpd/client.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: client.c,v 1.69 2006/06/04 18:58:13 otto Exp $ */
+/* $OpenBSD: client.c,v 1.70 2006/06/07 06:29:03 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -161,7 +161,7 @@ client_query(struct ntp_peer *p)
p->query->msg.xmttime.int_partl = arc4random();
p->query->msg.xmttime.fractionl = arc4random();
- p->query->xmttime = gettime();
+ p->query->xmttime = gettime_corrected();
if (ntp_sendmsg(p->query->fd, NULL, &p->query->msg,
NTP_MSGSIZE_NOAUTH, 0) == -1) {
@@ -196,7 +196,7 @@ client_dispatch(struct ntp_peer *p, u_int8_t settime)
fatal("recvfrom");
}
- T4 = gettime();
+ T4 = gettime_corrected();
ntp_getmsg((struct sockaddr *)&p->addr->ss, buf, size, &msg);
diff --git a/usr.sbin/ntpd/ntp.c b/usr.sbin/ntpd/ntp.c
index 4657f6f09c1..8ee2a981027 100644
--- a/usr.sbin/ntpd/ntp.c
+++ b/usr.sbin/ntpd/ntp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntp.c,v 1.83 2006/06/04 18:58:13 otto Exp $ */
+/* $OpenBSD: ntp.c,v 1.84 2006/06/07 06:29:03 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -500,8 +500,11 @@ priv_adjtime(void)
free(offsets);
- TAILQ_FOREACH(p, &conf->ntp_peers, entry)
+ TAILQ_FOREACH(p, &conf->ntp_peers, entry) {
+ for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
+ p->reply[i].offset -= offset_median;
p->update.good = 0;
+ }
return (0);
}
@@ -551,6 +554,7 @@ priv_host_dns(char *name, u_int32_t peerid)
void
update_scale(double offset)
{
+ offset += getoffset();
if (offset < 0)
offset = -offset;
diff --git a/usr.sbin/ntpd/ntpd.c b/usr.sbin/ntpd/ntpd.c
index 6d31ed2e294..17b08b617ff 100644
--- a/usr.sbin/ntpd/ntpd.c
+++ b/usr.sbin/ntpd/ntpd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.c,v 1.41 2006/02/21 23:47:00 stevesk Exp $ */
+/* $OpenBSD: ntpd.c,v 1.42 2006/06/07 06:29:03 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -320,6 +320,7 @@ ntpd_adjtime(double d)
int synced = 0;
static int firstadj = 1;
+ d += getoffset();
if (d >= (double)LOG_NEGLIGEE / 1000 ||
d <= -1 * (double)LOG_NEGLIGEE / 1000)
log_info("adjusting local clock by %fs", d);
diff --git a/usr.sbin/ntpd/ntpd.h b/usr.sbin/ntpd/ntpd.h
index ec7c0a7d2d4..76aa6d098fa 100644
--- a/usr.sbin/ntpd/ntpd.h
+++ b/usr.sbin/ntpd/ntpd.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: ntpd.h,v 1.70 2006/06/04 18:58:13 otto Exp $ */
+/* $OpenBSD: ntpd.h,v 1.71 2006/06/07 06:29:03 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -276,6 +276,8 @@ time_t error_interval(void);
void set_next(struct ntp_peer *, time_t);
/* util.c */
+double gettime_corrected(void);
+double getoffset(void);
double gettime(void);
void d_to_tv(double, struct timeval *);
double lfp_to_d(struct l_fixedpt);
diff --git a/usr.sbin/ntpd/server.c b/usr.sbin/ntpd/server.c
index e2529e5d4bf..8b6352b4485 100644
--- a/usr.sbin/ntpd/server.c
+++ b/usr.sbin/ntpd/server.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: server.c,v 1.28 2006/01/19 11:20:23 dtucker Exp $ */
+/* $OpenBSD: server.c,v 1.29 2006/06/07 06:29:03 otto Exp $ */
/*
* Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
@@ -137,7 +137,7 @@ server_dispatch(int fd, struct ntpd_conf *conf)
fatal("recvfrom");
}
- rectime = gettime();
+ rectime = gettime_corrected();
if (ntp_getmsg((struct sockaddr *)&fsa, buf, size, &query) == -1)
return (0);
@@ -160,7 +160,7 @@ server_dispatch(int fd, struct ntpd_conf *conf)
reply.precision = conf->status.precision;
reply.rectime = d_to_lfp(rectime);
reply.reftime = d_to_lfp(conf->status.reftime);
- reply.xmttime = d_to_lfp(gettime());
+ reply.xmttime = d_to_lfp(gettime_corrected());
reply.orgtime = query.xmttime;
reply.rootdelay = d_to_sfp(conf->status.rootdelay);
diff --git a/usr.sbin/ntpd/util.c b/usr.sbin/ntpd/util.c
index 76cf52a082f..41d42eb9a63 100644
--- a/usr.sbin/ntpd/util.c
+++ b/usr.sbin/ntpd/util.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: util.c,v 1.10 2004/12/08 15:47:38 mickey Exp $ */
+/* $OpenBSD: util.c,v 1.11 2006/06/07 06:29:03 otto Exp $ */
/*
* Copyright (c) 2004 Alexander Guy <alexander.guy@andern.org>
@@ -22,6 +22,21 @@
#include "ntpd.h"
double
+gettime_corrected(void)
+{
+ return (gettime() + getoffset());
+}
+
+double
+getoffset(void)
+{
+ struct timeval tv;
+ if (adjtime(NULL, &tv) == -1)
+ return (0.0);
+ return (tv.tv_sec + 1.0e-6 * tv.tv_usec);
+}
+
+double
gettime(void)
{
struct timeval tv;