Skip to content

Commit

Permalink
Add constant that results in getrandom() being used to generate seed …
Browse files Browse the repository at this point in the history
…for complete randomness.
  • Loading branch information
gamemann committed May 22, 2024
1 parent a04363a commit 6b0b55e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
19 changes: 10 additions & 9 deletions src/sequence.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

#include <csum.h>

#ifdef VERY_RANDOM
#include <sys/random.h>
#endif

pthread_t threads[MAX_THREADS];
int thread_cnt = 0;

Expand Down Expand Up @@ -429,15 +433,12 @@ void *thread_hdl(void *temp)
// Retrieve current time since boot.
clock_gettime(CLOCK_BOOTTIME, &ts);

// Generate seed (we use nanoseconds for better precision/randomness).
seed = ts.tv_nsec;

// Add some more randomness if track is enabled.
if (ti->seq.track)
{
seed ^= total_pckts[ti->seq_cnt];
}

// Generate seed.
#ifdef VERY_RANDOM
getrandom(&seed, sizeof(seed), 0);
#else
seed = ts.tv_nsec;
#endif
// Check if we need to generate random IP TTL.
if (ti->seq.ip.min_ttl != ti->seq.ip.max_ttl)
{
Expand Down
2 changes: 2 additions & 0 deletions src/sequence.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#include "af_xdp.h"
#include "main.h"

//#define VERY_RANDOM

#define MAX_PCKT_LEN 0xFFFF
#define MAX_THREADS 4096
#define MAX_NAME_LEN 64
Expand Down

0 comments on commit 6b0b55e

Please sign in to comment.