diff options
Diffstat (limited to 'discover')
-rw-r--r-- | discover/network.c | 4 | ||||
-rw-r--r-- | discover/sysinfo.c | 30 | ||||
-rw-r--r-- | discover/sysinfo.h | 2 | ||||
-rw-r--r-- | discover/user-event.c | 11 |
4 files changed, 47 insertions, 0 deletions
diff --git a/discover/network.c b/discover/network.c index 51a846a..69223b1 100644 --- a/discover/network.c +++ b/discover/network.c @@ -384,6 +384,10 @@ static void configure_interface_static(struct network *network, return; } + system_info_set_interface_address(sizeof(interface->hwaddr), + interface->hwaddr, + config->static_config.address); + /* we need the interface up before we can route through it */ rc = interface_up(interface); if (rc) diff --git a/discover/sysinfo.c b/discover/sysinfo.c index 219369a..619c0c5 100644 --- a/discover/sysinfo.c +++ b/discover/sysinfo.c @@ -3,6 +3,7 @@ #include <talloc/talloc.h> #include <process/process.h> +#include <log/log.h> #include "discover-server.h" #include "platform.h" @@ -16,6 +17,35 @@ const struct system_info *system_info_get(void) return sysinfo; } + +void system_info_set_interface_address(unsigned int hwaddr_size, + uint8_t *hwaddr, const char *address) +{ + struct interface_info *if_info; + unsigned int i; + + for (i = 0; i < sysinfo->n_interfaces; i++) { + if_info = sysinfo->interfaces[i]; + + if (if_info->hwaddr_size != hwaddr_size) + continue; + + if (memcmp(if_info->hwaddr, hwaddr, hwaddr_size)) + continue; + + /* Found an existing interface. Notify clients if a new address + * is set */ + if (!if_info->address || strcmp(if_info->address, address)) { + talloc_free(if_info->address); + if_info->address = talloc_strdup(if_info, address); + discover_server_notify_system_info(server, sysinfo); + return; + } + } + + pb_log("Couldn't find interface matching %s\n", "foo"); +} + void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr, const char *name, bool link) { diff --git a/discover/sysinfo.h b/discover/sysinfo.h index 7181c99..19ed950 100644 --- a/discover/sysinfo.h +++ b/discover/sysinfo.h @@ -7,6 +7,8 @@ struct discover_server; const struct system_info *system_info_get(void); +void system_info_set_interface_address(unsigned int hwaddr_size, + uint8_t *hwaddr, const char *address); void system_info_register_interface(unsigned int hwaddr_size, uint8_t *hwaddr, const char *name, bool link); void system_info_register_blockdev(const char *name, const char *uuid, diff --git a/discover/user-event.c b/discover/user-event.c index 20b2bea..fb3fddb 100644 --- a/discover/user-event.c +++ b/discover/user-event.c @@ -37,6 +37,7 @@ #include "resource.h" #include "event.h" #include "user-event.h" +#include "sysinfo.h" #define MAC_ADDR_SIZE 6 @@ -385,6 +386,16 @@ static int user_event_dhcp(struct user_event *uev, struct event *event) struct device_handler *handler = uev->handler; struct discover_device *dev; + 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); |