Skip to content

Commit

Permalink
Merge pull request #938 from donghaobo/random
Browse files Browse the repository at this point in the history
use better random source
  • Loading branch information
ywc689 authored Apr 10, 2024
2 parents 3ec1d59 + 180e1fb commit cead683
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/ipvs/ip_vs_synproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*
*/
#include <assert.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include <openssl/md5.h>
Expand Down Expand Up @@ -117,15 +120,35 @@ static int second_timer_expire(void *priv)
}
#endif

static int generate_random_key(void *key, unsigned length)
{
int fd;
int ret;

fd = open("/dev/urandom", O_RDONLY);
if (fd < 0) {
return -1;
}
ret = read(fd, key, length);
close(fd);

if (ret != (signed)length) {
return -1;
}
return 0;
}

int dp_vs_synproxy_init(void)
{
int i;
char ack_mbufpool_name[32];
struct timeval tv;

for (i = 0; i < MD5_LBLOCK; i++) {
g_net_secret[0][i] = (uint32_t)random();
g_net_secret[1][i] = (uint32_t)random();
if (generate_random_key(g_net_secret, sizeof(g_net_secret))) {
for (i = 0; i < MD5_LBLOCK; i++) {
g_net_secret[0][i] = (uint32_t)random();
g_net_secret[1][i] = (uint32_t)random();
}
}

rte_atomic32_set(&g_minute_count, (uint32_t)random());
Expand Down

0 comments on commit cead683

Please sign in to comment.