svn commit: r361422 - head/sys/netinet/tcp_stacks
Emmanuel Vadot
manu at FreeBSD.org
Sat May 23 19:52:21 UTC 2020
Author: manu
Date: Sat May 23 19:52:20 2020
New Revision: 361422
URL: https://svnweb.freebsd.org/changeset/base/361422
Log:
bbr: Use arc4random_uniform from libkern.
This unbreak LINT build
Reported by: jenkins, melifaro
Modified:
head/sys/netinet/tcp_stacks/bbr.c
Modified: head/sys/netinet/tcp_stacks/bbr.c
==============================================================================
--- head/sys/netinet/tcp_stacks/bbr.c Sat May 23 19:06:57 2020 (r361421)
+++ head/sys/netinet/tcp_stacks/bbr.c Sat May 23 19:52:20 2020 (r361422)
@@ -43,6 +43,7 @@ __FBSDID("$FreeBSD$");
#include <sys/arb.h>
#include <sys/module.h>
#include <sys/kernel.h>
+#include <sys/libkern.h>
#ifdef TCP_HHOOK
#include <sys/hhook.h>
#endif
@@ -3095,43 +3096,6 @@ bbr_lt_bw_samp_done(struct tcp_bbr *bbr, uint64_t bw,
bbr->r_ctl.rc_lt_bw = bw;
bbr_reset_lt_bw_interval(bbr, cts);
bbr_log_type_ltbw(bbr, cts, 5, 0, (uint32_t)bw, 0, timin);
-}
-
-/*
- * RRS: Copied from user space!
- * Calculate a uniformly distributed random number less than upper_bound
- * avoiding "modulo bias".
- *
- * Uniformity is achieved by generating new random numbers until the one
- * returned is outside the range [0, 2**32 % upper_bound). This
- * guarantees the selected random number will be inside
- * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
- * after reduction modulo upper_bound.
- */
-static uint32_t
-arc4random_uniform(uint32_t upper_bound)
-{
- uint32_t r, min;
-
- if (upper_bound < 2)
- return 0;
-
- /* 2**32 % x == (2**32 - x) % x */
- min = -upper_bound % upper_bound;
-
- /*
- * This could theoretically loop forever but each retry has
- * p > 0.5 (worst case, usually far better) of selecting a
- * number inside the range we need, so it should rarely need
- * to re-roll.
- */
- for (;;) {
- r = arc4random();
- if (r >= min)
- break;
- }
-
- return r % upper_bound;
}
static void
More information about the svn-src-head
mailing list