diff --git a/service/lxd_config.go b/service/lxd_config.go index c2fd91ef2..8e2cd9266 100644 --- a/service/lxd_config.go +++ b/service/lxd_config.go @@ -319,6 +319,9 @@ func (s LXDService) FindInterfaceForSubnet(cidrSubnet string) (*net.Interface, e return nil, fmt.Errorf("Failed to list interfaces: %v", err) } + // TO REMOVE + missedIPs := make([]string, 0) + for _, iface := range interfaces { addrs, err := iface.Addrs() if err != nil { @@ -326,21 +329,19 @@ func (s LXDService) FindInterfaceForSubnet(cidrSubnet string) (*net.Interface, e } for _, addr := range addrs { - ipAddr, ok := addr.(*net.IPNet) - if !ok { - continue - } - - // Skip IPv6 if the subnet is IPv4, and vice versa - if len(targetNet.IP) != len(ipAddr.IP) { - continue + ip, _, err := net.ParseCIDR(addr.String()) + if err != nil { + return nil, fmt.Errorf("Failed to parse IP address %s while finding interface for subnet: %v", addr.String(), err) } - if targetNet.IP.Mask(targetNet.Mask).Equal(ipAddr.IP.Mask(targetNet.Mask)) { + if targetNet.Contains(ip) { return &iface, nil } + + // TO REMOVE + missedIPs = append(missedIPs, ip.String()) } } - return nil, fmt.Errorf("No interface found for CIDR subnet %s", cidrSubnet) + return nil, fmt.Errorf("No interface found for CIDR subnet %s (missedIPs: %v, targetNet: %v)", cidrSubnet, missedIPs, targetNet.IP) }