@@ -27,6 +27,7 @@
#include <netdb.h>
#include <arpa/inet.h>
+#include <util/util.h>
#include "device-handler.h"
#include "discover-server.h"
#include "devmapper.h"
@@ -1491,6 +1492,7 @@ static void process_url_cb(struct load_url_result *result, void *data)
}
mac = event_get_param(event, "mac");
+ mac = hwaddr_preprocess(mac, NULL);
char *url = talloc_asprintf(event, "file://%s", result->local);
event_set_param(event, "pxeconffile-local", url);
@@ -396,18 +396,20 @@ static int user_event_dhcp(struct user_event *uev, struct event *event)
{
struct device_handler *handler = uev->handler;
struct discover_device *dev;
+ const char *mac;
- uint8_t hwaddr[MAC_ADDR_SIZE];
+ uint8_t hwaddr[MAX_ADDR_SIZE];
+ size_t hwaddr_len;
- sscanf(event_get_param(event, "mac"),
- "%hhX:%hhX:%hhX:%hhX:%hhX:%hhX",
- hwaddr, hwaddr + 1, hwaddr + 2,
- hwaddr + 3, hwaddr + 4, hwaddr + 5);
+ mac = event_get_param(event, "mac");
+ mac = hwaddr_preprocess(mac, &hwaddr_len);
+ if (hwaddr_from_pretty_str(mac, hwaddr_len, hwaddr, MAX_ADDR_SIZE) < 0)
+ return -1;
- system_info_set_interface_address(sizeof(hwaddr), hwaddr,
+ system_info_set_interface_address(hwaddr_len, hwaddr,
event_get_param(event, "ip"));
- dev = discover_device_create(handler, event_get_param(event, "mac"),
+ dev = discover_device_create(handler, mac,
event->device);
device_handler_dhcp(handler, dev, event);
@@ -420,10 +422,12 @@ static int user_event_add(struct user_event *uev, struct event *event)
struct device_handler *handler = uev->handler;
struct discover_context *ctx;
struct discover_device *dev;
+ const char *mac;
/* 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);
+ mac = event_get_param(event, "mac");
+ mac = hwaddr_preprocess(mac, NULL);
+ dev = discover_device_create(handler, mac, event->device);
dev->device->id = talloc_strdup(dev, event->device);
ctx = device_handler_discover_context_create(handler, dev);
@@ -441,9 +445,10 @@ 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");
+ mac = hwaddr_preprocess(mac, NULL);
if (mac)
- dev = device_lookup_by_uuid(handler, event_get_param(event, "mac"));
+ dev = device_lookup_by_uuid(handler, mac);
else
dev = device_lookup_by_id(handler, event->device);
Use new, common functions to preprocess and transform hardware addresses to strip any non-local address information. Signed-off-by: Daniel M. Weeks <weeksd2@rpi.edu> --- discover/device-handler.c | 2 ++ discover/user-event.c | 25 +++++++++++++++---------- 2 files changed, 17 insertions(+), 10 deletions(-)