xref: /netbsd-src/external/bsd/ntp/dist/ntpd/ntp_timer.c (revision 63aea4bd5b445e491ff0389fe27ec78b3099dba3)
1 /*	$NetBSD: ntp_timer.c,v 1.5 2015/10/23 18:06:19 christos Exp $	*/
2 
3 /*
4  * ntp_timer.c - event timer support routines
5  */
6 #ifdef HAVE_CONFIG_H
7 # include <config.h>
8 #endif
9 
10 #include "ntp_machine.h"
11 #include "ntpd.h"
12 #include "ntp_stdlib.h"
13 #include "ntp_calendar.h"
14 #include "ntp_leapsec.h"
15 
16 #if defined(HAVE_IO_COMPLETION_PORT)
17 # include "ntp_iocompletionport.h"
18 # include "ntp_timer.h"
19 #endif
20 
21 #include <stdio.h>
22 #include <signal.h>
23 #ifdef HAVE_SYS_SIGNAL_H
24 # include <sys/signal.h>
25 #endif
26 #ifdef HAVE_UNISTD_H
27 # include <unistd.h>
28 #endif
29 
30 #ifdef KERNEL_PLL
31 #include "ntp_syscall.h"
32 #endif /* KERNEL_PLL */
33 
34 #ifdef AUTOKEY
35 #include <openssl/rand.h>
36 #endif	/* AUTOKEY */
37 
38 
39 /* TC_ERR represents the timer_create() error return value. */
40 #ifdef SYS_VXWORKS
41 #define	TC_ERR	ERROR
42 #else
43 #define	TC_ERR	(-1)
44 #endif
45 
46 
47 static void check_leapsec(u_int32, const time_t*, int/*BOOL*/);
48 
49 /*
50  * These routines provide support for the event timer.  The timer is
51  * implemented by an interrupt routine which sets a flag once every
52  * second, and a timer routine which is called when the mainline code
53  * gets around to seeing the flag.  The timer routine dispatches the
54  * clock adjustment code if its time has come, then searches the timer
55  * queue for expiries which are dispatched to the transmit procedure.
56  * Finally, we call the hourly procedure to do cleanup and print a
57  * message.
58  */
59 volatile int interface_interval;     /* init_io() sets def. 300s */
60 
61 /*
62  * Initializing flag.  All async routines watch this and only do their
63  * thing when it is clear.
64  */
65 int initializing;
66 
67 /*
68  * Alarm flag. The mainline code imports this.
69  */
70 volatile int alarm_flag;
71 
72 /*
73  * The counters and timeouts
74  */
75 static  u_long interface_timer;	/* interface update timer */
76 static	u_long adjust_timer;	/* second timer */
77 static	u_long stats_timer;	/* stats timer */
78 static	u_long leapf_timer;	/* Report leapfile problems once/day */
79 static	u_long huffpuff_timer;	/* huff-n'-puff timer */
80 static	u_long worker_idle_timer;/* next check for idle intres */
81 u_long	leapsec;	        /* seconds to next leap (proximity class) */
82 int     leapdif;                /* TAI difference step at next leap second*/
83 u_long	orphwait; 		/* orphan wait time */
84 #ifdef AUTOKEY
85 static	u_long revoke_timer;	/* keys revoke timer */
86 static	u_long keys_timer;	/* session key timer */
87 u_long	sys_revoke = KEY_REVOKE; /* keys revoke timeout (log2 s) */
88 u_long	sys_automax = NTP_AUTOMAX; /* key list timeout (log2 s) */
89 #endif	/* AUTOKEY */
90 
91 /*
92  * Statistics counter for the interested.
93  */
94 volatile u_long alarm_overflow;
95 
96 u_long current_time;		/* seconds since startup */
97 
98 /*
99  * Stats.  Number of overflows and number of calls to transmit().
100  */
101 u_long timer_timereset;
102 u_long timer_overflows;
103 u_long timer_xmtcalls;
104 
105 #if defined(VMS)
106 static int vmstimer[2]; 	/* time for next timer AST */
107 static int vmsinc[2];		/* timer increment */
108 #endif /* VMS */
109 
110 #ifdef SYS_WINNT
111 HANDLE WaitableTimerHandle;
112 #else
113 static	RETSIGTYPE alarming (int);
114 #endif /* SYS_WINNT */
115 
116 #if !defined(VMS)
117 # if !defined SYS_WINNT || defined(SYS_CYGWIN32)
118 #  ifdef HAVE_TIMER_CREATE
119 static timer_t timer_id;
120 typedef struct itimerspec intervaltimer;
121 #   define	itv_frac	tv_nsec
122 #  else
123 typedef struct itimerval intervaltimer;
124 #   define	itv_frac	tv_usec
125 #  endif
126 intervaltimer itimer;
127 # endif
128 #endif
129 
130 #if !defined(SYS_WINNT) && !defined(VMS)
131 void	set_timer_or_die(const intervaltimer *);
132 #endif
133 
134 
135 #if !defined(SYS_WINNT) && !defined(VMS)
136 void
137 set_timer_or_die(
138 	const intervaltimer *	ptimer
139 	)
140 {
141 	const char *	setfunc;
142 	int		rc;
143 
144 # ifdef HAVE_TIMER_CREATE
145 	setfunc = "timer_settime";
146 	rc = timer_settime(timer_id, 0, &itimer, NULL);
147 # else
148 	setfunc = "setitimer";
149 	rc = setitimer(ITIMER_REAL, &itimer, NULL);
150 # endif
151 	if (-1 == rc) {
152 		msyslog(LOG_ERR, "interval timer %s failed, %m",
153 			setfunc);
154 		exit(1);
155 	}
156 }
157 #endif	/* !SYS_WINNT && !VMS */
158 
159 
160 /*
161  * reinit_timer - reinitialize interval timer after a clock step.
162  */
163 void
164 reinit_timer(void)
165 {
166 #if !defined(SYS_WINNT) && !defined(VMS)
167 	ZERO(itimer);
168 # ifdef HAVE_TIMER_CREATE
169 	timer_gettime(timer_id, &itimer);
170 # else
171 	getitimer(ITIMER_REAL, &itimer);
172 # endif
173 	if (itimer.it_value.tv_sec < 0 ||
174 	    itimer.it_value.tv_sec > (1 << EVENT_TIMEOUT))
175 		itimer.it_value.tv_sec = (1 << EVENT_TIMEOUT);
176 	if (itimer.it_value.itv_frac < 0)
177 		itimer.it_value.itv_frac = 0;
178 	if (0 == itimer.it_value.tv_sec &&
179 	    0 == itimer.it_value.itv_frac)
180 		itimer.it_value.tv_sec = (1 << EVENT_TIMEOUT);
181 	itimer.it_interval.tv_sec = (1 << EVENT_TIMEOUT);
182 	itimer.it_interval.itv_frac = 0;
183 	set_timer_or_die(&itimer);
184 # endif /* VMS */
185 }
186 
187 
188 /*
189  * init_timer - initialize the timer data structures
190  */
191 void
192 init_timer(void)
193 {
194 	/*
195 	 * Initialize...
196 	 */
197 	alarm_flag = FALSE;
198 	alarm_overflow = 0;
199 	adjust_timer = 1;
200 	stats_timer = SECSPERHR;
201 	leapf_timer = SECSPERDAY;
202 	huffpuff_timer = 0;
203 	interface_timer = 0;
204 	current_time = 0;
205 	timer_overflows = 0;
206 	timer_xmtcalls = 0;
207 	timer_timereset = 0;
208 
209 #ifndef SYS_WINNT
210 	/*
211 	 * Set up the alarm interrupt.	The first comes 2**EVENT_TIMEOUT
212 	 * seconds from now and they continue on every 2**EVENT_TIMEOUT
213 	 * seconds.
214 	 */
215 # ifndef VMS
216 #  ifdef HAVE_TIMER_CREATE
217 	if (TC_ERR == timer_create(CLOCK_REALTIME, NULL, &timer_id)) {
218 		msyslog(LOG_ERR, "timer_create failed, %m");
219 		exit(1);
220 	}
221 #  endif
222 	signal_no_reset(SIGALRM, alarming);
223 	itimer.it_interval.tv_sec =
224 		itimer.it_value.tv_sec = (1 << EVENT_TIMEOUT);
225 	itimer.it_interval.itv_frac = itimer.it_value.itv_frac = 0;
226 	set_timer_or_die(&itimer);
227 # else	/* VMS follows */
228 	vmsinc[0] = 10000000;		/* 1 sec */
229 	vmsinc[1] = 0;
230 	lib$emul(&(1<<EVENT_TIMEOUT), &vmsinc, &0, &vmsinc);
231 
232 	sys$gettim(&vmstimer);	/* that's "now" as abstime */
233 
234 	lib$addx(&vmsinc, &vmstimer, &vmstimer);
235 	sys$setimr(0, &vmstimer, alarming, alarming, 0);
236 # endif	/* VMS */
237 #else	/* SYS_WINNT follows */
238 	/*
239 	 * Set up timer interrupts for every 2**EVENT_TIMEOUT seconds
240 	 * Under Windows/NT,
241 	 */
242 
243 	WaitableTimerHandle = CreateWaitableTimer(NULL, FALSE, NULL);
244 	if (WaitableTimerHandle == NULL) {
245 		msyslog(LOG_ERR, "CreateWaitableTimer failed: %m");
246 		exit(1);
247 	}
248 	else {
249 		DWORD		Period;
250 		LARGE_INTEGER	DueTime;
251 		BOOL		rc;
252 
253 		Period = (1 << EVENT_TIMEOUT) * 1000;
254 		DueTime.QuadPart = Period * 10000i64;
255 		rc = SetWaitableTimer(WaitableTimerHandle, &DueTime,
256 				      Period, NULL, NULL, FALSE);
257 		if (!rc) {
258 			msyslog(LOG_ERR, "SetWaitableTimer failed: %m");
259 			exit(1);
260 		}
261 	}
262 
263 #endif	/* SYS_WINNT */
264 }
265 
266 
267 /*
268  * intres_timeout_req(s) is invoked in the parent to schedule an idle
269  * timeout to fire in s seconds, if not reset earlier by a call to
270  * intres_timeout_req(0), which clears any pending timeout.  When the
271  * timeout expires, worker_idle_timer_fired() is invoked (again, in the
272  * parent).
273  *
274  * sntp and ntpd each provide implementations adapted to their timers.
275  */
276 void
277 intres_timeout_req(
278 	u_int	seconds		/* 0 cancels */
279 	)
280 {
281 	if (0 == seconds) {
282 		worker_idle_timer = 0;
283 		return;
284 	}
285 	worker_idle_timer = current_time + seconds;
286 }
287 
288 
289 /*
290  * timer - event timer
291  */
292 void
293 timer(void)
294 {
295 	struct peer *	p;
296 	struct peer *	next_peer;
297 	l_fp		now;
298 	time_t          tnow;
299 
300 	/*
301 	 * The basic timerevent is one second.  This is used to adjust the
302 	 * system clock in time and frequency, implement the kiss-o'-death
303 	 * function and the association polling function.
304 	 */
305 	current_time++;
306 	if (adjust_timer <= current_time) {
307 		adjust_timer += 1;
308 		adj_host_clock();
309 #ifdef REFCLOCK
310 		for (p = peer_list; p != NULL; p = next_peer) {
311 			next_peer = p->p_link;
312 			if (FLAG_REFCLOCK & p->flags)
313 				refclock_timer(p);
314 		}
315 #endif /* REFCLOCK */
316 	}
317 
318 	/*
319 	 * Now dispatch any peers whose event timer has expired. Be
320 	 * careful here, since the peer structure might go away as the
321 	 * result of the call.
322 	 */
323 	for (p = peer_list; p != NULL; p = next_peer) {
324 		next_peer = p->p_link;
325 
326 		/*
327 		 * Restrain the non-burst packet rate not more
328 		 * than one packet every 16 seconds. This is
329 		 * usually tripped using iburst and minpoll of
330 		 * 128 s or less.
331 		 */
332 		if (p->throttle > 0)
333 			p->throttle--;
334 		if (p->nextdate <= current_time) {
335 #ifdef REFCLOCK
336 			if (FLAG_REFCLOCK & p->flags)
337 				refclock_transmit(p);
338 			else
339 #endif	/* REFCLOCK */
340 				transmit(p);
341 		}
342 	}
343 
344 	/*
345 	 * Orphan mode is active when enabled and when no servers less
346 	 * than the orphan stratum are available. A server with no other
347 	 * synchronization source is an orphan. It shows offset zero and
348 	 * reference ID the loopback address.
349 	 */
350 	if (sys_orphan < STRATUM_UNSPEC && sys_peer == NULL &&
351 	    current_time > orphwait) {
352 		if (sys_leap == LEAP_NOTINSYNC) {
353 			set_sys_leap(LEAP_NOWARNING);
354 #ifdef AUTOKEY
355 			if (crypto_flags)
356 				crypto_update();
357 #endif	/* AUTOKEY */
358 		}
359 		sys_stratum = (u_char)sys_orphan;
360 		if (sys_stratum > 1)
361 			sys_refid = htonl(LOOPBACKADR);
362 		else
363 			memcpy(&sys_refid, "LOOP", 4);
364 		sys_offset = 0;
365 		sys_rootdelay = 0;
366 		sys_rootdisp = 0;
367 	}
368 
369 	get_systime(&now);
370 	time(&tnow);
371 
372 	/*
373 	 * Leapseconds. Get time and defer to worker if either something
374 	 * is imminent or every 8th second.
375 	 */
376 	if (leapsec > LSPROX_NOWARN || 0 == (current_time & 7))
377 		check_leapsec(now.l_ui, &tnow,
378                                 (sys_leap == LEAP_NOTINSYNC));
379         if (sys_leap != LEAP_NOTINSYNC) {
380                 if (leapsec >= LSPROX_ANNOUNCE && leapdif) {
381 		        if (leapdif > 0)
382 			        set_sys_leap(LEAP_ADDSECOND);
383 		        else
384 			        set_sys_leap(LEAP_DELSECOND);
385                 } else {
386                         set_sys_leap(LEAP_NOWARNING);
387                 }
388 	}
389 
390 	/*
391 	 * Update huff-n'-puff filter.
392 	 */
393 	if (huffpuff_timer <= current_time) {
394 		huffpuff_timer += HUFFPUFF;
395 		huffpuff();
396 	}
397 
398 #ifdef AUTOKEY
399 	/*
400 	 * Garbage collect expired keys.
401 	 */
402 	if (keys_timer <= current_time) {
403 		keys_timer += 1 << sys_automax;
404 		auth_agekeys();
405 	}
406 
407 	/*
408 	 * Generate new private value. This causes all associations
409 	 * to regenerate cookies.
410 	 */
411 	if (revoke_timer && revoke_timer <= current_time) {
412 		revoke_timer += 1 << sys_revoke;
413 		RAND_bytes((u_char *)&sys_private, 4);
414 	}
415 #endif	/* AUTOKEY */
416 
417 	/*
418 	 * Interface update timer
419 	 */
420 	if (interface_interval && interface_timer <= current_time) {
421 		timer_interfacetimeout(current_time +
422 		    interface_interval);
423 		DPRINTF(2, ("timer: interface update\n"));
424 		interface_update(NULL, NULL);
425 	}
426 
427 	if (worker_idle_timer && worker_idle_timer <= current_time)
428 		worker_idle_timer_fired();
429 
430 	/*
431 	 * Finally, write hourly stats and do the hourly
432 	 * and daily leapfile checks.
433 	 */
434 	if (stats_timer <= current_time) {
435 		stats_timer += SECSPERHR;
436 		write_stats();
437 		if (leapf_timer <= current_time) {
438 			leapf_timer += SECSPERDAY;
439 			check_leap_file(TRUE, now.l_ui, &tnow);
440 		} else {
441 			check_leap_file(FALSE, now.l_ui, &tnow);
442 		}
443 	}
444 }
445 
446 
447 #ifndef SYS_WINNT
448 /*
449  * alarming - tell the world we've been alarmed
450  */
451 static RETSIGTYPE
452 alarming(
453 	int sig
454 	)
455 {
456 # ifdef DEBUG
457 	const char *msg = "alarming: initializing TRUE\n";
458 # endif
459 
460 	if (!initializing) {
461 		if (alarm_flag) {
462 			alarm_overflow++;
463 # ifdef DEBUG
464 			msg = "alarming: overflow\n";
465 # endif
466 		} else {
467 # ifndef VMS
468 			alarm_flag++;
469 # else
470 			/* VMS AST routine, increment is no good */
471 			alarm_flag = 1;
472 # endif
473 # ifdef DEBUG
474 			msg = "alarming: normal\n";
475 # endif
476 		}
477 	}
478 # ifdef VMS
479 	lib$addx(&vmsinc, &vmstimer, &vmstimer);
480 	sys$setimr(0, &vmstimer, alarming, alarming, 0);
481 # endif
482 # ifdef DEBUG
483 	if (debug >= 4)
484 		(void)(-1 == write(1, msg, strlen(msg)));
485 # endif
486 }
487 #endif /* SYS_WINNT */
488 
489 
490 void
491 timer_interfacetimeout(u_long timeout)
492 {
493 	interface_timer = timeout;
494 }
495 
496 
497 /*
498  * timer_clr_stats - clear timer module stat counters
499  */
500 void
501 timer_clr_stats(void)
502 {
503 	timer_overflows = 0;
504 	timer_xmtcalls = 0;
505 	timer_timereset = current_time;
506 }
507 
508 
509 static void
510 check_leap_sec_in_progress( const leap_result_t *lsdata ) {
511 	int prv_leap_sec_in_progress = leap_sec_in_progress;
512 	leap_sec_in_progress = lsdata->tai_diff && (lsdata->ddist < 3);
513 
514 	/* if changed we may have to update the leap status sent to clients */
515 	if (leap_sec_in_progress != prv_leap_sec_in_progress)
516 		set_sys_leap(sys_leap);
517 }
518 
519 
520 static void
521 check_leapsec(
522 	u_int32        now  ,
523 	const time_t * tpiv ,
524         int/*BOOL*/    reset)
525 {
526 	static const char leapmsg_p_step[] =
527 	    "Positive leap second, stepped backward.";
528 	static const char leapmsg_p_slew[] =
529 	    "Positive leap second, no step correction. "
530 	    "System clock will be inaccurate for a long time.";
531 
532 	static const char leapmsg_n_step[] =
533 	    "Negative leap second, stepped forward.";
534 	static const char leapmsg_n_slew[] =
535 	    "Negative leap second, no step correction. "
536 	    "System clock will be inaccurate for a long time.";
537 
538 	leap_result_t lsdata;
539 	u_int32       lsprox;
540 #ifdef AUTOKEY
541 	int/*BOOL*/   update_autokey = FALSE;
542 #endif
543 
544 #ifndef SYS_WINNT  /* WinNT port has its own leap second handling */
545 # ifdef KERNEL_PLL
546 	leapsec_electric(pll_control && kern_enable);
547 # else
548 	leapsec_electric(0);
549 # endif
550 #endif
551 #ifdef LEAP_SMEAR
552 	leap_smear.enabled = leap_smear_intv != 0;
553 #endif
554 	if (reset)	{
555 		lsprox = LSPROX_NOWARN;
556 		leapsec_reset_frame();
557 		memset(&lsdata, 0, sizeof(lsdata));
558 	} else {
559 	  int fired = leapsec_query(&lsdata, now, tpiv);
560 
561 	  DPRINTF(1, ("*** leapsec_query: fired %i, now %u (0x%08X), tai_diff %i, ddist %u\n",
562 		  fired, now, now, lsdata.tai_diff, lsdata.ddist));
563 
564 #ifdef LEAP_SMEAR
565 	  leap_smear.in_progress = 0;
566 	  leap_smear.doffset = 0.0;
567 
568 	  if (leap_smear.enabled) {
569 		if (lsdata.tai_diff) {
570 			if (leap_smear.interval == 0) {
571 				leap_smear.interval = leap_smear_intv;
572 				leap_smear.intv_end = lsdata.ttime.Q_s;
573 				leap_smear.intv_start = leap_smear.intv_end - leap_smear.interval;
574 				DPRINTF(1, ("*** leapsec_query: setting leap_smear interval %li, begin %.0f, end %.0f\n",
575 					leap_smear.interval, leap_smear.intv_start, leap_smear.intv_end));
576 			}
577 		}
578 		else {
579 			if (leap_smear.interval)
580 				DPRINTF(1, ("*** leapsec_query: clearing leap_smear interval\n"));
581 			leap_smear.interval = 0;
582 		}
583 
584 		if (leap_smear.interval) {
585 			double dtemp = now;
586 			if (dtemp >= leap_smear.intv_start && dtemp <= leap_smear.intv_end) {
587 				double leap_smear_time = dtemp - leap_smear.intv_start;
588 				/*
589 				 * For now we just do a linear interpolation over the smear interval
590 				 */
591 #if 0
592 				// linear interpolation
593 				leap_smear.doffset = -(leap_smear_time * lsdata.tai_diff / leap_smear.interval);
594 #else
595 				// Google approach: lie(t) = (1.0 - cos(pi * t / w)) / 2.0
596 				leap_smear.doffset = -((double) lsdata.tai_diff - cos( M_PI * leap_smear_time / leap_smear.interval)) / 2.0;
597 #endif
598 				/*
599 				 * TODO see if we're inside an inserted leap second, so we need to compute
600 				 * leap_smear.doffset = 1.0 - leap_smear.doffset
601 				 */
602 				leap_smear.in_progress = 1;
603 #if 0 && defined( DEBUG )
604 				msyslog(LOG_NOTICE, "*** leapsec_query: [%.0f:%.0f] (%li), now %u (%.0f), smear offset %.6f ms\n",
605 					leap_smear.intv_start, leap_smear.intv_end, leap_smear.interval,
606 					now, leap_smear_time, leap_smear.doffset);
607 #else
608 				DPRINTF(1, ("*** leapsec_query: [%.0f:%.0f] (%li), now %u (%.0f), smear offset %.6f ms\n",
609 					leap_smear.intv_start, leap_smear.intv_end, leap_smear.interval,
610 					now, leap_smear_time, leap_smear.doffset));
611 #endif
612 
613 			}
614 		}
615 	  }
616 	  else
617 		leap_smear.interval = 0;
618 
619 	  /*
620 	   * Update the current leap smear offset, eventually 0.0 if outside smear interval.
621 	   */
622 	  DTOLFP(leap_smear.doffset, &leap_smear.offset);
623 
624 #endif	/* LEAP_SMEAR */
625 
626 	  if (fired) {
627 		/* Full hit. Eventually step the clock, but always
628 		 * announce the leap event has happened.
629 		 */
630 		const char *leapmsg = NULL;
631 		if (lsdata.warped < 0) {
632 			if (clock_max_back > 0.0 &&
633 			    clock_max_back < abs(lsdata.warped)) {
634 				step_systime(lsdata.warped);
635 				leapmsg = leapmsg_p_step;
636 			} else {
637 				leapmsg = leapmsg_p_slew;
638 			}
639 		} else 	if (lsdata.warped > 0) {
640 			if (clock_max_fwd > 0.0 &&
641 			    clock_max_fwd < abs(lsdata.warped)) {
642 				step_systime(lsdata.warped);
643 				leapmsg = leapmsg_n_step;
644 			} else {
645 				leapmsg = leapmsg_n_slew;
646 			}
647 		}
648 		if (leapmsg)
649 			msyslog(LOG_NOTICE, "%s", leapmsg);
650 		report_event(EVNT_LEAP, NULL, NULL);
651 #ifdef AUTOKEY
652 		update_autokey = TRUE;
653 #endif
654 		lsprox  = LSPROX_NOWARN;
655 		leapsec = LSPROX_NOWARN;
656 		sys_tai = lsdata.tai_offs;
657 	  } else {
658 #ifdef AUTOKEY
659 		update_autokey = (sys_tai != (u_int)lsdata.tai_offs);
660 #endif
661 		lsprox  = lsdata.proximity;
662 		sys_tai = lsdata.tai_offs;
663 	  }
664 	}
665 
666 	/* We guard against panic alarming during the red alert phase.
667 	 * Strange and evil things might happen if we go from stone cold
668 	 * to piping hot in one step. If things are already that wobbly,
669 	 * we let the normal clock correction take over, even if a jump
670 	 * is involved.
671          * Also make sure the alarming events are edge-triggered, that is,
672          * ceated only when the threshold is crossed.
673          */
674 	if (  (leapsec > 0 || lsprox < LSPROX_ALERT)
675 	    && leapsec < lsprox                     ) {
676 		if (  leapsec < LSPROX_SCHEDULE
677                    && lsprox >= LSPROX_SCHEDULE) {
678 			if (lsdata.dynamic)
679 				report_event(PEVNT_ARMED, sys_peer, NULL);
680 			else
681 				report_event(EVNT_ARMED, NULL, NULL);
682 		}
683 		leapsec = lsprox;
684 	}
685 	if (leapsec > lsprox) {
686 		if (  leapsec >= LSPROX_SCHEDULE
687                    && lsprox   < LSPROX_SCHEDULE) {
688 			report_event(EVNT_DISARMED, NULL, NULL);
689 		}
690 		leapsec = lsprox;
691 	}
692 
693 	if (leapsec >= LSPROX_SCHEDULE)
694 		leapdif = lsdata.tai_diff;
695 	else
696 		leapdif = 0;
697 
698 	check_leap_sec_in_progress(&lsdata);
699 
700 #ifdef AUTOKEY
701 	if (update_autokey)
702 		crypto_update_taichange();
703 #endif
704 }
705