diff options
author | Jeremy Kerr <jk@ozlabs.org> | 2014-07-21 15:51:58 +0800 |
---|---|---|
committer | Jeremy Kerr <jk@ozlabs.org> | 2014-07-21 17:20:08 +0800 |
commit | 0adfe11dc0738321cdd529f30773899cc8f79855 (patch) | |
tree | f456887c66a18679f27940d34082bde40e9c3857 /discover/network.c | |
parent | 20889c61bc0e6712c1cac5a0a6e9e8e9dff7cf84 (diff) | |
download | talos-petitboot-0adfe11dc0738321cdd529f30773899cc8f79855.tar.gz talos-petitboot-0adfe11dc0738321cdd529f30773899cc8f79855.zip |
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 <jk@ozlabs.org>
Diffstat (limited to 'discover/network.c')
-rw-r--r-- | discover/network.c | 41 |
1 files changed, 40 insertions, 1 deletions
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"; |