summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--discover/device-handler.c7
-rw-r--r--discover/network.c41
-rw-r--r--discover/network.h6
3 files changed, 53 insertions, 1 deletions
diff --git a/discover/device-handler.c b/discover/device-handler.c
index c21eb28..7f7081d 100644
--- a/discover/device-handler.c
+++ b/discover/device-handler.c
@@ -344,6 +344,11 @@ void device_handler_remove(struct device_handler *handler,
talloc_free(opt);
}
+ /* if this is a network device, we have to unregister it from the
+ * network code */
+ if (device->device->type == DEVICE_TYPE_NETWORK)
+ network_unregister_device(handler->network, device);
+
handler->n_devices--;
memmove(&handler->devices[i], &handler->devices[i + 1],
(handler->n_devices - i) * sizeof(handler->devices[0]));
@@ -646,6 +651,8 @@ void device_handler_add_device(struct device_handler *handler,
struct discover_device *, handler->n_devices);
handler->devices[handler->n_devices - 1] = device;
+ if (device->device->type == DEVICE_TYPE_NETWORK)
+ network_register_device(handler->network, device);
}
/* Start discovery on a hotplugged device. The device will be in our devices
diff --git a/discover/network.c b/discover/network.c
index ad17a41..c0bd2af 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -97,6 +97,18 @@ static struct interface *find_interface_by_ifindex(struct network *network,
return NULL;
}
+static struct interface *find_interface_by_name(struct network *network,
+ const char *name)
+{
+ struct interface *interface;
+
+ list_for_each_entry(&network->interfaces, interface, list)
+ if (!strcmp(interface->name, name))
+ return interface;
+
+ return NULL;
+}
+
static int network_init_netlink(struct network *network)
{
struct sockaddr_nl addr;
@@ -184,11 +196,38 @@ static void add_interface(struct network *network,
static void remove_interface(struct network *network,
struct interface *interface)
{
- device_handler_remove(network->handler, interface->dev);
+ if (interface->dev)
+ device_handler_remove(network->handler, interface->dev);
list_remove(&interface->list);
talloc_free(interface);
}
+void network_register_device(struct network *network,
+ struct discover_device *dev)
+{
+ struct interface *iface;
+
+ iface = find_interface_by_name(network, dev->device->id);
+ if (!iface)
+ return;
+
+ iface->dev = dev;
+ dev->uuid = mac_bytes_to_string(iface->dev, iface->hwaddr,
+ sizeof(iface->hwaddr));
+}
+
+void network_unregister_device(struct network *network,
+ struct discover_device *dev)
+{
+ struct interface *iface;
+
+ iface = find_interface_by_name(network, dev->device->id);
+ if (!iface)
+ return;
+
+ iface->dev = NULL;
+}
+
static int interface_change(struct interface *interface, bool up)
{
const char *statestr = up ? "up" : "down";
diff --git a/discover/network.h b/discover/network.h
index 912174f..bfd1ab1 100644
--- a/discover/network.h
+++ b/discover/network.h
@@ -3,11 +3,17 @@
struct network;
struct device_handler;
+struct discover_device;
struct waitset;
struct network *network_init(struct device_handler *handler,
struct waitset *waitset, bool dry_run);
int network_shutdown(struct network *network);
+void network_register_device(struct network *network,
+ struct discover_device *dev);
+void network_unregister_device(struct network *network,
+ struct discover_device *dev);
+
#endif /* NETWORK_H */
OpenPOWER on IntegriCloud