]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
simplified isc_random_jitter() and eliminated floating
authorAndreas Gustafsson <source@isc.org>
Tue, 26 Sep 2000 17:23:19 +0000 (17:23 +0000)
committerAndreas Gustafsson <source@isc.org>
Tue, 26 Sep 2000 17:23:19 +0000 (17:23 +0000)
point from the code using it in zone.c

CHANGES
lib/dns/zone.c
lib/isc/include/isc/random.h
lib/isc/random.c

diff --git a/CHANGES b/CHANGES
index b938295d8717ef3f4b386cce0a2de72d27943c02..156c63ee30e65d03031c7c19fe600deb113294d9 100644 (file)
--- a/CHANGES
+++ b/CHANGES
                        to break up the key data in a "trusted-keys"
                        statement into multiple lines. [RT #284]
 
- 432.  [func]          Added refresh/retry jitter.  This is currently
-                       hard-coded to be no more than 20% of the SOA
-                       provided time or 10 minutes, whichever is less.
+ 432.  [func]          Added refresh/retry jitter.  The actual refresh/
+                       retry time is now a random value between 75% and
+                       100% of the configured value.
 
  431.  [func]          Log at ISC_LOG_INFO when a zone is successfully
                        loaded.
index 9a232632493599aa2ad715f0b1608acaff58318b..0d18520a238e8a6b7a649a5cd87c5e57642c2347 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: zone.c,v 1.218 2000/09/26 16:32:39 gson Exp $ */
+/* $Id: zone.c,v 1.219 2000/09/26 17:23:19 gson Exp $ */
 
 #include <config.h>
 
@@ -90,9 +90,6 @@
 #define DNS_MAX_EXPIRE 14515200        /* 24 weeks */
 #endif
 
-#define REFRESH_JITTER         600     /* seconds */
-#define RETRY_JITTER           600
-
 typedef struct dns_notify dns_notify_t;
 typedef struct dns_stub dns_stub_t;
 typedef struct dns_load dns_load_t;
@@ -1784,9 +1781,8 @@ dns_zone_refresh(dns_zone_t *zone) {
         * Setting this to the retry time will do that.  XXXMLG
         * If we are successful it will be reset using zone->refresh.
         */
-       zone->refreshtime = now + isc_random_jitter(zone->retry,
-                                                   zone->retry * .80,
-                                                   RETRY_JITTER);
+       zone->refreshtime = now +
+               isc_random_jitter(zone->retry, zone->retry / 4);
        zone_log(zone, "dns_zone_refresh", ISC_LOG_DEBUG(20),
                 "refresh time (%u/%u), now %u",
                 zone->refreshtime, zone->refresh, now);
@@ -2677,8 +2673,7 @@ stub_callback(isc_task_t *task, isc_event_t *event) {
        LOCK(&zone->lock);
        zone->flags &= ~DNS_ZONEFLG_REFRESH;
        zone->refreshtime = now +
-               isc_random_jitter(zone->refresh, zone->refresh * .80,
-                                 REFRESH_JITTER);
+               isc_random_jitter(zone->refresh, zone->refresh / 4);
        zone->expiretime = now + zone->expire;
        zone_log(zone, me, ISC_LOG_DEBUG(20),
                 "refresh time (%u/%u), now %u",
@@ -2925,8 +2920,7 @@ refresh_callback(isc_task_t *task, isc_event_t *event) {
                                         dns_result_totext(result));
                }
                zone->refreshtime = now +
-                       isc_random_jitter(zone->refresh, zone->refresh * .80,
-                                         REFRESH_JITTER);
+                       isc_random_jitter(zone->refresh, zone->refresh / 4);
                zone->expiretime = now + zone->expire;
                zone_log(zone, me, ISC_LOG_DEBUG(20),
                         "refresh time (%u/%u), now %u",
@@ -4275,8 +4269,7 @@ zone_xfrdone(dns_zone_t *zone, isc_result_t result) {
                } else {
                        zone->refreshtime = now +
                                isc_random_jitter(zone->refresh,
-                                                 zone->refresh * .80,
-                                                 REFRESH_JITTER);
+                                                 zone->refresh / 4);
                        zone_log(zone, me, ISC_LOG_DEBUG(20),
                                 "refresh time (%u/%u), now %u",
                                 zone->refreshtime, zone->refresh, now);
index f5b79d633a92409e2559f4afd5c740d6a26663ca..1801ec9e4110b6e2da5bec903534554db7a6c214 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: random.h,v 1.9 2000/09/06 16:25:35 gson Exp $ */
+/* $Id: random.h,v 1.10 2000/09/26 17:23:16 gson Exp $ */
 
 #ifndef ISC_RANDOM_H
 #define ISC_RANDOM_H 1
@@ -49,11 +49,10 @@ isc_random_get(isc_uint32_t *val);
  */
 
 isc_uint32_t
-isc_random_jitter(isc_uint32_t max, isc_uint32_t min, isc_uint32_t jitter);
+isc_random_jitter(isc_uint32_t max, isc_uint32_t jitter);
 /*
- * Return a value between (max - jitter) and (max).
- *
- * If (max - min) < jitter, the maximum jitter becomes (max - min) instead.
+ * Get a random value between (max - jitter) and (max).
+ * This is useful for jittering timer values.
  */
 
 ISC_LANG_ENDDECLS
index 0e812997d2961f175810a91f6612c1b79473719d..4434345c80255a4082e48eeb6e556ec07a468f6c 100644 (file)
@@ -15,7 +15,7 @@
  * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
-/* $Id: random.c,v 1.12 2000/09/08 00:06:39 explorer Exp $ */
+/* $Id: random.c,v 1.13 2000/09/26 17:23:17 gson Exp $ */
 
 #include <config.h>
 
@@ -60,22 +60,10 @@ isc_random_get(isc_uint32_t *val)
 }
 
 isc_uint32_t
-isc_random_jitter(isc_uint32_t max, isc_uint32_t min, isc_uint32_t jitter) {
-       isc_uint32_t val;
-
-       REQUIRE(jitter > 0);
-
-       if (min >= max)
-               return (min);
-
-       /*
-        * Don't allow jitter to be more than max - min.
-        */
-       if (jitter > max - min)
-               jitter = max - min;
+isc_random_jitter(isc_uint32_t max, isc_uint32_t jitter) {
+       REQUIRE(jitter < max);
        if (jitter == 0)
-               return (min);
-
-       val = rand() % jitter;
-       return (max - val);
+               return (max);
+       else
+               return (max - rand() % jitter);
 }