Module Name: src Committed By: yamt Date: Mon Jan 28 15:05:03 UTC 2013
Modified Files: src/sys/net: if_tap.c Log Message: use cprng_fast instead of getmicrouptime to generate "random" mac address because the latter often produces the same addresses for subsequent tap instances. To generate a diff of this commit: cvs rdiff -u -r1.69 -r1.70 src/sys/net/if_tap.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/if_tap.c diff -u src/sys/net/if_tap.c:1.69 src/sys/net/if_tap.c:1.70 --- src/sys/net/if_tap.c:1.69 Mon Jan 28 15:01:13 2013 +++ src/sys/net/if_tap.c Mon Jan 28 15:05:03 2013 @@ -1,4 +1,4 @@ -/* $NetBSD: if_tap.c,v 1.69 2013/01/28 15:01:13 yamt Exp $ */ +/* $NetBSD: if_tap.c,v 1.70 2013/01/28 15:05:03 yamt Exp $ */ /* * Copyright (c) 2003, 2004, 2008, 2009 The NetBSD Foundation. @@ -33,7 +33,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.69 2013/01/28 15:01:13 yamt Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1.70 2013/01/28 15:05:03 yamt Exp $"); #if defined(_KERNEL_OPT) @@ -46,6 +46,7 @@ __KERNEL_RCSID(0, "$NetBSD: if_tap.c,v 1 #include <sys/kernel.h> #include <sys/malloc.h> #include <sys/conf.h> +#include <sys/cprng.h> #include <sys/device.h> #include <sys/file.h> #include <sys/filedesc.h> @@ -265,8 +266,6 @@ tap_attach(device_t parent, device_t sel uint8_t enaddr[ETHER_ADDR_LEN] = { 0xf2, 0x0b, 0xa4, 0xff, 0xff, 0xff }; char enaddrstr[3 * ETHER_ADDR_LEN]; - struct timeval tv; - uint32_t ui; sc->sc_dev = self; sc->sc_sih = softint_establish(SOFTINT_CLOCK, tap_softintr, sc); @@ -278,12 +277,10 @@ tap_attach(device_t parent, device_t sel /* * In order to obtain unique initial Ethernet address on a host, - * do some randomisation using the current uptime. It's not meant - * for anything but avoiding hard-coding an address. + * do some randomisation. It's not meant for anything but avoiding + * hard-coding an address. */ - getmicrouptime(&tv); - ui = (tv.tv_sec ^ tv.tv_usec) & 0xffffff; - memcpy(enaddr+3, (uint8_t *)&ui, 3); + cprng_fast(&enaddr[3], 3); aprint_verbose_dev(self, "Ethernet address %s\n", ether_snprintf(enaddrstr, sizeof(enaddrstr), enaddr));