From 20889c61bc0e6712c1cac5a0a6e9e8e9dff7cf84 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Thu, 17 Jul 2014 09:13:58 +0800 Subject: discover: Set UUID for network interface devices We want to lookup network (as well as block) devices by UUID, so set one based on the MAC address. Signed-off-by: Jeremy Kerr --- discover/network.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'discover/network.c') diff --git a/discover/network.c b/discover/network.c index 1801710..ad17a41 100644 --- a/discover/network.c +++ b/discover/network.c @@ -150,6 +150,25 @@ static int network_send_link_query(struct network *network) return 0; } +static char *mac_bytes_to_string(void *ctx, uint8_t *addr, int len) +{ + const int l = strlen("xx:"); + char *buf; + int i; + + if (len <= 0) + return talloc_strdup(ctx, ""); + + buf = talloc_array(ctx, char, (len * l) + 1); + + for (i = 0; i < len; i++) + sprintf(buf + (l * i), "%02x:", addr[i]); + + *(buf + (l * len) - 1) = '\0'; + + return buf; +} + static void add_interface(struct network *network, struct interface *interface) { @@ -157,6 +176,8 @@ static void add_interface(struct network *network, interface->dev = discover_device_create(network->handler, interface->name); interface->dev->device->type = DEVICE_TYPE_NETWORK; + interface->dev->uuid = mac_bytes_to_string(interface->dev, + interface->hwaddr, sizeof(interface->hwaddr)); device_handler_add_device(network->handler, interface->dev); } -- cgit v1.1