[Libvirt-cim] [PATCH] Improve random MAC generator
Richard Maciel
rmaciel at linux.vnet.ibm.com
Mon Mar 23 16:07:45 UTC 2009
+1
Kaitlin Rupert wrote:
> # HG changeset patch
> # User Kaitlin Rupert <karupert at us.ibm.com>
> # Date 1237266354 25200
> # Node ID 69b7af00d9da92ce169d915bb6b17c493fe0b021
> # Parent 160e1a86d82e8ed930e3006098f2af8b230c9834
> Improve random MAC generator
>
> Use microseconds since the epoch instead of seconds. When defining a guest
> with multiple net devices specified (in which none of them have a MAC supplied),
> it's possible for _net_rand_mac() to be called in rapid succession.
>
> Also, initialize s - the seed value passed to rand_r().
>
> Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>
>
> diff -r 160e1a86d82e -r 69b7af00d9da src/Virt_VirtualSystemManagementService.c
> --- a/src/Virt_VirtualSystemManagementService.c Mon Mar 16 13:55:02 2009 -0700
> +++ b/src/Virt_VirtualSystemManagementService.c Mon Mar 16 22:05:54 2009 -0700
> @@ -25,6 +25,7 @@
> #include <stdbool.h>
> #include <inttypes.h>
> #include <time.h>
> +#include <sys/time.h>
> #include <libvirt/libvirt.h>
>
> #include "cmpidt.h"
> @@ -383,8 +384,14 @@
> const char *_mac = NULL;
> CMPIString *str = NULL;
> CMPIStatus status;
> + struct timeval curr_time;
>
> - srand(time(NULL));
> + ret = gettimeofday(&curr_time, NULL);
> + if (ret != 0)
> + goto out;
> +
> + srand(curr_time.tv_usec);
> + s = curr_time.tv_usec;
> r = rand_r(&s);
>
> ret = asprintf(&mac,
>
> _______________________________________________
> Libvirt-cim mailing list
> Libvirt-cim at redhat.com
> https://www.redhat.com/mailman/listinfo/libvirt-cim
--
Richard Maciel, MSc
IBM Linux Technology Center
rmaciel at linux.vnet.ibm.com
More information about the Libvirt-cim
mailing list