discover: Record IP address of network interfaces
[petitboot] / discover / user-event.c
index 7ceddb12c7e0b3def7dd4acd9b0795981cc6e43b..fb3fddb5c4bc5f7390f114ec7820f33d7ec45e77 100644 (file)
@@ -37,6 +37,7 @@
 #include "resource.h"
 #include "event.h"
 #include "user-event.h"
+#include "sysinfo.h"
 
 
 #define MAC_ADDR_SIZE  6
@@ -385,7 +386,18 @@ static int user_event_dhcp(struct user_event *uev, struct event *event)
        struct device_handler *handler = uev->handler;
        struct discover_device *dev;
 
-       dev = discover_device_create(handler, event->device);
+       uint8_t hwaddr[MAC_ADDR_SIZE];
+
+       sscanf(event_get_param(event, "mac"),
+              "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX",
+              hwaddr, hwaddr + 1, hwaddr + 2,
+              hwaddr + 3, hwaddr + 4, hwaddr + 5);
+
+       system_info_set_interface_address(sizeof(hwaddr), hwaddr,
+                                         event_get_param(event, "ip"));
+
+       dev = discover_device_create(handler, event_get_param(event, "mac"),
+                                       event->device);
 
        device_handler_dhcp(handler, dev, event);
 
@@ -398,7 +410,10 @@ static int user_event_add(struct user_event *uev, struct event *event)
        struct discover_context *ctx;
        struct discover_device *dev;
 
-       dev = discover_device_create(handler, event->device);
+       /* In case this is a network interface, try to refer to it by UUID */
+       dev = discover_device_create(handler, event_get_param(event, "mac"),
+                                       event->device);
+       dev->device->id = talloc_strdup(dev, event->device);
        ctx = device_handler_discover_context_create(handler, dev);
 
        parse_user_event(ctx, event);
@@ -414,8 +429,13 @@ static int user_event_remove(struct user_event *uev, struct event *event)
 {
        struct device_handler *handler = uev->handler;
        struct discover_device *dev;
+       const char *mac = event_get_param(event, "mac");
+
+       if (mac)
+               dev = device_lookup_by_uuid(handler, event_get_param(event, "mac"));
+       else
+               dev = device_lookup_by_id(handler, event->device);
 
-       dev = device_lookup_by_id(handler, event->device);
        if (!dev)
                return 0;