Deleted Added
full compact
ntp_timer.c (106163) ntp_timer.c (132451)
1/*
2 * ntp_timer.c - event timer support routines
3 */
4#ifdef HAVE_CONFIG_H
5# include <config.h>
6#endif
7
8#include "ntp_machine.h"

--- 9 unchanged lines hidden (view full) ---

18# include <unistd.h>
19#endif
20
21#if defined(HAVE_IO_COMPLETION_PORT)
22# include "ntp_iocompletionport.h"
23# include "ntp_timer.h"
24#endif
25
1/*
2 * ntp_timer.c - event timer support routines
3 */
4#ifdef HAVE_CONFIG_H
5# include <config.h>
6#endif
7
8#include "ntp_machine.h"

--- 9 unchanged lines hidden (view full) ---

18# include <unistd.h>
19#endif
20
21#if defined(HAVE_IO_COMPLETION_PORT)
22# include "ntp_iocompletionport.h"
23# include "ntp_timer.h"
24#endif
25
26#ifdef PUBKEY
27#include "ntp_crypto.h"
28#endif /* PUBKEY */
29
30/*
31 * These routines provide support for the event timer. The timer is
32 * implemented by an interrupt routine which sets a flag once every
33 * 2**EVENT_TIMEOUT seconds (currently 4), and a timer routine which
34 * is called when the mainline code gets around to seeing the flag.
35 * The timer routine dispatches the clock adjustment code if its time
36 * has come, then searches the timer queue for expiries which are
37 * dispatched to the transmit procedure. Finally, we call the hourly

--- 7 unchanged lines hidden (view full) ---

45
46/*
47 * The counters
48 */
49static u_long adjust_timer; /* second timer */
50static u_long keys_timer; /* minute timer */
51static u_long hourly_timer; /* hour timer */
52static u_long huffpuff_timer; /* huff-n'-puff timer */
26/*
27 * These routines provide support for the event timer. The timer is
28 * implemented by an interrupt routine which sets a flag once every
29 * 2**EVENT_TIMEOUT seconds (currently 4), and a timer routine which
30 * is called when the mainline code gets around to seeing the flag.
31 * The timer routine dispatches the clock adjustment code if its time
32 * has come, then searches the timer queue for expiries which are
33 * dispatched to the transmit procedure. Finally, we call the hourly

--- 7 unchanged lines hidden (view full) ---

41
42/*
43 * The counters
44 */
45static u_long adjust_timer; /* second timer */
46static u_long keys_timer; /* minute timer */
47static u_long hourly_timer; /* hour timer */
48static u_long huffpuff_timer; /* huff-n'-puff timer */
53#ifdef AUTOKEY
49#ifdef OPENSSL
54static u_long revoke_timer; /* keys revoke timer */
50static u_long revoke_timer; /* keys revoke timer */
55u_long sys_revoke = 1 << KEY_REVOKE; /* keys revoke timeout */
56#endif /* AUTOKEY */
51u_char sys_revoke = KEY_REVOKE; /* keys revoke timeout (log2 s) */
52#endif /* OPENSSL */
57
58/*
59 * Statistics counter for the interested.
60 */
61volatile u_long alarm_overflow;
62
63#define MINUTE 60
64#define HOUR (60*60)

--- 13 unchanged lines hidden (view full) ---

78#endif /* VMS */
79
80#if defined SYS_WINNT
81static HANDLE WaitableTimerHandle = NULL;
82#else
83static RETSIGTYPE alarming P((int));
84#endif /* SYS_WINNT */
85
53
54/*
55 * Statistics counter for the interested.
56 */
57volatile u_long alarm_overflow;
58
59#define MINUTE 60
60#define HOUR (60*60)

--- 13 unchanged lines hidden (view full) ---

