Skip to content

Commit

Permalink
fix: iface panic
Browse files Browse the repository at this point in the history
  • Loading branch information
wwqgtxx committed Mar 24, 2024
1 parent d56a439 commit d2ae94f
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions component/iface/iface.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,25 @@ func ResolveInterface(name string) (*Interface, error) {

ipNets := make([]netip.Prefix, 0, len(addrs))
for _, addr := range addrs {
ipNet := addr.(*net.IPNet)
ip, _ := netip.AddrFromSlice(ipNet.IP)

ones, bits := ipNet.Mask.Size()
if bits == 32 {
var pf netip.Prefix
switch addr.(type) {
case *net.IPNet:
ipNet := addr.(*net.IPNet)
ip, _ := netip.AddrFromSlice(ipNet.IP)
ones, bits := ipNet.Mask.Size()
if bits == 32 {
ip = ip.Unmap()
}
pf = netip.PrefixFrom(ip, ones)
case *net.IPAddr:
ipNet := addr.(*net.IPAddr)
ip, _ := netip.AddrFromSlice(ipNet.IP)
ip = ip.Unmap()
pf = netip.PrefixFrom(ip, ip.BitLen())
}
if pf.IsValid() {
ipNets = append(ipNets, pf)
}

pf := netip.PrefixFrom(ip, ones)
ipNets = append(ipNets, pf)
}

r[iface.Name] = &Interface{
Expand Down

0 comments on commit d2ae94f

Please sign in to comment.