summaryrefslogtreecommitdiffstats
path: root/discover/network.c
diff options
context:
space:
mode:
authorJeremy Kerr <jk@ozlabs.org>2018-07-03 16:24:58 +1000
committerSamuel Mendoza-Jonas <sam@mendozajonas.com>2018-07-09 15:13:07 +1000
commit6fa0edfb029726968cbacad9d4e193a345956ff3 (patch)
treef406c1621bb407b9affe4af522dbc6ec0e626524 /discover/network.c
parent13cc5c5d57318a6c2043168277862b3704a7d3d9 (diff)
downloadtalos-petitboot-6fa0edfb029726968cbacad9d4e193a345956ff3.tar.gz
talos-petitboot-6fa0edfb029726968cbacad9d4e193a345956ff3.zip
discover: implement a periodic requery for network devices
If we boot a machine before external (network) dependencies are properly configured, it will have tried once to download configuration, and possibly failed due to that configuration not being present. This change introduces a periodic requery of network resources. After a timeout, petitboot will either re-acquire its DHCP lease (causing any downloads to be re-processed, possibly with different parameters from the new lease), or re-download a statically defined URL. This timeout defaults to five minutes (similar to pxelinux), and is configurable by DHCP option 211, "reboot time". Signed-off-by: Jeremy Kerr <jk@ozlabs.org> [added test stub] Signed-off-by: Samuel Mendoza-Jonas <sam@mendozajonas.com>
Diffstat (limited to 'discover/network.c')
-rw-r--r--discover/network.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/discover/network.c b/discover/network.c
index 9594b2e..5a3b0b4 100644
--- a/discover/network.c
+++ b/discover/network.c
@@ -331,6 +331,7 @@ static void configure_interface_dhcp(struct network *network,
"-f",
"-O", "pxeconffile",
"-O", "pxepathprefix",
+ "-O", "reboottime",
"-p", pidfile,
"-i", interface->name,
"-x", id, /* [11,12] - dhcp client identifier */
@@ -417,6 +418,8 @@ static void configure_interface_static(struct network *network,
interface->hwaddr,
sizeof(interface->hwaddr)),
config->static_config.address);
+ device_handler_start_requery_timeout(network->handler,
+ interface->dev, -1);
}
return;
@@ -498,6 +501,49 @@ static void configure_interface(struct network *network,
interface->state = IFSTATE_CONFIGURED;
}
+void network_requery_device(struct network *network,
+ struct discover_device *dev)
+{
+ const struct interface_config *config;
+ struct interface *interface;
+
+ interface = find_interface_by_uuid(network, dev->uuid);
+ if (!interface)
+ return;
+
+ if (interface->udhcpc_process) {
+ interface->udhcpc_process->exit_cb = NULL;
+ interface->udhcpc_process->data = NULL;
+ process_stop_async(interface->udhcpc_process);
+ process_release(interface->udhcpc_process);
+ }
+
+ config = find_config_by_hwaddr(interface->hwaddr);
+
+ if (config && config->ignore)
+ return;
+
+ if (!config || config->method == CONFIG_METHOD_DHCP) {
+ /* Restart DHCP. Once we acquire a lease, we'll re-start
+ * the requery timeout (based on any reboottime DHCP option)
+ */
+ configure_interface_dhcp(network, interface);
+
+ } else if (config->method == CONFIG_METHOD_STATIC &&
+ config->static_config.url) {
+ /* Redownload statically-provided URL, and manually restart
+ * requery timeout */
+ device_handler_process_url(network->handler,
+ config->static_config.url,
+ mac_bytes_to_string(interface->dev,
+ interface->hwaddr,
+ sizeof(interface->hwaddr)),
+ config->static_config.address);
+ device_handler_start_requery_timeout(network->handler,
+ dev, -1);
+ }
+}
+
static int network_handle_nlmsg(struct network *network, struct nlmsghdr *nlmsg)
{
bool have_ifaddr, have_ifname;
OpenPOWER on IntegriCloud