Skip to content

Commit

Permalink
libnet/ipams/default: normalize addr pools before calling newAddrSpace
Browse files Browse the repository at this point in the history
This normalization process does two things:

- Unmap IPv4-mapped IPv6 addrs. This ensures such address pools are
part of the IPv4 address space.
- Mask the host ID. This was done by newAddrSpace but `splitByIPFamily`
is already validating / normalizing the address pools.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
  • Loading branch information
akerouanton committed May 11, 2024
1 parent b676a96 commit 89d3950
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
9 changes: 0 additions & 9 deletions libnetwork/ipams/defaultipam/address_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package defaultipam

import (
"context"
"errors"
"net/netip"
"slices"
"sync"
Expand Down Expand Up @@ -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)
})
Expand Down
2 changes: 2 additions & 0 deletions libnetwork/ipams/defaultipam/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 89d3950

Please sign in to comment.