On Mon, 14 Aug 2023 04:31:39 +0200
Francois Michel <francois.michel@xxxxxxxxxxxx> wrote:
+/* netem_get_random_u32 - polls a new random 32-bits integer from
+ * the prng.
+ * Uses a deterministic seeded prng if p->deterministic_rng is true.
+ * Uses get_random_u32() underneath if p is NULL or if p->deterministic_rng
+ * is false.
+ */
+static u32 netem_get_random_u32(struct prng *p)
Overall I am fine with this patch, but the function name is getting excessively
long. It is a local function, so no need for netem_ prefix.
Checking for p == NULL is redundant, all callers are passing a valid pointer.
For logical consistency, put the new wrapper before init_crandom() and after netem_skb_cb().
Since this is not security related, the change could also be simplified to just
always prandom_u32_state() and initialize the state on first use with either
get_random or provided seed. This would also simplify the code around storing
original seed and boolean.
Reminds me of the quote attributed to Mark Twain:
“I apologize for such a long letter - I didn't have time to write a short one.”