git: f4ab464d3492 - stable/14 - ng_pipe: Replace deprecated random() with prng32_bounded()

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 08 May 2024 13:07:50 UTC
The branch stable/14 has been updated by markj:

URL: https://cgit.FreeBSD.org/src/commit/?id=f4ab464d3492c8ad6d3d0a4851e382e40d438a19

commit f4ab464d3492c8ad6d3d0a4851e382e40d438a19
Author:     Martin Vahlensieck <git@academicsolutions.ch>
AuthorDate: 2024-04-17 18:59:22 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-05-08 13:06:16 +0000

    ng_pipe: Replace deprecated random() with prng32_bounded()
    
    Signed-off-by: Martin Vahlensieck <git@academicsolutions.ch>
    
    MFC after:      2 weeks
    Reviewed by:    markj
    Pull Request:   https://github.com/freebsd/freebsd-src/pull/1181
    
    (cherry picked from commit a3ecf8c7863683e53c77a17f96ab7012352265b9)
---
 sys/netgraph/ng_pipe.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/netgraph/ng_pipe.c b/sys/netgraph/ng_pipe.c
index 7afaf24f5914..d368c142b1ab 100644
--- a/sys/netgraph/ng_pipe.c
+++ b/sys/netgraph/ng_pipe.c
@@ -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>
@@ -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);
@@ -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++;