summaryrefslogtreecommitdiff
path: root/eth-multiplexer/vdev.c
diff options
context:
space:
mode:
authorJustus Winter <justus@gnupg.org>2016-11-05 18:41:13 +0100
committerJustus Winter <justus@gnupg.org>2016-11-05 18:47:09 +0100
commit54c6736341bda9564a028ad3d61d46488e53b8a6 (patch)
tree0e27d98a6ace8074b63a5ab60576c292ffbd529b /eth-multiplexer/vdev.c
parent115695afe34e5253816ff0e828054f8c07e2ddbd (diff)
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.
Diffstat (limited to 'eth-multiplexer/vdev.c')
-rw-r--r--eth-multiplexer/vdev.c9
1 files changed, 8 insertions, 1 deletions
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 <arpa/inet.h>
#include <stdlib.h>
#include <error.h>
+#include <hurd/ihash.h>
#include <pthread.h>
#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);