Browse Source

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@
OPENBSD_4_0
otto 18 years ago
parent
commit
89f43414db
6 changed files with 33 additions and 11 deletions
  1. +3
    -3
      src/usr.sbin/ntpd/client.c
  2. +6
    -2
      src/usr.sbin/ntpd/ntp.c
  3. +2
    -1
      src/usr.sbin/ntpd/ntpd.c
  4. +3
    -1
      src/usr.sbin/ntpd/ntpd.h
  5. +3
    -3
      src/usr.sbin/ntpd/server.c
  6. +16
    -1
      src/usr.sbin/ntpd/util.c

+ 3
- 3
src/usr.sbin/ntpd/client.c View File

@ -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);


+ 6
- 2
src/usr.sbin/ntpd/ntp.c View File

@ -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;


+ 2
- 1
src/usr.sbin/ntpd/ntpd.c View File

@ -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);


+ 3
- 1
src/usr.sbin/ntpd/ntpd.h View File

@ -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);


+ 3
- 3
src/usr.sbin/ntpd/server.c View File

@ -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);


+ 16
- 1
src/usr.sbin/ntpd/util.c View File

@ -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>
@ -21,6 +21,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)
{


Loading…
Cancel
Save