Skip to content

Commit 9c87b2a

Browse files
francoismichelkuba-moo
authored andcommitted
netem: use a seeded PRNG for generating random losses
Use prandom_u32_state() instead of get_random_u32() to generate the random loss events of netem. The state of the prng is part of the prng attribute of struct netem_sched_data. Signed-off-by: François Michel <francois.michel@uclouvain.be> Reviewed-by: Simon Horman <horms@kernel.org> Acked-by: Stephen Hemminger <stephen@networkplumber.org> Link: https://lore.kernel.org/r/20230815092348.1449179-3-francois.michel@uclouvain.be Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 4072d97 commit 9c87b2a

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

net/sched/sch_netem.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ static u32 get_crandom(struct crndstate *state)
206206
static bool loss_4state(struct netem_sched_data *q)
207207
{
208208
struct clgstate *clg = &q->clg;
209-
u32 rnd = get_random_u32();
209+
u32 rnd = prandom_u32_state(&q->prng.prng_state);
210210

211211
/*
212212
* Makes a comparison between rnd and the transition
@@ -271,18 +271,19 @@ static bool loss_4state(struct netem_sched_data *q)
271271
static bool loss_gilb_ell(struct netem_sched_data *q)
272272
{
273273
struct clgstate *clg = &q->clg;
274+
struct rnd_state *s = &q->prng.prng_state;
274275

275276
switch (clg->state) {
276277
case GOOD_STATE:
277-
if (get_random_u32() < clg->a1)
278+
if (prandom_u32_state(s) < clg->a1)
278279
clg->state = BAD_STATE;
279-
if (get_random_u32() < clg->a4)
280+
if (prandom_u32_state(s) < clg->a4)
280281
return true;
281282
break;
282283
case BAD_STATE:
283-
if (get_random_u32() < clg->a2)
284+
if (prandom_u32_state(s) < clg->a2)
284285
clg->state = GOOD_STATE;
285-
if (get_random_u32() > clg->a3)
286+
if (prandom_u32_state(s) > clg->a3)
286287
return true;
287288
}
288289

0 commit comments

Comments
 (0)