1 diff -urN openntpd-3.7p1.orig/client.c openntpd-3.7p1/client.c
2 --- openntpd-3.7p1.orig/client.c 2005-03-13 13:36:38.000000000 +0100
3 +++ openntpd-3.7p1/client.c 2006-02-23 16:27:53.686827824 +0100
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 diff -urN openntpd-3.7p1.orig/configure.ac openntpd-3.7p1/configure.ac
14 --- openntpd-3.7p1.orig/configure.ac 2005-05-23 13:11:08.000000000 +0200
15 +++ openntpd-3.7p1/configure.ac 2006-02-23 16:27:53.688827520 +0100
17 [ builtin_arc4random=$withval ]
20 +AC_ARG_WITH(adjtimex,
21 + [ --with-adjtimex Use adjtimex to adjust kernel skew],
22 + [ AC_DEFINE(USE_ADJTIMEX, [], [Use adjust skew with adjtimex (experimental)]) ]
25 # Search for OpenSSL if required.
26 if test "$ac_cv_func_arc4random" != "yes" && test "x$builtin_arc4random" != "xyes"; then
27 saved_CPPFLAGS="$CPPFLAGS"
28 diff -urN openntpd-3.7p1.orig/defines.h openntpd-3.7p1/defines.h
29 --- openntpd-3.7p1.orig/defines.h 2005-05-23 02:16:33.000000000 +0200
30 +++ openntpd-3.7p1/defines.h 2006-02-23 16:27:53.688827520 +0100
32 # define setproctitle(x)
36 +# define adjtime(a,b) (_compat_adjtime((a),(b)))
40 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
41 # define SA_LEN(x) ((x)->sa_len)
42 diff -urN openntpd-3.7p1.orig/openbsd-compat/Makefile.in openntpd-3.7p1/openbsd-compat/Makefile.in
43 --- openntpd-3.7p1.orig/openbsd-compat/Makefile.in 2004-12-20 00:41:36.000000000 +0100
44 +++ openntpd-3.7p1/openbsd-compat/Makefile.in 2006-02-23 16:27:53.901795144 +0100
46 OPENBSD= asprintf.o daemon.o inet_pton.o strlcpy.o
47 COMPAT= atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
48 bsd-snprintf.o fake-rfc2553.o uidswap.o
50 +PORT= port-linux.o port-qnx.o
54 diff -urN openntpd-3.7p1.orig/openbsd-compat/openbsd-compat.h openntpd-3.7p1/openbsd-compat/openbsd-compat.h
55 --- openntpd-3.7p1.orig/openbsd-compat/openbsd-compat.h 2004-12-19 04:04:22.000000000 +0100
56 +++ openntpd-3.7p1/openbsd-compat/openbsd-compat.h 2006-02-23 16:27:53.948788000 +0100
58 __attribute__((__format__ (printf, 2, 3)));
62 +# include <sys/time.h>
63 +int _compat_adjtime(const struct timeval *, struct timeval *);
66 #ifndef HAVE_INET_PTON
67 int inet_pton(int, const char *, void *);
69 diff -urN openntpd-3.7p1.orig/openbsd-compat/port-linux.c openntpd-3.7p1/openbsd-compat/port-linux.c
70 --- openntpd-3.7p1.orig/openbsd-compat/port-linux.c 1970-01-01 01:00:00.000000000 +0100
71 +++ openntpd-3.7p1/openbsd-compat/port-linux.c 2006-02-23 16:27:53.996780704 +0100
76 + * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
78 + * Permission to use, copy, modify, and distribute this software for any
79 + * purpose with or without fee is hereby granted, provided that the above
80 + * copyright notice and this permission notice appear in all copies.
82 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
83 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
84 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
85 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
86 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
87 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
88 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
91 +#include "includes.h"
94 +#include <sys/timex.h>
102 +/* scale factor used by adjtimex freq param. 1 ppm = 65536 */
103 +#define ADJTIMEX_FREQ_SCALE 65536
105 +/* maximum change to skew per adjustment, in PPM */
106 +#define MAX_SKEW_DELTA 5.0
109 +_compat_adjtime(const struct timeval *delta, struct timeval *olddelta)
111 + static struct timeval tlast = {0,0};
112 + static double tskew = 0;
113 + static int synced = -1;
114 + struct timeval tnow, tdelta;
115 + double skew = 0, newskew, deltaskew, adjust, interval = 0;
117 + int result, saved_errno;
119 + gettimeofday(&tnow, NULL);
120 + adjust = (double)delta->tv_sec;
121 + adjust += (double)delta->tv_usec / 1000000;
123 + /* Even if the caller doesn't care about the olddelta, we do */
124 + if (olddelta == NULL)
125 + olddelta = &tdelta;
127 + result = adjtime(delta, olddelta);
128 + saved_errno = errno;
130 + if (olddelta->tv_sec == 0 && olddelta->tv_usec == 0 &&
137 + * do skew calculations if we have synced
139 + if (synced == 0 ) {
141 + if (adjtimex(&tmx) == -1)
142 + log_warn("adjtimex get failed");
144 + tskew = (double)tmx.freq / ADJTIMEX_FREQ_SCALE;
145 + } else if (synced >= 1) {
146 + interval = (double)(tnow.tv_sec - tlast.tv_sec);
147 + interval += (double)(tnow.tv_usec - tlast.tv_usec) / 1000000;
149 + skew = (adjust * 1000000) / interval;
150 + newskew = ((tskew * synced) + skew) / synced;
151 + deltaskew = newskew - tskew;
153 + if (deltaskew > MAX_SKEW_DELTA) {
154 + log_info("skew change %0.3lf exceeds limit", deltaskew);
155 + tskew += MAX_SKEW_DELTA;
156 + } else if (deltaskew < -MAX_SKEW_DELTA) {
157 + log_info("skew change %0.3lf exceeds limit", deltaskew);
158 + tskew -= MAX_SKEW_DELTA;
163 + /* Adjust the kernel skew. */
164 + tmx.freq = (long)(tskew * ADJTIMEX_FREQ_SCALE);
165 + tmx.modes = ADJ_FREQUENCY;
166 + if (adjtimex(&tmx) == -1)
167 + log_warn("adjtimex set freq failed");
170 + log_debug("interval %0.3lf skew %0.3lf total skew %0.3lf", interval,
174 + errno = saved_errno;