diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-07-17 09:13:58 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-07-17 11:09:06 +0800 |
commit | 20889c61bc0e6712c1cac5a0a6e9e8e9dff7cf84 (patch) | |
tree | 00f741cf2fa9dc6e2371e2f692da174cebab72ec | |
parent | c1359507c1556ba5f6d2afd0e401abcfe66f02a9 (diff) | |
download | talos-petitboot-20889c61bc0e6712c1cac5a0a6e9e8e9dff7cf84.tar.gz talos-petitboot-20889c61bc0e6712c1cac5a0a6e9e8e9dff7cf84.zip |
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 <jk@ozlabs.org>
-rw-r--r-- | discover/network.c | 21 |
1 files changed, 21 insertions, 0 deletions
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); } |