summaryrefslogtreecommitdiff
path: root/eth-multiplexer/ethernet.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/ethernet.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/ethernet.c')
-rw-r--r--eth-multiplexer/ethernet.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/eth-multiplexer/ethernet.c b/eth-multiplexer/ethernet.c
index 002f30c2..1f3a57c4 100644
--- a/eth-multiplexer/ethernet.c
+++ b/eth-multiplexer/ethernet.c
@@ -42,6 +42,10 @@ static struct port_info *readpt;
/* Port for writing message to the real network interface. */
mach_port_t ether_port;
+
+/* The ethernet address of the real network interface. */
+char ether_address[ETH_ALEN];
+
/* Port for receiving messages from the interface. */
static mach_port_t readptname;
@@ -102,6 +106,24 @@ int set_promisc (char *dev_name, mach_port_t ether_port, int is_promisc)
return 0;
}
+static error_t
+get_ethernet_address (mach_port_t port, char *address)
+{
+ error_t err;
+ int net_address[2];
+ size_t count = 2;
+ assert (count * sizeof (int) >= ETH_ALEN);
+
+ err = device_get_status (port, NET_ADDRESS, net_address, &count);
+ if (err)
+ return err;
+
+ net_address[0] = ntohl (net_address[0]);
+ net_address[1] = ntohl (net_address[1]);
+ memcpy (address, net_address, ETH_ALEN);
+ return 0;
+}
+
int ethernet_open (char *dev_name, device_t master_device,
struct port_bucket *etherport_bucket,
struct port_class *etherreadclass)
@@ -132,6 +154,11 @@ int ethernet_open (char *dev_name, device_t master_device,
error (2, err, "device_set_filter: %s", dev_name);
set_promisc (dev_name, ether_port, 1);
+
+ err = get_ethernet_address (ether_port, ether_address);
+ if (err)
+ error (2, err, "%s: Cannot get hardware Ethernet address", dev_name);
+
return 0;
}