diff options
author | Thomas Huth <thuth@redhat.com> | 2015-12-22 11:08:40 +0100 |
---|---|---|
committer | Alexey Kardashevskiy <aik@ozlabs.ru> | 2015-12-23 13:01:19 +1100 |
commit | 2c49891b555baa62ecd1b252317d6ebd1605579c (patch) | |
tree | 8e4e32e0b57ff282ef27b25ecb6168a642965633 /clients | |
parent | 48ae29e4c070874ff94adbc97a4b07f66c3d55e1 (diff) | |
download | SLOF-2c49891b555baa62ecd1b252317d6ebd1605579c.zip SLOF-2c49891b555baa62ecd1b252317d6ebd1605579c.tar.gz SLOF-2c49891b555baa62ecd1b252317d6ebd1605579c.tar.bz2 |
net-snk: Seed the pseudo-random number generator
Use the MAC address and the current timebase value to seed the
pseudo-random number generator - this will hopefully give use
enough pseudo-randomness so that two guests that are booting in
parallel won't use the same rand() numbers.
Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'clients')
-rw-r--r-- | clients/net-snk/app/netapps/netboot.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/clients/net-snk/app/netapps/netboot.c b/clients/net-snk/app/netapps/netboot.c index 5b7cefa..74fc235 100644 --- a/clients/net-snk/app/netapps/netboot.c +++ b/clients/net-snk/app/netapps/netboot.c @@ -367,6 +367,18 @@ int dhcp(char *ret_buffer, filename_ip_t * fn_ip, unsigned int retries, int flag return rc; } +/** + * Seed the random number generator with our mac and current timestamp + */ +static void seed_rng(uint8_t mac[]) +{ + unsigned int seed; + + asm volatile("mftbl %0" : "=r"(seed)); + seed ^= (mac[2] << 24) | (mac[3] << 16) | (mac[4] << 8) | mac[5]; + srand(seed); +} + int netboot(int argc, char *argv[]) { @@ -437,6 +449,8 @@ netboot(int argc, char *argv[]) // init ethernet layer set_mac_address(own_mac); + seed_rng(own_mac); + if (argc > 6) { parse_args(argv[6], &obp_tftp_args); if(obp_tftp_args.bootp_retries - rc < DEFAULT_BOOT_RETRIES) |