From 54c6736341bda9564a028ad3d61d46488e53b8a6 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Sat, 5 Nov 2016 18:41:13 +0100 Subject: eth-multiplexer: Generate stable ethernet addresses. Previously, the ethernet multiplexer generated ethernet addresses for the virtual interfaces using a pseudo-random number generator. This has the downside of generating a new address every time. Generate stable pseudo-random addresses instead. * eth-multiplexer/Makefile (HURDLIBS): Link to libihash. * eth-multiplexer/ethernet.c (ether_address): New variable. (get_ethernet_address): New function. (ethernet_open): Get the ethernet address of the real interface. * eth-multiplexer/ethernet.h (ether_address): New declaration. * eth-multiplexer/vdev.c (add_vdev): Compute the ethernet address by hashing the address of the real interface with the name of the virtual interface. --- eth-multiplexer/vdev.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'eth-multiplexer/vdev.c') diff --git a/eth-multiplexer/vdev.c b/eth-multiplexer/vdev.c index e753b85f..47dc8d2d 100644 --- a/eth-multiplexer/vdev.c +++ b/eth-multiplexer/vdev.c @@ -28,10 +28,12 @@ #include #include #include +#include #include #include "vdev.h" +#include "ethernet.h" #include "queue.h" #include "bpf_impl.h" #include "util.h" @@ -127,6 +129,7 @@ add_vdev (char *name, int size, struct port_class *class, struct port_bucket *bucket) { error_t err; + uint32_t hash; struct vether_device *vdev; if (size < sizeof (*vdev)) @@ -143,9 +146,13 @@ add_vdev (char *name, int size, vdev->if_header_format = HDR_ETHERNET; vdev->if_address_size = ETH_ALEN; vdev->if_flags = 0; + + /* Compute a pseudo-random but stable ethernet address. */ vdev->if_address[0] = 0x52; vdev->if_address[1] = 0x54; - *(int *)(vdev->if_address + 2) = random (); + hash = hurd_ihash_hash32 (ether_address, ETH_ALEN, 0); + hash = hurd_ihash_hash32 (name, strlen (name), hash); + memcpy (&vdev->if_address[2], &hash, 4); queue_init (&vdev->port_list.if_rcv_port_list); queue_init (&vdev->port_list.if_snd_port_list); -- cgit v1.2.3