From 95ad79bc6d15c64b2770fe8b7092a64d5c2a293c Mon Sep 17 00:00:00 2001 From: Syrone Wong Date: Tue, 10 Jan 2023 11:04:25 +0800 Subject: [PATCH] nf_nat_fullcone.c: fix missing prandom_u32() with Linux >= 6.1.0 prandom_u32() previously was only calling get_random_u32() so it's been dropped with Linux 6.1.0. So let's directly call get_random_u32() if Linux version >= 6.1.0. Signed-off-by: Syrone Wong --- src/nf_nat_fullcone.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/nf_nat_fullcone.c b/src/nf_nat_fullcone.c index 0757ef9..0b13cbe 100644 --- a/src/nf_nat_fullcone.c +++ b/src/nf_nat_fullcone.c @@ -854,7 +854,11 @@ static uint16_t find_appropriate_port6(struct net *net, const u16 zone, /* for now we do the same thing for both --random and --random-fully */ /* select a random starting point */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) + start = (uint16_t) (get_random_u32() % (u32) range_size); +#else start = (uint16_t) (prandom_u32() % (u32) range_size); +#endif } else { if ((original_port >= min && original_port <= min + range_size - 1) @@ -927,7 +931,11 @@ static uint16_t find_appropriate_port(struct net *net, const u16 zone, /* for now we do the same thing for both --random and --random-fully */ /* select a random starting point */ +#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0) + start = (uint16_t) (get_random_u32() % (u32) range_size); +#else start = (uint16_t) (prandom_u32() % (u32) range_size); +#endif } else { if ((original_port >= min && original_port <= min + range_size - 1)