1 diff -urN openntpd-3.9p1.orig/configure.ac openntpd-3.9p1/configure.ac
2 --- openntpd-3.9p1.orig/configure.ac 2006-05-14 14:29:23.000000000 +0900
3 +++ openntpd-3.9p1/configure.ac 2011-11-22 09:34:20.036828225 +0900
4 @@ -583,6 +583,11 @@
5 [ builtin_arc4random=$withval ]
6 )
7
8 +AC_ARG_WITH(adjtimex,
9 + [ --with-adjtimex Use adjtimex to adjust kernel skew],
10 + [ AC_DEFINE(USE_ADJTIMEX, [], [Use adjust skew with adjtimex (experimental)]) ]
11 + )
12 +
13 AC_ARG_WITH(mantype,
14 [ --with-mantype=man|cat|doc Set man page type],
15 [
16 diff -urN openntpd-3.9p1.orig/defines.h openntpd-3.9p1/defines.h
17 --- openntpd-3.9p1.orig/defines.h 2006-05-14 14:29:21.000000000 +0900
18 +++ openntpd-3.9p1/defines.h 2011-11-22 09:34:20.036828225 +0900
19 @@ -20,6 +20,10 @@
20 # define setproctitle(x)
21 #endif
22
23 +#ifdef USE_ADJTIMEX
24 +# define adjtime(a,b) (_compat_adjtime((a),(b)))
25 +#endif
26 +
27 #if !defined(SA_LEN)
28 # if defined(HAVE_STRUCT_SOCKADDR_SA_LEN)
29 # define SA_LEN(x) ((x)->sa_len)
30 diff -urN openntpd-3.9p1.orig/openbsd-compat/Makefile.in openntpd-3.9p1/openbsd-compat/Makefile.in
31 --- openntpd-3.9p1.orig/openbsd-compat/Makefile.in 2006-05-14 14:29:19.000000000 +0900
32 +++ openntpd-3.9p1/openbsd-compat/Makefile.in 2011-11-22 09:34:20.036828225 +0900
33 @@ -9,7 +9,7 @@
34 COMPAT= atomicio.o bsd-arc4random.o bsd-misc.o bsd-poll.o \
35 bsd-snprintf.o bsd-getifaddrs.o bsd-setresuid.o \
36 bsd-setresgid.o fake-rfc2553.o
37 -PORT= port-qnx.o
38 +PORT= port-linux.o port-qnx.o
39
40 VPATH=@srcdir@
41 CC=@CC@
42 diff -urN openntpd-3.9p1.orig/openbsd-compat/openbsd-compat.h openntpd-3.9p1/openbsd-compat/openbsd-compat.h
43 --- openntpd-3.9p1.orig/openbsd-compat/openbsd-compat.h 2006-05-14 14:29:19.000000000 +0900
44 +++ openntpd-3.9p1/openbsd-compat/openbsd-compat.h 2011-11-22 09:34:20.036828225 +0900
45 @@ -46,6 +46,11 @@
46 __attribute__((__format__ (printf, 2, 3)));
47 #endif
48
49 +#ifdef USE_ADJTIMEX
50 +# include <sys/time.h>
51 +int _compat_adjtime(const struct timeval *, struct timeval *);
52 +#endif
53 +
54 #ifndef HAVE_INET_PTON
55 int inet_pton(int, const char *, void *);
56 #endif
57 diff -urN openntpd-3.9p1.orig/openbsd-compat/port-linux.c openntpd-3.9p1/openbsd-compat/port-linux.c
58 --- openntpd-3.9p1.orig/openbsd-compat/port-linux.c 1970-01-01 09:00:00.000000000 +0900
59 +++ openntpd-3.9p1/openbsd-compat/port-linux.c 2011-11-22 09:34:20.036828225 +0900
60 @@ -0,0 +1,105 @@
61 +
62 +
63 +/*
64 + * Copyright (c) 2004 Darren Tucker <dtucker at zip com au>
65 + *
66 + * Permission to use, copy, modify, and distribute this software for any
67 + * purpose with or without fee is hereby granted, provided that the above
68 + * copyright notice and this permission notice appear in all copies.
69 + *
70 + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
71 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
72 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
73 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
74 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
75 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
76 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
77 + */
78 +
79 +#include "includes.h"
80 +
81 +#ifdef USE_ADJTIMEX
82 +#include <sys/timex.h>
83 +#include <errno.h>
84 +#ifdef adjtime
85 +# undef adjtime
86 +#endif
87 +
88 +#include "ntpd.h"
89 +
90 +/* scale factor used by adjtimex freq param. 1 ppm = 65536 */
91 +#define ADJTIMEX_FREQ_SCALE 65536
92 +
93 +/* maximum change to skew per adjustment, in PPM */
94 +#define MAX_SKEW_DELTA 5.0
95 +
96 +int
97 +_compat_adjtime(const struct timeval *delta, struct timeval *olddelta)
98 +{
99 + static struct timeval tlast = {0,0};
100 + static double tskew = 0;
101 + static int synced = -1;
102 + struct timeval tnow, tdelta;
103 + double skew = 0, newskew, deltaskew, adjust, interval = 0;
104 + struct timex tmx;
105 + int result, saved_errno;
106 +
107 + gettimeofday(&tnow, NULL);
108 + adjust = (double)delta->tv_sec;
109 + adjust += (double)delta->tv_usec / 1000000;
110 +
111 + /* Even if the caller doesn't care about the olddelta, we do */
112 + if (olddelta == NULL)
113 + olddelta = &tdelta;
114 +
115 + result = adjtime(delta, olddelta);
116 + saved_errno = errno;
117 +
118 + if (olddelta->tv_sec == 0 && olddelta->tv_usec == 0 &&
119 + synced != INT_MAX)
120 + synced++;
121 + else
122 + synced = 0;
123 +
124 + /*
125 + * do skew calculations if we have synced
126 + */
127 + if (synced == 0 ) {
128 + tmx.modes = 0;
129 + if (adjtimex(&tmx) == -1)
130 + log_warn("adjtimex get failed");
131 + else
132 + tskew = (double)tmx.freq / ADJTIMEX_FREQ_SCALE;
133 + } else if (synced >= 1) {
134 + interval = (double)(tnow.tv_sec - tlast.tv_sec);
135 + interval += (double)(tnow.tv_usec - tlast.tv_usec) / 1000000;
136 +
137 + skew = (adjust * 1000000) / interval;
138 + newskew = ((tskew * synced) + skew) / synced;
139 + deltaskew = newskew - tskew;
140 +
141 + if (deltaskew > MAX_SKEW_DELTA) {
142 + log_info("skew change %0.3lf exceeds limit", deltaskew);
143 + tskew += MAX_SKEW_DELTA;
144 + } else if (deltaskew < -MAX_SKEW_DELTA) {
145 + log_info("skew change %0.3lf exceeds limit", deltaskew);
146 + tskew -= MAX_SKEW_DELTA;
147 + } else {
148 + tskew = newskew;
149 + }
150 +
151 + /* Adjust the kernel skew. */
152 + tmx.freq = (long)(tskew * ADJTIMEX_FREQ_SCALE);
153 + tmx.modes = ADJ_FREQUENCY;
154 + if (adjtimex(&tmx) == -1)
155 + log_warn("adjtimex set freq failed");
156 + }
157 +
158 + log_debug("interval %0.3lf skew %0.3lf total skew %0.3lf", interval,
159 + skew, tskew);
160 +
161 + tlast = tnow;
162 + errno = saved_errno;
163 + return result;
164 +}
165 +#endif
|