Skip to content

Commit

Permalink
libnet/ipams/default: improve address pools validation
Browse files Browse the repository at this point in the history
Nothing was validating whether address pools' `base` prefix
were larger than the target subnet `size` they're associated to. As
such invalid address pools would yield no subnet, the error could go
unnoticed.

Signed-off-by: Albin Kerouanton <albinker@gmail.com>
  • Loading branch information
akerouanton committed May 11, 2024
1 parent 89d3950 commit b2fb88d
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions libnetwork/ipams/defaultipam/allocator.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ func splitByIPFamily(s []*ipamutils.NetworkToSplit) ([]*ipamutils.NetworkToSplit
if !n.Base.IsValid() || n.Size == 0 {
return []*ipamutils.NetworkToSplit{}, []*ipamutils.NetworkToSplit{}, fmt.Errorf("network at index %d (%v) is not in canonical form", i, n)
}
if n.Base.Bits() > n.Size {
return []*ipamutils.NetworkToSplit{}, []*ipamutils.NetworkToSplit{}, fmt.Errorf("network at index %d (%v) has a smaller prefix (/%d) than the target size of that pool (/%d)", i, n, n.Base.Bits(), n.Size)
}

n.Base, _ = n.Base.Addr().Unmap().Prefix(n.Base.Bits())

Expand Down

0 comments on commit b2fb88d

Please sign in to comment.