Int64 will cause OutOfRange
arctan90 opened this issue · 0 comments
arctan90 commented
Line 76 in 34d622b
Ipv6 address is 128bits, but 64bits of Int64, considering this circumstances
a := net.ParseIP("2001:db8:acad:3::101")
b := net.ParseIP("2001:db8:acad:3:ffff:ffff:ffff:fffe")
out := Capacity(a, b) // out is -258
then in subnet webhook, validating will pass. An over ranged subnet will be created, and causing OOM when loading IPs of subnet into ipslce by the following code
// /pkg/ipam/types/subnet.go Line 286
// generate valid Available IP Slice
s.AvailableIPs = NewIPSlice()
for i := s.Start; utils.Cmp(i, s.End) <= 0; i = utils.NextIP(i) {
if !s.Contains(i) {
continue
}
// ignore reserved ip
if s.IsReservedIP(i.String()) {
continue
}
s.AvailableIPs.Add(i.String(), i.Equal(s.LastAllocatedIP))
}