Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/net use cprng_fast instead of getmicrouptime to generate...
details: https://anonhg.NetBSD.org/src/rev/4cc1a12c860c
branches: trunk
changeset: 784436:4cc1a12c860c
user: yamt <yamt%NetBSD.org@localhost>
date: Mon Jan 28 15:05:03 2013 +0000
description:
use cprng_fast instead of getmicrouptime to generate "random" mac address
because the latter often produces the same addresses for subsequent tap
instances.
diffstat:
sys/net/if_tap.c | 15 ++++++---------
1 files changed, 6 insertions(+), 9 deletions(-)
diffs (51 lines):
diff -r a81679ebab10 -r 4cc1a12c860c sys/net/if_tap.c
--- a/sys/net/if_tap.c Mon Jan 28 15:01:13 2013 +0000
+++ b/sys/net/if_tap.c Mon Jan 28 15:05:03 2013 +0000
@@ -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 @@
#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 @@
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 @@
/*
* 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));
Home |
Main Index |
Thread Index |
Old Index