Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Mougard <[email protected]>
  • Loading branch information
gabrielmougard committed Dec 2, 2024
1 parent f303379 commit 8e01972
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions service/lxd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -319,28 +319,29 @@ 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 {
continue
}

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)
}

0 comments on commit 8e01972

Please sign in to comment.