1 diff -u -p -r1.46 client.c
2 --- openntpd-3.7p1/client.c 13 Mar 2005 12:36:43 -0000 1.46
3 +++ openntpd-3.7p1/client.c 26 Jun 2005 03:15:54 -0000
4 @@ -306,7 +306,7 @@ client_update(struct ntp_peer *p)
7 for (i = 0; i < OFFSET_ARRAY_SIZE; i++)
8 - if (p->reply[i].rcvd <= p->reply[best].rcvd)
9 + /* if (p->reply[i].rcvd <= p->reply[best].rcvd) */
13 --- openntpd-3.7p1/configure.ac 23 May 2005 11:10:34 -0000 1.62
14 +++ openntpd-3.7p1/configure.ac 26 Jun 2005 03:15:54 -0000
15 @@ -466,6 +466,11 @@ AC_ARG_WITH(builtin-arc4random,
16 [ builtin_arc4random=$withval ]
19 +AC_ARG_WITH(adjtimex,
20 + [ --with-adjtimex Use adjtimex to adjust kernel skew],
21 + [ AC_DEFINE(USE_ADJTIMEX, [], [Use adjust skew with adjtimex (experimental)]) ]
24 # Search for OpenSSL if required.
25 if test "$ac_cv_func_arc4random" != "yes" && test "x$builtin_arc4random" != "xyes"; then
26 saved_CPPFLAGS="$CPPFLAGS"
27 --- openntpd-3.7p1/defines.h 23 May 2005 00:16:15 -0000 1.23
28 +++ openntpd-3.7p1/defines.h 26 Jun 2005 03:15:54 -0000
30 # define setproctitle(x)
34 +# define adjtime(a,b) (_compat_adjtime((a),(b)))
38 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
39 # define SA_LEN(x) ((x)->sa_len)
40 --- openntpd-3.7p1/openbsd-compat/Makefile.in 19 Dec 2004 23:41:28 -0000 1.10
41 +++ openntpd-3.7p1/openbsd-compat/Makefile.in 26 Jun 2005 03:17:15 -0000
42 @@ -9,7 +9,7 @@ all: libopenbsd-compat.a
43 OPENBSD= asprintf.o daemon.o inet_pton.o strlcpy.o
44 COMPAT= atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
45 bsd-snprintf.o fake-rfc2553.o uidswap.o
47 +PORT= port-linux.o port-qnx.o
51 --- openntpd-3.7p1/openbsd-compat/openbsd-compat.h 19 Dec 2004 03:04:22 -0000 1.15
52 +++ openntpd-3.7p1/openbsd-compat/openbsd-compat.h 26 Jun 2005 03:15:54 -0000
53 @@ -44,6 +44,11 @@ int asprintf(char **, const char *,
54 __attribute__((__format__ (printf, 2, 3)));
58 +# include <sys/time.h>
59 +int _compat_adjtime(const struct timeval *, struct timeval *);
62 #ifndef HAVE_INET_PTON
63 int inet_pton(int, const char *, void *);
65 --- /dev/null 1 Jan 1970 00:00:00 -0000
66 +++ openntpd-3.7p1/openbsd-compat/port-linux.c 10 Dec 2004 01:10:30 -0000
71 + * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
73 + * Permission to use, copy, modify, and distribute this software for any
74 + * purpose with or without fee is hereby granted, provided that the above
75 + * copyright notice and this permission notice appear in all copies.
77 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
78 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
79 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
80 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
81 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
82 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
83 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
86 +#include "includes.h"
89 +#include <sys/timex.h>
97 +/* scale factor used by adjtimex freq param. 1 ppm = 65536 */
98 +#define ADJTIMEX_FREQ_SCALE 65536
100 +/* maximum change to skew per adjustment, in PPM */
101 +#define MAX_SKEW_DELTA 5.0
104 +_compat_adjtime(const struct timeval *delta, struct timeval *olddelta)
106 + static struct timeval tlast = {0,0};
107 + static double tskew = 0;
108 + static int synced = -1;
109 + struct timeval tnow, tdelta;
110 + double skew = 0, newskew, deltaskew, adjust, interval = 0;
112 + int result, saved_errno;
114 + gettimeofday(&tnow, NULL);
115 + adjust = (double)delta->tv_sec;
116 + adjust += (double)delta->tv_usec / 1000000;
118 + /* Even if the caller doesn't care about the olddelta, we do */
119 + if (olddelta == NULL)
120 + olddelta = &tdelta;
122 + result = adjtime(delta, olddelta);
123 + saved_errno = errno;
125 + if (olddelta->tv_sec == 0 && olddelta->tv_usec == 0 &&
132 + * do skew calculations if we have synced
134 + if (synced == 0 ) {
136 + if (adjtimex(&tmx) == -1)
137 + log_warn("adjtimex get failed");
139 + tskew = (double)tmx.freq / ADJTIMEX_FREQ_SCALE;
140 + } else if (synced >= 1) {
141 + interval = (double)(tnow.tv_sec - tlast.tv_sec);
142 + interval += (double)(tnow.tv_usec - tlast.tv_usec) / 1000000;
144 + skew = (adjust * 1000000) / interval;
145 + newskew = ((tskew * synced) + skew) / synced;
146 + deltaskew = newskew - tskew;
148 + if (deltaskew > MAX_SKEW_DELTA) {
149 + log_info("skew change %0.3lf exceeds limit", deltaskew);
150 + tskew += MAX_SKEW_DELTA;
151 + } else if (deltaskew < -MAX_SKEW_DELTA) {
152 + log_info("skew change %0.3lf exceeds limit", deltaskew);
153 + tskew -= MAX_SKEW_DELTA;
158 + /* Adjust the kernel skew. */
159 + tmx.freq = (long)(tskew * ADJTIMEX_FREQ_SCALE);
160 + tmx.modes = ADJ_FREQUENCY;
161 + if (adjtimex(&tmx) == -1)
162 + log_warn("adjtimex set freq failed");
165 + log_debug("interval %0.3lf skew %0.3lf total skew %0.3lf", interval,
169 + errno = saved_errno;