[Git][NTPsec/ntpsec][master] 2 commits: Add --disable-fuzz
Hal Murray
gitlab at mg.gitlab.com
Fri Dec 6 10:43:53 UTC 2019
Hal Murray pushed to branch master at NTPsec / ntpsec
Commits:
e218247e by Hal Murray at 2019-12-06T09:52:12Z
Add --disable-fuzz
tinker tick <number> is still left in the parser.
- - - - -
3fcdb750 by Hal Murray at 2019-12-06T10:33:34Z
Remove trailing space
- - - - -
13 changed files:
- include/ntp_fp.h
- include/ntp_stdlib.h
- include/ntpd.h
- libntp/systime.c
- ntpd/ntp_config.c
- ntpd/ntp_control.c
- ntpd/ntp_loopfilter.c
- ntpd/ntp_packetstamp.c
- ntpd/ntp_proto.c
- ntpd/ntpd.c
- tests/option-tester.sh
- wafhelpers/options.py
- wscript
Changes:
=====================================
include/ntp_fp.h
=====================================
@@ -161,7 +161,9 @@ extern char * prettydate (const l_fp);
extern char * rfc3339date (const l_fp);
extern char * rfc3339time (time_t);
+#ifdef ENABLE_FUZZ
extern void set_sys_fuzz (double);
+#endif
extern void get_systime (l_fp *);
extern bool step_systime (doubletime_t, int (*settime)(struct timespec *));
extern bool adj_systime (double, int (*adjtime)(const struct timeval *, struct timeval *));
=====================================
include/ntp_stdlib.h
=====================================
@@ -150,10 +150,12 @@ extern size_t strlcat(char *dst, const char *src, size_t siz);
/* ntp_proto.c */
extern double measured_tick; /* non-overridable sys_tick */
+#ifdef ENABLE_FUZZ
/* systime.c */
extern double sys_tick; /* tick size or time to read */
extern double sys_fuzz; /* min clock read latency */
extern bool trunc_os_clock; /* sys_tick > measured_tick */
+#endif
/* use these as return values for sort-comparison functions */
#define COMPARE_GREATERTHAN 1
=====================================
include/ntpd.h
=====================================
@@ -166,7 +166,9 @@ extern void poll_update (struct peer *, uint8_t);
extern void clock_filter (struct peer *, double, double, double);
extern void init_proto (const bool);
+#ifdef ENABLE_FUZZ
extern void set_sys_tick_precision(double);
+#endif
extern void proto_config (int, unsigned long, double);
extern void proto_clr_stats (void);
=====================================
libntp/systime.c
=====================================
@@ -56,12 +56,15 @@
* adj_systime() and step_systime() will behave sanely with these
* variables not set, but the adjustments may be in larger steps.
*/
+#ifdef ENABLE_FUZZ
double sys_tick = 0; /* tick size or time to read (s) */
double sys_fuzz = 0; /* min. time to read the clock (s) */
bool trunc_os_clock; /* sys_tick > measured_tick */
+#endif
time_stepped_callback step_callback;
static doubletime_t sys_residual = 0; /* adjustment residue (s) */
+#ifdef ENABLE_FUZZ
static long sys_fuzz_nsec = 0; /* minimum time to read clock (ns) */
/* perlinger at ntp.org: As 'get_systime()' does its own check for clock
@@ -70,9 +73,11 @@ static long sys_fuzz_nsec = 0; /* minimum time to read clock (ns) */
* static value could be removed after the v4.2.8 release.
*/
static bool lamport_violated; /* clock was stepped back */
+#endif
static void get_ostime (struct timespec *tsp);
+#ifdef ENABLE_FUZZ
void
set_sys_fuzz(
double fuzz_val
@@ -83,6 +88,7 @@ set_sys_fuzz(
//INSIST(sys_fuzz <= 1.0);
sys_fuzz_nsec = (long)(sys_fuzz * NS_PER_S + 0.5);
}
+#endif
static void
@@ -91,7 +97,6 @@ get_ostime(
)
{
int rc;
- long ticks;
rc = clock_gettime(CLOCK_REALTIME, tsp);
if (rc < 0) {
@@ -102,13 +107,17 @@ get_ostime(
exit(1);
}
+#ifdef ENABLE_FUZZ
if (trunc_os_clock) {
+ long ticks;
ticks = (long)((tsp->tv_nsec * S_PER_NS) / sys_tick);
tsp->tv_nsec = (long)(ticks * NS_PER_S * sys_tick);
}
+#endif
}
+#ifdef ENABLE_FUZZ
static void normalize_time (struct timespec, long, l_fp *);
static void
@@ -205,6 +214,7 @@ normalize_time(
lamport_violated = false;
*now = result;
}
+#endif
/*
* get_systime - return system time in NTP timestamp format.
@@ -216,7 +226,11 @@ get_systime(
{
struct timespec ts; /* seconds and nanoseconds */
get_ostime(&ts);
+#ifdef ENABLE_FUZZ
normalize_time(ts, sys_fuzz > 0.0 ? ntp_random() : 0, now);
+#else
+ *now = tspec_stamp_to_lfp(ts);
+#endif
}
@@ -264,11 +278,15 @@ adj_systime(
}
adjtv.tv_sec = (long)dtemp;
dtemp -= adjtv.tv_sec;
+#ifdef ENABLE_FUZZ
if (sys_tick > sys_fuzz) {
quant = sys_tick;
} else {
quant = S_PER_US;
}
+#else
+ quant = S_PER_US;
+#endif
ticks = (long)(dtemp / quant + .5);
adjtv.tv_usec = (long)(ticks * quant * US_PER_S + .5);
/* The rounding in the conversions could push us over the
@@ -415,7 +433,9 @@ step_systime(
}
sys_residual = 0;
+#ifdef ENABLE_FUZZ
lamport_violated = (step < 0);
+#endif
if (step_callback)
(*step_callback)();
return true;
=====================================
ntpd/ntp_config.c
=====================================
@@ -1972,8 +1972,13 @@ config_tinker(
break;
case T_Tick:
+#ifdef ENABLE_FUZZ
item = LOOP_TICK;
break;
+#else
+ msyslog(LOG_ERR, "ERR: tinker tick not supported");
+ continue;
+#endif
}
loop_config(item, tinker->value.d);
}
@@ -2563,9 +2568,11 @@ config_vars(
/* Determine which variable to set and set it */
switch (curr_var->attr) {
+#ifdef ENABLE_FUZZ
case T_Tick:
loop_config(LOOP_TICK, curr_var->value.d);
break;
+#endif
case T_Driftfile:
if ('\0' == curr_var->value.s[0]) {
=====================================
ntpd/ntp_control.c
=====================================
@@ -1941,7 +1941,11 @@ ctl_putsys(
case CS_FUZZ:
/* a.k.a. fuzz (s), output in ms */
+#ifdef ENABLE_FUZZ
ctl_putdbl6(sys_var[varid].text, sys_fuzz * MS_PER_S);
+#else
+ ctl_putdbl6(sys_var[varid].text, 0.0);
+#endif
break;
case CS_WANDER_THRESH:
@@ -1950,7 +1954,11 @@ ctl_putsys(
case CS_TICK:
/* a.k.a. sys_tick (s), output in ms */
+#ifdef ENABLE_FUZZ
ctl_putdbl6(sys_var[varid].text, sys_tick * MS_PER_S);
+#else
+ ctl_putdbl6(sys_var[varid].text, 0.0);
+#endif
break;
case CS_NUMCTLREQ:
=====================================
ntpd/ntp_loopfilter.c
=====================================
@@ -1298,9 +1298,11 @@ loop_config(
}
break;
+#ifdef ENABLE_FUZZ
case LOOP_TICK: /* tick increment (tick) */
set_sys_tick_precision(freq);
break;
+#endif
case LOOP_LEAP: /* not used, fall through */
default:
=====================================
ntpd/ntp_packetstamp.c
=====================================
@@ -91,9 +91,11 @@ fetch_packetstamp(
#elif defined(SO_TIMESTAMP)
struct timeval * tvp;
#endif
+#ifdef ENABLE_FUZZ
unsigned long ticks;
double fuzz;
l_fp lfpfuzz;
+#endif
l_fp nts = 0; /* network time stamp */
/* There should be only one cmsg. */
@@ -126,29 +128,34 @@ fetch_packetstamp(
#if defined(SO_TIMESTAMPNS)
tsp = (struct timespec *)CMSG_DATA(cmsghdr);
+#ifdef ENABLE_FUZZ
if (sys_tick > measured_tick && sys_tick > S_PER_NS) {
ticks = (unsigned long) ((tsp->tv_nsec * S_PER_NS) / sys_tick);
tsp->tv_nsec = (long) (ticks * NS_PER_S * sys_tick);
}
+#endif
DPRINT(4, ("fetch_timestamp: system nsec network time stamp: %ld.%09ld\n",
tsp->tv_sec, tsp->tv_nsec));
nts = tspec_stamp_to_lfp(*tsp);
#elif defined(SO_TIMESTAMP)
tvp = (struct timeval *)CMSG_DATA(cmsghdr);
+#ifdef ENABLE_FUZZ
if (sys_tick > measured_tick && sys_tick > S_PER_NS) {
ticks = (unsigned long) ((tvp->tv_usec * S_PER_NS) / sys_tick);
tvp->tv_usec = (long)(ticks * US_PER_S * sys_tick);
}
+#endif
DPRINT(4, ("fetch_timestamp: system usec network time stamp: %jd.%06ld\n",
(intmax_t)tvp->tv_sec, (long)tvp->tv_usec));
nts = tspec_stamp_to_lfp(tval_to_tspec(*tvp));
#else
# error "Can't get packet timestamp"
#endif
+#ifdef ENABLE_FUZZ
fuzz = ntp_random() * 2. / FRAC * sys_fuzz;
lfpfuzz = dtolfp(fuzz);
nts += lfpfuzz;
-
+#endif
return nts;
}
=====================================
ntpd/ntp_proto.c
=====================================
@@ -238,8 +238,10 @@ static void clock_select (void);
static void clock_update (struct peer *);
static void fast_xmit (struct recvbuf *, int, auth_info*, int);
static int local_refid (struct peer *);
+#ifdef ENABLE_FUZZ
static void measure_precision(const bool);
static double measure_tick_fuzz(void);
+#endif
static void peer_xmit (struct peer *);
static int peer_unfit (struct peer *);
static double root_distance (struct peer *);
@@ -2639,6 +2641,7 @@ peer_unfit(
}
+#ifdef ENABLE_FUZZ
/*
* Find the precision of this particular machine
*/
@@ -2746,7 +2749,6 @@ measure_tick_fuzz(void)
return tick;
}
-
void
set_sys_tick_precision(
double tick
@@ -2784,7 +2786,7 @@ set_sys_tick_precision(
sys_vars.sys_precision = (int8_t)i;
}
-
+#endif
/*
* init_proto - initialize the protocol module's data
@@ -2806,7 +2808,11 @@ init_proto(const bool verbose)
sys_vars.sys_rootdisp = 0;
sys_vars.sys_reftime = 0;
clkstate.sys_jitter = 0;
+#ifdef ENABLE_FUZZ
measure_precision(verbose);
+#else
+ UNUSED_ARG(verbose);
+#endif
get_systime(&dummy);
sys_survivors = 0;
stat_count.sys_stattime = current_time;
=====================================
ntpd/ntpd.c
=====================================
@@ -661,7 +661,7 @@ ntpdmain(
init_refclock();
# endif
set_process_priority();
- init_proto(!dumpopts); /* Call at high priority */
+ init_proto(!dumpopts); /* Call at high priority */
init_io();
init_loopfilter();
init_readconfig(); /* see readconfig() */
=====================================
tests/option-tester.sh
=====================================
@@ -59,7 +59,7 @@ doit minimal "--disable-droproot --disable-mdns-registration --disable-manpage"
# This also tests refclocks without DEBUG
doit classic "--enable-classic-mode --refclock=all --disable-manpage"
-doit all "--enable-warnings --enable-debug --enable-debug-gdb --enable-debug-timing --refclock=all --enable-leap-smear --enable-mssntp --enable-early-droproot $LINUX"
+doit all "--enable-warnings --enable-debug --enable-debug-gdb --enable-debug-timing --refclock=all --enable-leap-smear --enable-mssntp --enable-early-droproot --disable-fuzz $LINUX"
if [ "`which asciidoc 2>/dev/null`" != "" -a \
"`which xsltproc 2>/dev/null`" != "" ]
=====================================
wafhelpers/options.py
=====================================
@@ -81,6 +81,9 @@ def options_cmd(ctx, config):
grp.add_option('--undefine', type='string', action="callback",
callback=callback_flags,
help="Force undefinition of symbol.")
+ grp.add_option('--disable-fuzz', action='store_true',
+ default=False,
+ help="Disable fuzzing of low bits of time")
grp = ctx.add_option_group("NTP documentation configure options")
grp.add_option('--enable-doc', action='store_true',
=====================================
wscript
=====================================
@@ -792,6 +792,9 @@ int main(int argc, char **argv) {
if ctx.options.enable_early_droproot:
ctx.define("ENABLE_EARLY_DROPROOT", 1,
comment="Enable early drop root")
+ if not ctx.options.disable_fuzz:
+ ctx.define("ENABLE_FUZZ", 1,
+ comment="Enable fuzzing low bits of time")
# This is true under every Unix-like OS.
ctx.define("HAVE_WORKING_FORK", 1,
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/5d7907981b37832654a6cf3737763221481f72aa...3fcdb75085b256077802cdf5c08d903fed1df7ab
--
View it on GitLab: https://gitlab.com/NTPsec/ntpsec/compare/5d7907981b37832654a6cf3737763221481f72aa...3fcdb75085b256077802cdf5c08d903fed1df7ab
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.ntpsec.org/pipermail/vc/attachments/20191206/b5f3f449/attachment-0001.htm>
More information about the vc
mailing list