74#endif /* VMS */
75
76#if defined SYS_WINNT
77static HANDLE WaitableTimerHandle = NULL;
78#else
79static RETSIGTYPE alarming P((int));
80#endif /* SYS_WINNT */
81
82#if !defined(VMS)
83# if !defined SYS_WINNT || defined(SYS_CYGWIN32)
84# ifndef HAVE_TIMER_SETTIME
85 struct itimerval itimer;
86# else
87 static timer_t ntpd_timerid;
88 struct itimerspec itimer;
89# endif /* HAVE_TIMER_SETTIME */
90# endif /* SYS_WINNT */
91#endif /* VMS */
86
87/*
92
93/*
94 * reinit_timer - reinitialize interval timer.
95 */
96void
97reinit_timer(void)
98{
99#if !defined(SYS_WINNT) && !defined(VMS)
100# if defined(HAVE_TIMER_CREATE) && defined(HAVE_TIMER_SETTIME)
101 timer_gettime(ntpd_timerid, &itimer);
102 if (itimer.it_value.tv_sec < 0 || itimer.it_value.tv_sec > (1<<EVENT_TIMEOUT)) {
103 itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT);
104 }
105 if (itimer.it_value.tv_nsec < 0 ) {
106 itimer.it_value.tv_nsec = 0;
107 }
108 if (itimer.it_value.tv_sec == 0 && itimer.it_value.tv_nsec == 0) {
109 itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT);
110 itimer.it_value.tv_nsec = 0;
111 }
112 itimer.it_interval.tv_sec = (1<<EVENT_TIMEOUT);
113 itimer.it_interval.tv_nsec = 0;
114 timer_settime(ntpd_timerid, 0 /*!TIMER_ABSTIME*/, &itimer, NULL);
115# else
116 getitimer(ITIMER_REAL, &itimer);
117 if (itimer.it_value.tv_sec < 0 || itimer.it_value.tv_sec > (1<<EVENT_TIMEOUT)) {
118 itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT);
119 }
120 if (itimer.it_value.tv_usec < 0 ) {
121 itimer.it_value.tv_usec = 0;
122 }
123 if (itimer.it_value.tv_sec == 0 && itimer.it_value.tv_usec == 0) {
124 itimer.it_value.tv_sec = (1<<EVENT_TIMEOUT);
125 itimer.it_value.tv_usec = 0;
126 }
127 itimer.it_interval.tv_sec = (1<<EVENT_TIMEOUT);
128 itimer.it_interval.tv_usec = 0;
129 setitimer(ITIMER_REAL, &itimer, (struct itimerval *)0);
130# endif
131# endif /* VMS */
132}
133
134/*
88 * init_timer - initialize the timer data structures
89 */
90void
91init_timer(void)
92{
135 * init_timer - initialize the timer data structures
136 */
137void
138init_timer(void)
139{
93#if !defined(VMS)
94# if !defined SYS_WINNT || defined(SYS_CYGWIN32)
95# ifndef HAVE_TIMER_SETTIME
96 struct itimerval itimer;
97# else
98 static timer_t ntpd_timerid; /* should be global if we ever want */
99 /* to kill timer without rebooting ... */
100 struct itimerspec itimer;
101# endif /* HAVE_TIMER_SETTIME */
102# else /* SYS_WINNT */
140# if defined SYS_WINNT & !defined(SYS_CYGWIN32)
103 HANDLE hToken;
104 TOKEN_PRIVILEGES tkp;
105# endif /* SYS_WINNT */
141 HANDLE hToken;
142 TOKEN_PRIVILEGES tkp;
143# endif /* SYS_WINNT */
106#endif /* !VMS */
107
108 /*
109 * Initialize...
110 */
111 alarm_flag = 0;
112 alarm_overflow = 0;
113 adjust_timer = 1;
114 hourly_timer = HOUR;

--- 98 unchanged lines hidden (view full) ---

213
214/*
215 * timer - dispatch anyone who needs to be
216 */
217void
218timer(void)
219{
220 register struct peer *peer, *next_peer;
144
145 /*
146 * Initialize...
147 */
148 alarm_flag = 0;
149 alarm_overflow = 0;
150 adjust_timer = 1;
151 hourly_timer = HOUR;

--- 98 unchanged lines hidden (view full) ---

250
251/*
252 * timer - dispatch anyone who needs to be
253 */
254void
255timer(void)
256{
257 register struct peer *peer, *next_peer;
258#ifdef OPENSSL
259 char statstr[NTP_MAXSTRLEN]; /* statistics for filegen */
260#endif /* OPENSSL */
221 u_int n;
222
223 current_time += (1<<EVENT_TIMEOUT);
224
225 /*
226 * Adjustment timeout first.
227 */
228 if (adjust_timer <= current_time) {
229 adjust_timer += 1;
230 adj_host_clock();
261 u_int n;
262
263 current_time += (1<<EVENT_TIMEOUT);
264
265 /*
266 * Adjustment timeout first.
267 */
268 if (adjust_timer <= current_time) {
269 adjust_timer += 1;
270 adj_host_clock();
271 kod_proto();
231 }
232
233 /*
234 * Now dispatch any peers whose event timer has expired. Be careful
235 * here, since the peer structure might go away as the result of
236 * the call.
237 */
238 for (n = 0; n < HASH_SIZE; n++) {

--- 25 unchanged lines hidden (view full) ---

264 /*
265 * Huff-n'-puff filter
266 */
267 if (huffpuff_timer <= current_time) {
268 huffpuff_timer += HUFFPUFF;
269 huffpuff();
270 }
271
272 }
273
274 /*
275 * Now dispatch any peers whose event timer has expired. Be careful
276 * here, since the peer structure might go away as the result of
277 * the call.
278 */
279 for (n = 0; n < HASH_SIZE; n++) {

--- 25 unchanged lines hidden (view full) ---

305 /*
306 * Huff-n'-puff filter
307 */
308 if (huffpuff_timer <= current_time) {
309 huffpuff_timer += HUFFPUFF;
310 huffpuff();
311 }
312
272#ifdef AUTOKEY
313#ifdef OPENSSL
273 /*
274 * Garbage collect old keys and generate new private value
275 */
276 if (revoke_timer <= current_time) {
314 /*
315 * Garbage collect old keys and generate new private value
316 */
317 if (revoke_timer <= current_time) {
277 revoke_timer += sys_revoke;
318 revoke_timer += RANDPOLL(sys_revoke);
278 expire_all();
319 expire_all();
320 sprintf(statstr, "refresh ts %u", ntohl(hostval.tstamp));
321 record_crypto_stats(NULL, statstr);
279#ifdef DEBUG
280 if (debug)
322#ifdef DEBUG
323 if (debug)
281 printf("key expire: at %lu next %lu\n",
282 current_time, revoke_timer);
324 printf("timer: %s\n", statstr);
283#endif
284 }
325#endif
326 }
285#endif /* AUTOKEY */
327#endif /* OPENSSL */
286
287 /*
288 * Finally, call the hourly routine.
289 */
290 if (hourly_timer <= current_time) {
291 hourly_timer += HOUR;
292 hourly_stats();
293 }

--- 42 unchanged lines hidden ---
328
329 /*
330 * Finally, call the hourly routine.
331 */
332 if (hourly_timer <= current_time) {
333 hourly_timer += HOUR;
334 hourly_stats();
335 }

--- 42 unchanged lines hidden ---