[SLOF] [PATCH 4/7] net-snk: Seed the pseudo-random number generator
Stefan Berger
stefanb at linux.vnet.ibm.com
Tue Dec 22 02:49:31 AEDT 2015
On 12/17/2015 03:18 PM, Thomas Huth wrote:
> 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 at redhat.com>
> ---
> clients/net-snk/app/netapps/netboot.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/clients/net-snk/app/netapps/netboot.c b/clients/net-snk/app/netapps/netboot.c
> index 76a4b4f..51189c4 100644
> --- a/clients/net-snk/app/netapps/netboot.c
> +++ b/clients/net-snk/app/netapps/netboot.c
> @@ -366,6 +366,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[])
> {
> @@ -436,6 +448,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)
Reviewed-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
More information about the SLOF
mailing list