1 diff -urN openntpd-3.9p1/client.c openntpd-3.9p1.new/client.c
2 --- openntpd-3.9p1/client.c 2006-05-14 07:29:21.000000000 +0200
3 +++ openntpd-3.9p1.new/client.c 2006-11-03 11:05:18.000000000 +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.9p1/configure.ac openntpd-3.9p1.new/configure.ac
14 --- openntpd-3.9p1/configure.ac 2006-05-14 07:29:23.000000000 +0200
15 +++ openntpd-3.9p1.new/configure.ac 2006-11-03 11:06:26.000000000 +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)]) ]
27 [ --with-mantype=man|cat|doc Set man page type],
29 diff -urN openntpd-3.9p1/defines.h openntpd-3.9p1.new/defines.h
30 --- openntpd-3.9p1/defines.h 2006-05-14 07:29:21.000000000 +0200
31 +++ openntpd-3.9p1.new/defines.h 2006-11-03 11:06:56.000000000 +0100
33 # define setproctitle(x)
37 +# define adjtime(a,b) (_compat_adjtime((a),(b)))
41 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
42 # define SA_LEN(x) ((x)->sa_len)
43 diff -urN openntpd-3.9p1/openbsd-compat/Makefile.in openntpd-3.9p1.new/openbsd-compat/Makefile.in
44 --- openntpd-3.9p1/openbsd-compat/Makefile.in 2006-05-14 07:29:19.000000000 +0200
45 +++ openntpd-3.9p1.new/openbsd-compat/Makefile.in 2006-11-03 11:07:20.000000000 +0100
47 COMPAT= atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
48 bsd-snprintf.o bsd-getifaddrs.o bsd-setresuid.o \
49 bsd-setresgid.o fake-rfc2553.o
51 +PORT= port-linux.o port-qnx.o
55 diff -urN openntpd-3.9p1/openbsd-compat/openbsd-compat.h openntpd-3.9p1.new/openbsd-compat/openbsd-compat.h
56 --- openntpd-3.9p1/openbsd-compat/openbsd-compat.h 2006-05-14 07:29:19.000000000 +0200
57 +++ openntpd-3.9p1.new/openbsd-compat/openbsd-compat.h 2006-11-03 11:07:55.000000000 +0100
59 __attribute__((__format__ (printf, 2, 3)));
63 +# include <sys/time.h>
64 +int _compat_adjtime(const struct timeval *, struct timeval *);
67 #ifndef HAVE_INET_PTON
68 int inet_pton(int, const char *, void *);
70 diff -urN openntpd-3.9p1/openbsd-compat/port-linux.c openntpd-3.9p1.new/openbsd-compat/port-linux.c
71 --- openntpd-3.9p1/openbsd-compat/port-linux.c 1970-01-01 01:00:00.000000000 +0100
72 +++ openntpd-3.9p1.new/openbsd-compat/port-linux.c 2006-11-03 11:08:57.000000000 +0100
77 + * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
79 + * Permission to use, copy, modify, and distribute this software for any
80 + * purpose with or without fee is hereby granted, provided that the above
81 + * copyright notice and this permission notice appear in all copies.
83 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
84 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
85 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
86 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
87 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
88 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
89 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
92 +#include "includes.h"
95 +#include <sys/timex.h>
103 +/* scale factor used by adjtimex freq param. 1 ppm = 65536 */
104 +#define ADJTIMEX_FREQ_SCALE 65536
106 +/* maximum change to skew per adjustment, in PPM */
107 +#define MAX_SKEW_DELTA 5.0
110 +_compat_adjtime(const struct timeval *delta, struct timeval *olddelta)
112 + static struct timeval tlast = {0,0};
113 + static double tskew = 0;
114 + static int synced = -1;
115 + struct timeval tnow, tdelta;
116 + double skew = 0, newskew, deltaskew, adjust, interval = 0;
118 + int result, saved_errno;
120 + gettimeofday(&tnow, NULL);
121 + adjust = (double)delta->tv_sec;
122 + adjust += (double)delta->tv_usec / 1000000;
124 + /* Even if the caller doesn't care about the olddelta, we do */
125 + if (olddelta == NULL)
126 + olddelta = &tdelta;
128 + result = adjtime(delta, olddelta);
129 + saved_errno = errno;
131 + if (olddelta->tv_sec == 0 && olddelta->tv_usec == 0 &&
138 + * do skew calculations if we have synced
140 + if (synced == 0 ) {
142 + if (adjtimex(&tmx) == -1)
143 + log_warn("adjtimex get failed");
145 + tskew = (double)tmx.freq / ADJTIMEX_FREQ_SCALE;
146 + } else if (synced >= 1) {
147 + interval = (double)(tnow.tv_sec - tlast.tv_sec);
148 + interval += (double)(tnow.tv_usec - tlast.tv_usec) / 1000000;
150 + skew = (adjust * 1000000) / interval;
151 + newskew = ((tskew * synced) + skew) / synced;
152 + deltaskew = newskew - tskew;
154 + if (deltaskew > MAX_SKEW_DELTA) {
155 + log_info("skew change %0.3lf exceeds limit", deltaskew);
156 + tskew += MAX_SKEW_DELTA;
157 + } else if (deltaskew < -MAX_SKEW_DELTA) {
158 + log_info("skew change %0.3lf exceeds limit", deltaskew);
159 + tskew -= MAX_SKEW_DELTA;
164 + /* Adjust the kernel skew. */
165 + tmx.freq = (long)(tskew * ADJTIMEX_FREQ_SCALE);
166 + tmx.modes = ADJ_FREQUENCY;
167 + if (adjtimex(&tmx) == -1)
168 + log_warn("adjtimex set freq failed");
171 + log_debug("interval %0.3lf skew %0.3lf total skew %0.3lf", interval,
175 + errno = saved_errno;