]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 3640] sidekick: fixed "discard monitor" implementation
authorJuergen Perlinger <perlinger@ntp.org>
Sun, 13 Nov 2022 08:47:08 +0000 (09:47 +0100)
committerJuergen Perlinger <perlinger@ntp.org>
Sun, 13 Nov 2022 08:47:08 +0000 (09:47 +0100)
bk: 6370af0c2dixLDDTTrOHMhX27Qc33A

ChangeLog
include/ntp_random.h
libntp/ntp_random.c
libntp/systime.c
ntpd/ntp_io.c
ntpd/ntp_monitor.c
ntpd/ntp_proto.c

index 3addb7b81eaef60a58c74b960291d16ae7370602..51a731231d15dfbc1083a307442227808f9b06c7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -37,6 +37,8 @@
 * [Bug 3672] fix biased selection in median cut <perlinger@ntp.org>
 * [Bug 3666] avoid unlimited receive buffer allocation <perlinger@ntp.org>
   - follow-up: fix inverted sense in check, reset shortfall counter
+* [Bug 3640] ntp.conf: missing documentation for "discard monitor" default value
+  - sidekick: fixed a bug in discard monitor implementation <perlingeræntp.org>
 * [Bug 3626] (SNTP) UTC offset calculation needs dst flag <perlinger@ntp.org>
   - applied patch by Gerry Garvey
 * [Bug 3432] refclocks that 'write()' should check the result <perlinger@ntp.org>
index fa77f6553ec657c5dad3ee8dc5f9b42baf26133f..931b2199020e48dd3195936878759294792b751a 100644 (file)
@@ -5,6 +5,7 @@ void ntp_crypto_srandom(void);
 int ntp_crypto_random_buf(void *buf, size_t nbytes);
 
 long ntp_random (void);
+double ntp_uurandom(void);
 void ntp_srandom (unsigned long);
 void ntp_srandomdev (void);
 char * ntp_initstate (unsigned long,   /* seed for R.N.G. */
index 0ada44f256b042fc5f6c7286013890dc5a7e8cdc..83806c420425c6f7cd57c9a90417bdad5c60fd9f 100644 (file)
@@ -497,3 +497,18 @@ ntp_random( void )
        }
        return(i);
 }
+
+/*
+ * ntp_uurandom()
+ *
+ * Generate a Uniform-distributed Unity based random number. Replaces a
+ * few locations where the transformation was made in an ad-hoc style
+ * (and in one instance, wrong...)
+ *
+ * returns a number in [0.0 .. 1.0], both ends inclusive
+ */
+double
+ntp_uurandom( void )
+{
+       return (double)ntp_random() / 0x7FFFFFFFu;
+}
index a738c8d924dd0e6bd1a12376f9c2c4c8c630aeff..e2f07f71aa924d2f0e86e77332bffe8d4bf09218 100644 (file)
@@ -235,7 +235,7 @@ get_systime(
         * must scale up the result by 2.0 to cover the full fractional
         * range.
         */
-       dfuzz = ntp_random() * 2. / FRAC * sys_fuzz;
+       dfuzz = ntp_uurandom() * sys_fuzz;
        DTOLFP(dfuzz, &lfpfuzz);
        L_ADD(&result, &lfpfuzz);
 
index c0dcea598121e72a6fa3a7a11a65a37d22b85c62..6b88f5e4d9604b2f52f18f4bba636139589d818c 100644 (file)
@@ -3444,7 +3444,7 @@ fetch_timestamp(
                                break;
 #endif  /* HAVE_TIMESTAMP */
                        }
-                       fuzz = ntp_random() * 2. / FRAC * sys_fuzz;
+                       fuzz = ntp_uurandom() * sys_fuzz;
                        DTOLFP(fuzz, &lfpfuzz);
                        L_ADD(&nts, &lfpfuzz);
 #ifdef DEBUG_TIMING
index a07a1aaef1962ac99eb135b2602f5c87f2c029e5..5252794fd359b3e380513f038e26fec58807e7b5 100644 (file)
@@ -459,7 +459,7 @@ ntp_monitor(
                                mon_getmoremem();
                        UNLINK_HEAD_SLIST(mon, mon_free, hash_next);
                /* Preempt from the MRU list if old enough. */
-               } else if (ntp_random() / (2. * FRAC) >
+               } else if (ntp_uurandom() >
                           (double)oldest_age / mon_age) {
                        return ~(RES_LIMITED | RES_KOD) & flags;
                } else {
index 898ff73eecdd41fac545e9e1f76892495582092b..7992ef0f085719959052122675fb6fa5278b01da 100644 (file)
@@ -740,7 +740,7 @@ receive(
         * surviving packets.
         */
        if (restrict_mask & RES_FLAKE) {
-               if ((double)ntp_random() / 0x7fffffff < .1) {
+               if (ntp_uurandom() < .1) {
                        DPRINTF(2, ("receive: drop: RES_FLAKE\n"));
                        sys_restricted++;
                        return;                 /* no flakeway */