]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dhcp] Unregister ProxyDHCP and PXEBS settings on a successful DHCPACK
authorMichael Brown <mcb30@ipxe.org>
Wed, 8 Mar 2023 00:43:33 +0000 (00:43 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 14 Mar 2023 11:35:30 +0000 (11:35 +0000)
When a DHCP transaction does not result in the registration of a new
"proxydhcp" or "pxebs" settings block, any existing settings blocks
are currently left unaltered.

This can cause surprising behaviour.  For example: when chainloading
iPXE, the "proxydhcp" and "pxebs" settings blocks may be prepopulated
using cached values from the previous PXE bootloader.  If iPXE
performs a subsequent DHCP request, then the DHCP or ProxyDHCP servers
may choose to respond differently to iPXE.  The response may choose to
omit the ProxyDHCP or PXEBS stages, in which case no new "proxydhcp"
or "pxebs" settings blocks may be registered.  This will result in
iPXE using a combination of both old and new DHCP responses.

Fix by assuming that a successful DHCPACK effectively acquires
ownership of the "proxydhcp" and "pxebs" settings blocks, and that any
existing settings blocks should therefore be unregistered.

Reported-by: Henry Tung <htung@palantir.com>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/udp/dhcp.c

index a1a481e198e7897b53a3337d762ab6fbbc1cf869..bd2c4a197ad342ca5a95bef475bf2a973dc06329 100644 (file)
@@ -601,6 +601,12 @@ static void dhcp_request_rx ( struct dhcp_session *dhcp,
                return;
        }
 
+       /* Unregister any existing ProxyDHCP or PXEBS settings */
+       if ( ( settings = find_settings ( PROXYDHCP_SETTINGS_NAME ) ) != NULL )
+               unregister_settings ( settings );
+       if ( ( settings = find_settings ( PXEBS_SETTINGS_NAME ) ) != NULL )
+               unregister_settings ( settings );
+
        /* Perform ProxyDHCP if applicable */
        if ( dhcp->proxy_offer /* Have ProxyDHCP offer */ &&
             ( ! dhcp->no_pxedhcp ) /* ProxyDHCP not disabled */ ) {