From 3dc2ceffae70eee992ce2aba0251dfd9130008c4 Mon Sep 17 00:00:00 2001 From: Max Makarov Date: Tue, 31 Mar 2026 16:00:42 +0300 Subject: [PATCH] Fix UnboundLocalError for dhcp_addr in get_adapter_addresses When a network adapter has DHCP_ENABLED and IPV6_ENABLED flags set but not IPV4_ENABLED, the dhcp_addr variable is never assigned before being referenced in the IPv6 check condition, causing: UnboundLocalError: cannot access local variable 'dhcp_addr' This occurs on cloud VMs with vDPA/SR-IOV networking where the adapter may have IPv6 link-local addressing (DHCP enabled) but static IPv4 configuration (no IPV4_ENABLED flag). Fix by initializing dhcp_addr to None before the conditional assignments. Signed-off-by: Max Makarov --- cloudbaseinit/utils/windows/network.py | 1 + 1 file changed, 1 insertion(+) diff --git a/cloudbaseinit/utils/windows/network.py b/cloudbaseinit/utils/windows/network.py index 0ce2c72e..ba465815 100644 --- a/cloudbaseinit/utils/windows/network.py +++ b/cloudbaseinit/utils/windows/network.py @@ -120,6 +120,7 @@ def get_adapter_addresses(): if dhcp_enabled: if not xp_data_only: + dhcp_addr = None if curr_addr.Flags & iphlpapi.IP_ADAPTER_IPV4_ENABLED: dhcp_addr = curr_addr.Dhcpv4Server