From c3d1e7869731c8cccb041ce05ee0ebbb3dc375d5 Mon Sep 17 00:00:00 2001 From: Michael Brown Date: Fri, 8 Nov 2013 12:45:22 +0000 Subject: [PATCH] [pxe] Ensure cached DHCPACK is retrieved prior to network device creation The retrieval of the cached DHCPACK and the creation of network devices are both currently scheduled as STARTUP_NORMAL. It is therefore possible that the cached DHCPACK will not be retrieved in time for cachedhcp_probe() to apply it to the relevant network device. Fix by retrieving the cached DHCPACK at initialisation time rather than at startup time. As an optimisation, an unclaimed cached DHCPACK can be freed immediately after the last network device has been created, rather than waiting until shutdown. Reported-by: Espen Braastad Signed-off-by: Michael Brown --- src/arch/i386/core/cachedhcp.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/arch/i386/core/cachedhcp.c b/src/arch/i386/core/cachedhcp.c index b967e9b9..3cac28e7 100644 --- a/src/arch/i386/core/cachedhcp.c +++ b/src/arch/i386/core/cachedhcp.c @@ -50,7 +50,7 @@ static struct dhcp_packet *cached_dhcpack; * Cached DHCPACK startup function * */ -static void cachedhcp_startup ( void ) { +static void cachedhcp_init ( void ) { struct dhcp_packet *dhcppkt; struct dhcp_packet *tmp; struct dhcphdr *dhcphdr; @@ -98,13 +98,14 @@ static void cachedhcp_startup ( void ) { } /** - * Cached DHCPACK shutdown function + * Cached DHCPACK startup function * - * @v booting Shutting down in order to boot */ -static void cachedhcp_shutdown ( int booting __unused ) { +static void cachedhcp_startup ( void ) { - /* If cached DHCP packet has not yet been claimed, free it */ + /* If cached DHCP packet was not claimed by any network device + * during startup, then free it. + */ if ( cached_dhcpack ) { DBGC ( colour, "CACHEDHCP freeing unclaimed cached DHCPACK\n" ); dhcppkt_put ( cached_dhcpack ); @@ -113,9 +114,13 @@ static void cachedhcp_shutdown ( int booting __unused ) { } /** Cached DHCPACK initialisation function */ -struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_NORMAL ) = { +struct init_fn cachedhcp_init_fn __init_fn ( INIT_NORMAL ) = { + .initialise = cachedhcp_init, +}; + +/** Cached DHCPACK startup function */ +struct startup_fn cachedhcp_startup_fn __startup_fn ( STARTUP_LATE ) = { .startup = cachedhcp_startup, - .shutdown = cachedhcp_shutdown, }; /**