summaryrefslogtreecommitdiffstats
path: root/sys/net/if_ethersubr.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2010-01-12 03:41:29 +0000
committerderaadt <deraadt@openbsd.org>2010-01-12 03:41:29 +0000
commita7ae98197d00f324de2d3d7b310d471791b0cc1b (patch)
tree1c6c1db92afa7366570bfc4eee72efdd1189ed94 /sys/net/if_ethersubr.c
parentDon't leak @if0 format routing host names, pointed out by claudio. (diff)
downloadwireguard-openbsd-a7ae98197d00f324de2d3d7b310d471791b0cc1b.tar.xz
wireguard-openbsd-a7ae98197d00f324de2d3d7b310d471791b0cc1b.zip
Unify the various fake ethernet generators as ether_fakeaddr() which
is safe for both hardware devices and virtual devices ok mpf, kettenis, moaning and groaning and slow acceptance from mcbride XXX should loop checking for uniqueness after new henning diff goes in
Diffstat (limited to 'sys/net/if_ethersubr.c')
-rw-r--r--sys/net/if_ethersubr.c36
1 files changed, 21 insertions, 15 deletions
diff --git a/sys/net/if_ethersubr.c b/sys/net/if_ethersubr.c
index 595355fba0d..39309e025a8 100644
--- a/sys/net/if_ethersubr.c
+++ b/sys/net/if_ethersubr.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_ethersubr.c,v 1.137 2010/01/11 03:50:56 yasuoka Exp $ */
+/* $OpenBSD: if_ethersubr.c,v 1.138 2010/01/12 03:41:29 deraadt Exp $ */
/* $NetBSD: if_ethersubr.c,v 1.19 1996/05/07 02:40:30 thorpej Exp $ */
/*
@@ -879,30 +879,36 @@ ether_sprintf(ap)
}
/*
+ * Generate a (hopefully) acceptable MAC address, if asked.
+ */
+void
+ether_fakeaddr(struct ifnet *ifp)
+{
+ static int unit;
+ int rng;
+
+ ((struct arpcom *)ifp)->ac_enaddr[0] = 0xfe;
+ ((struct arpcom *)ifp)->ac_enaddr[1] = 0xe1;
+ ((struct arpcom *)ifp)->ac_enaddr[2] = 0xba;
+ ((struct arpcom *)ifp)->ac_enaddr[3] = 0xd0 | (unit++ & 0xf);
+ rng = cold ? random() ^ (long)ifp : arc4random();
+ ((struct arpcom *)ifp)->ac_enaddr[4] = rng;
+ ((struct arpcom *)ifp)->ac_enaddr[5] = rng >> 8;
+}
+
+/*
* Perform common duties while attaching to interface list
*/
void
ether_ifattach(ifp)
struct ifnet *ifp;
{
-
/*
* Any interface which provides a MAC address which is obviously
* invalid gets whacked, so that users will notice.
*/
- if (ETHER_IS_MULTICAST(((struct arpcom *)ifp)->ac_enaddr)) {
- ((struct arpcom *)ifp)->ac_enaddr[0] = 0x00;
- ((struct arpcom *)ifp)->ac_enaddr[1] = 0xfe;
- ((struct arpcom *)ifp)->ac_enaddr[2] = 0xe1;
- ((struct arpcom *)ifp)->ac_enaddr[3] = 0xba;
- ((struct arpcom *)ifp)->ac_enaddr[4] = 0xd0;
- /*
- * XXX use of random() by anything except the scheduler is
- * normally invalid, but this is boot time, so pre-scheduler,
- * and the random subsystem is not alive yet
- */
- ((struct arpcom *)ifp)->ac_enaddr[5] = (u_char)random() & 0xff;
- }
+ if (ETHER_IS_MULTICAST(((struct arpcom *)ifp)->ac_enaddr))
+ ether_fakeaddr(ifp);
ifp->if_type = IFT_ETHER;
ifp->if_addrlen = ETHER_ADDR_LEN;