Skip to content

Commit 3dc2cef

Browse files
committed
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 <maxpain@linux.com>
1 parent d63509f commit 3dc2cef

1 file changed

Lines changed: 1 addition & 0 deletions

File tree

cloudbaseinit/utils/windows/network.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ def get_adapter_addresses():
120120

121121
if dhcp_enabled:
122122
if not xp_data_only:
123+
dhcp_addr = None
123124
if curr_addr.Flags & iphlpapi.IP_ADAPTER_IPV4_ENABLED:
124125
dhcp_addr = curr_addr.Dhcpv4Server
125126

0 commit comments

Comments
 (0)