From 0adfe11dc0738321cdd529f30773899cc8f79855 Mon Sep 17 00:00:00 2001 From: Jeremy Kerr Date: Mon, 21 Jul 2014 15:51:58 +0800 Subject: discover: allow separate lifetimes for network interfaces and discover devices We want the network code's network interfaces to (potentially) persist remove events. For example, discover devices may be removed by a user event (this happens during a udhcpc deconfig). In this case, we want the boot options to be removed, but the struct interface needs to stay present. This change adds network_(un)_register_device functions, to allow the device handler to detach from and attach to interfaces. Signed-off-by: Jeremy Kerr --- discover/network.c | 41 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 40 insertions(+), 1 deletion(-) (limited to 'discover/network.c') 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"; -- cgit v1.1