Skip to content

Commit

Permalink
ng_pipe: Replace deprecated random() with prng32_bounded()
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>

MFC after:	2 weeks
Reviewed by:	markj
Pull Request:	#1181

(cherry picked from commit a3ecf8c)
  • Loading branch information
Martin Vahlensieck authored and markjdb committed May 8, 2024
1 parent a3ca254 commit f4ab464
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions sys/netgraph/ng_pipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
#include <sys/kernel.h>
#include <sys/malloc.h>
#include <sys/mbuf.h>
#include <sys/prng.h>
#include <sys/time.h>

#include <vm/uma.h>
Expand Down Expand Up @@ -771,7 +772,7 @@ pipe_dequeue(struct hookinfo *hinfo, struct timeval *now) {
* the original packet...
*/
if (hinfo->cfg.duplicate &&
random() % 100 <= hinfo->cfg.duplicate) {
prng32_bounded(100) <= hinfo->cfg.duplicate) {
ngp_h = uma_zalloc(ngp_zone, M_NOWAIT);
KASSERT(ngp_h != NULL, ("ngp_h zalloc failed (3)"));
m = m_dup(m, M_NOWAIT);
Expand Down Expand Up @@ -814,7 +815,7 @@ pipe_dequeue(struct hookinfo *hinfo, struct timeval *now) {
/* Randomly discard the frame, according to BER setting */
if (hinfo->cfg.ber) {
oldrand = rand;
rand = random();
rand = prng32_bounded(1U << 31);
if (((oldrand ^ rand) << 17) >=
hinfo->ber_p[priv->overhead + m->m_pkthdr.len]) {
hinfo->stats.out_disc_frames++;
Expand Down

0 comments on commit f4ab464

Please sign in to comment.