bbr: Use arc4random_uniform from libkern.
This unbreak LINT build Reported by: jenkins, melifaro
This commit is contained in:
parent
4d2c2509f2
commit
77c68315f6
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=361422
@ -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
|
||||
@ -3097,43 +3098,6 @@ bbr_lt_bw_samp_done(struct tcp_bbr *bbr, uint64_t bw, uint32_t cts, uint32_t tim
|
||||
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
|
||||
bbr_randomize_extra_state_time(struct tcp_bbr *bbr)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user