david/ipxe
Archived
1
0

[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 <espen.braastad@redpill-linpro.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown 2013-11-08 12:45:22 +00:00
parent 43eba2f555
commit c3d1e78697

View File

@ -50,7 +50,7 @@ static struct dhcp_packet *cached_dhcpack;
* Cached DHCPACK startup function * Cached DHCPACK startup function
* *
*/ */
static void cachedhcp_startup ( void ) { static void cachedhcp_init ( void ) {
struct dhcp_packet *dhcppkt; struct dhcp_packet *dhcppkt;
struct dhcp_packet *tmp; struct dhcp_packet *tmp;
struct dhcphdr *dhcphdr; 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 ) { if ( cached_dhcpack ) {
DBGC ( colour, "CACHEDHCP freeing unclaimed cached DHCPACK\n" ); DBGC ( colour, "CACHEDHCP freeing unclaimed cached DHCPACK\n" );
dhcppkt_put ( cached_dhcpack ); dhcppkt_put ( cached_dhcpack );
@ -113,9 +114,13 @@ static void cachedhcp_shutdown ( int booting __unused ) {
} }
/** Cached DHCPACK initialisation function */ /** 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, .startup = cachedhcp_startup,
.shutdown = cachedhcp_shutdown,
}; };
/** /**