From 3617e03f7e18cd3862c40749c116158c65bd01e9 Mon Sep 17 00:00:00 2001 From: oromenahar Date: Fri, 18 Apr 2025 15:25:38 +0200 Subject: [PATCH] search for a valid ip, including IPv6 addresses. It first checks for a valid IPv6 or IPv4 and continues if it's not valid. After that it continues if the ip is part of linkLocalUnicat, Multicast or loopback. The first ip which doesn't match one of the following types will be returned as valid. no IPv4 or IPv6 at all SiteLocalUnicast: fec0::/10 multicast: ff00::/8 global Unicast ::/96 LinkLocalUnicat: fe80::/64 If the proxmox interface supports IPv4 and IPv6 the selected ip depends on the proxmox list sorting of the returned addresses. The first valid ip will be used which can change depending on the proxmox api. related to #233 related to #10227 related to #10858 Signed-off-by: oromenahar --- builder/proxmox/common/builder.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/builder/proxmox/common/builder.go b/builder/proxmox/common/builder.go index a10fd691..786e6bb5 100644 --- a/builder/proxmox/common/builder.go +++ b/builder/proxmox/common/builder.go @@ -176,10 +176,15 @@ func getVMIP(state multistep.StateBag) (string, error) { for _, iface := range ifs { for _, addr := range iface.IpAddresses { - if addr.IsLoopback() { + if addr.To4() == nil && addr.To16() == nil { + // no IPv4 or IPv6 at all continue - } - if addr.To4() == nil { + } else if addr.IsLinkLocalUnicast() || addr.IsMulticast() || addr.IsLoopback() || addr.IsUnspecified() { + // can not be replaced by !addr.IsGlobalUnicast() because it just returns ips wich are globally routable, + // but Unique Local Addresses: fc00::/7 can be used as well for IPv6 setups. + // SiteLocalUnicast: fec0::/10 + // multicast: ff00::/8 + // LinkLocalUnicat: fe80::/64 continue } return addr.String(), nil