[Git][NTPsec/ntpsec][master] Improvements to capture code. Capture ntp_set_tod and adjtime.
Eric S. Raymond
gitlab at mg.gitlab.com
Wed Dec 9 05:06:17 UTC 2015
Eric S. Raymond pushed to branch master at NTPsec / ntpsec
Commits:
ec010c7d by Eric S. Raymond at 2015-12-08T22:26:34Z
Improvements to capture code. Capture ntp_set_tod and adjtime.
- - - - -
7 changed files:
- include/ntp_fp.h
- libntp/systime.c
- ntpd/ntp_control.c
- ntpd/ntp_intercept.c
- ntpd/ntp_intercept.h
- ntpd/ntp_loopfilter.c
- ntpdig/main.c
Changes:
=====================================
include/ntp_fp.h
=====================================
--- a/include/ntp_fp.h
+++ b/include/ntp_fp.h
@@ -356,7 +356,7 @@ extern void get_ostime (struct timespec *tsp);
extern void normalize_time (struct timespec, long, l_fp *);
extern void get_systime (l_fp *);
extern bool step_systime (double);
-extern bool adj_systime (double);
+extern bool adj_systime (double, int (*adjtime)(const struct timeval *, struct timeval *));
extern struct tm * ntp2unix_tm (uint32_t ntp, int local);
=====================================
libntp/systime.c
=====================================
--- a/libntp/systime.c
+++ b/libntp/systime.c
@@ -321,7 +321,8 @@ normalize_time(
#if !defined SYS_WINNT
bool /* true on okay, false on error */
adj_systime(
- double now /* adjustment (s) */
+ double now, /* adjustment (s) */
+ int (*ladjtime)(const struct timeval *, struct timeval *)
)
{
struct timeval adjtv; /* new adjustment */
@@ -376,7 +377,7 @@ adj_systime(
sys_residual = -sys_residual;
}
if (adjtv.tv_sec != 0 || adjtv.tv_usec != 0) {
- if (adjtime(&adjtv, &oadjtv) < 0) {
+ if (ladjtime(&adjtv, &oadjtv) < 0) {
msyslog(LOG_ERR, "adj_systime: %m");
return false;
}
=====================================
ntpd/ntp_control.c
=====================================
--- a/ntpd/ntp_control.c
+++ b/ntpd/ntp_control.c
@@ -1697,7 +1697,7 @@ ctl_putsys(
if (CS_KERN_FIRST <= varid && varid <= CS_KERN_LAST &&
current_time != ntp_adjtime_time) {
ZERO(ntx);
- if (intercept_kernel_pll_adjtime(&ntx) < 0)
+ if (intercept_ntp_adjtime(&ntx) < 0)
msyslog(LOG_ERR, "ntp_adjtime() for mode 6 query failed: %m");
else
ntp_adjtime_time = current_time;
=====================================
ntpd/ntp_intercept.c
=====================================
--- a/ntpd/ntp_intercept.c
+++ b/ntpd/ntp_intercept.c
@@ -20,17 +20,19 @@ following kinds:
7. Alarm events.
-8. Calls to adjtime to set the system clock.
+8. Calls to adjtime/ntp_adjtime/adjtime to adjust the system clock.
-9. Read of the system leapsecond file.
+9 Calls to ntp_set_tod to ser the system clock.
-10. Packets incoming from NTP peers and others.
+10. Read of the system leapsecond file.
-11. Packets outgoing to NTP peers and others.
+11. Packets incoming from NTP peers and others.
-12. Read of authkey file
+12. Packets outgoing to NTP peers and others.
-13. Termination.
+13. Read of authkey file
+
+14. Termination.
We must support two modes of operation. In "capture" mode, ntpd
operates normally, logging all events. In "replay" mode, ntpd accepts
@@ -234,16 +236,17 @@ bool intercept_drift_read(const char *drift_file, double *drift)
}
if (mode != none)
- printf("event drift %.3f\n", *drift);
+ printf("event drift-read %.3f\n", *drift);
return true;
}
void intercept_drift_write(char *driftfile, double drift)
{
- if (mode == capture || mode == replay)
- printf("event drift %.3f\n", drift);
- else
+ if (mode != none)
+ printf("event drift-write %.3f\n", drift);
+
+ if (mode != replay)
{
int fd;
char tmpfile[PATH_MAX], driftcopy[PATH_MAX];
@@ -274,8 +277,21 @@ void intercept_drift_write(char *driftfile, double drift)
}
}
+int intercept_adjtime(const struct timeval *ntv, struct timeval *otv)
+/* old-fashioned BSD call for systems with no PLL */
+{
+ printf("event adjtime %ld %ld %ld %ld",
+ ntv->tv_sec, ntv->tv_usec, ntv->tv_sec, ntv->tv_usec);
+
+ if (mode != replay)
+ return adjtime(ntv, otv);
+
+ return 0;
+}
+
#ifdef HAVE_KERNEL_PLL
-int intercept_kernel_pll_adjtime(struct timex *tx)
+int intercept_ntp_adjtime(struct timex *tx)
+/* for newer systems with PLLs */
{
int res = 0;
@@ -285,7 +301,7 @@ int intercept_kernel_pll_adjtime(struct timex *tx)
res = ntp_adjtime(tx);
if (mode != none)
- printf("event adjtime %u %ld %ld %ld %ld %i %ld %ld %ld %ld %ld %i %ld %ld %ld %ld %d\n",
+ printf("event ntp_adjtime %u %ld %ld %ld %ld %i %ld %ld %ld %ld %ld %i %ld %ld %ld %ld %d\n",
tx->modes,
tx->offset,
tx->freq,
@@ -309,6 +325,18 @@ int intercept_kernel_pll_adjtime(struct timex *tx)
}
#endif
+int intercept_set_tod(struct timespec *tvs)
+{
+ if (mode != none)
+ printf("event set_tod %ld %ld\n", tvs->tv_sec, tvs->tv_nsec);
+
+ if (mode != replay)
+ return ntp_set_tod(tvs);
+
+ /* dodgy - returning success despite not setting time */
+ return 0;
+}
+
bool
intercept_leapsec_load_file(
const char * fname,
=====================================
ntpd/ntp_intercept.h
=====================================
--- a/ntpd/ntp_intercept.h
+++ b/ntpd/ntp_intercept.h
@@ -35,9 +35,11 @@ void intercept_sendpkt(const char *,
void intercept_receive(struct recvbuf *);
bool intercept_drift_read(const char *, double *);
void intercept_drift_write(char *, double);
+int intercept_adjtime(const struct timeval *, struct timeval *);
#ifdef HAVE_KERNEL_PLL
-int intercept_kernel_pll_adjtime(struct timex *);
+int intercept_ntp_adjtime(struct timex *);
#endif
+int intercept_set_tod(struct timespec *tvs);
extern bool intercept_leapsec_load_file(const char * fname, struct stat * sb,
bool force, bool logall);
void intercept_getauthkeys(const char *);
=====================================
ntpd/ntp_loopfilter.c
=====================================
--- a/ntpd/ntp_loopfilter.c
+++ b/ntpd/ntp_loopfilter.c
@@ -501,7 +501,7 @@ local_clock(
fp_offset);
printf("ntpd: time set %+.6fs\n", fp_offset);
} else {
- adj_systime(fp_offset);
+ adj_systime(fp_offset, intercept_adjtime);
msyslog(LOG_NOTICE, "ntpd: time slew %+.6f s",
fp_offset);
printf("ntpd: time slew %+.6fs\n", fp_offset);
@@ -662,7 +662,7 @@ local_clock(
* the stepout threshold.
*/
case EVNT_NSET:
- adj_systime(fp_offset);
+ adj_systime(fp_offset, intercept_adjtime);
rstclock(EVNT_FREQ, fp_offset);
break;
@@ -805,7 +805,7 @@ local_clock(
* the pps. In any case, fetch the kernel offset,
* frequency and jitter.
*/
- ntp_adj_ret = intercept_kernel_pll_adjtime(&ntv);
+ ntp_adj_ret = intercept_ntp_adjtime(&ntv);
/*
* A squeal is a return status < 0, or a state change.
*/
@@ -840,7 +840,7 @@ local_clock(
loop_tai = sys_tai;
ntv.modes = MOD_TAI;
ntv.constant = sys_tai;
- if ((ntp_adj_ret = intercept_kernel_pll_adjtime(&ntv)) != 0) {
+ if ((ntp_adj_ret = intercept_ntp_adjtime(&ntv)) != 0) {
ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, false, true, __LINE__ - 1);
}
}
@@ -997,7 +997,7 @@ adj_host_clock(
* but does not automatically stop slewing when an offset
* has decayed to zero.
*/
- adj_systime(offset_adj + freq_adj);
+ adj_systime(offset_adj + freq_adj, intercept_adjtime);
#endif /* ENABLE_LOCKCLOCK */
}
@@ -1077,7 +1077,7 @@ set_freq(
loop_desc = "kernel";
ntv.freq = DTOFREQ(drift_comp);
}
- if ((ntp_adj_ret = intercept_kernel_pll_adjtime(&ntv)) != 0) {
+ if ((ntp_adj_ret = intercept_ntp_adjtime(&ntv)) != 0) {
ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, false, false, __LINE__ - 1);
}
}
@@ -1114,7 +1114,7 @@ start_kern_loop(void)
pll_control = false;
} else {
if (sigsetjmp(env, 1) == 0) {
- if ((ntp_adj_ret = intercept_kernel_pll_adjtime(&ntv)) != 0) {
+ if ((ntp_adj_ret = intercept_ntp_adjtime(&ntv)) != 0) {
ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, false, false, __LINE__ - 1);
}
}
@@ -1125,7 +1125,7 @@ start_kern_loop(void)
}
}
#else /* SIGSYS */
- if ((ntp_adj_ret = intercept_kernel_pll_adjtime(&ntv)) != 0) {
+ if ((ntp_adj_ret = intercept_ntp_adjtime(&ntv)) != 0) {
ntp_adjtime_error_handler(__func__, &ntv, ntp_adj_ret, errno, false, false, __LINE__ - 1);
}
#endif /* SIGSYS */
@@ -1274,7 +1274,7 @@ loop_config(
memset((char *)&ntv, 0, sizeof(ntv));
ntv.modes = MOD_STATUS;
ntv.status = STA_UNSYNC;
- intercept_kernel_pll_adjtime(&ntv);
+ intercept_ntp_adjtime(&ntv);
sync_status("kernel time sync disabled",
pll_status,
ntv.status);
=====================================
ntpdig/main.c
=====================================
--- a/ntpdig/main.c
+++ b/ntpdig/main.c
@@ -1572,7 +1572,7 @@ set_time(
}
if (opt_slew) {
- rc = adj_systime(offset);
+ rc = adj_systime(offset, adjtime);
/* If there was a problem, can we rely on errno? */
if (rc)
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/commit/ec010c7d466c66bc51ee8eb3f71e20aff7631548
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ntpsec.org/pipermail/vc/attachments/20151209/e045282a/attachment.html>
More information about the vc
mailing list