libnet/i/defaultipam: Unmap IPv4-mapped IPv6 addrs

This ensures such address pools are part of the IPv4 address space.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
This commit is contained in:
Albin Kerouanton
2024-05-07 08:51:20 +02:00
parent 9d288b5b43
commit 0c022307e9
2 changed files with 2 additions and 9 deletions

View File

@@ -2,7 +2,6 @@ package defaultipam
import (
"context"
"errors"
"net/netip"
"slices"
"sync"
@@ -31,14 +30,6 @@ type addrSpace struct {
}
func newAddrSpace(predefined []*ipamutils.NetworkToSplit) (*addrSpace, error) {
for i, p := range predefined {
if !p.Base.IsValid() {
return nil, errors.New("newAddrSpace: prefix zero found")
}
predefined[i].Base = p.Base.Masked()
}
slices.SortFunc(predefined, func(a, b *ipamutils.NetworkToSplit) int {
return netiputil.PrefixCompare(a.Base, b.Base)
})

View File

@@ -96,6 +96,8 @@ func splitByIPFamily(s []*ipamutils.NetworkToSplit) ([]*ipamutils.NetworkToSplit
return []*ipamutils.NetworkToSplit{}, []*ipamutils.NetworkToSplit{}, fmt.Errorf("network at index %d (%v) is not in canonical form", i, n)
}
n.Base, _ = n.Base.Addr().Unmap().Prefix(n.Base.Bits())
if n.Base.Addr().Is4() {
v4 = append(v4, n)
} else {