Skip to content
Snippets Groups Projects
Commit cf99b754 authored by Guy Zana's avatar Guy Zana
Browse files

bsd: fix read_random() make it appear more randomized.

read_random() is used indirectly by the TCP stack to randomize a local port number,
before this patch it was identical in each execution, and that caused NAT problems.

also add a FIXME note to implement real random one day.
parent 30ab1c50
No related branches found
No related tags found
No related merge requests found
...@@ -31,11 +31,14 @@ static struct mtx arc4_mtx; ...@@ -31,11 +31,14 @@ static struct mtx arc4_mtx;
static u_int8_t arc4_randbyte(void); static u_int8_t arc4_randbyte(void);
uint8_t read_random_gen = 0; /* FIXME: OSv - use real random */
int read_random(void* buf, int count) int read_random(void* buf, int count)
{ {
struct timeval tv;
getmicrotime(&tv);
for (int i=0; i<count; i++) { for (int i=0; i<count; i++) {
((uint8_t *)buf)[i] = read_random_gen++; ((uint8_t *)buf)[i] = tv.tv_usec & 0xFF;
tv.tv_usec *= 7;
} }
return (count); return (count);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment