Update pool.go

This commit is contained in:
Jason
2019-08-19 14:42:47 +08:00
parent 9d7433260e
commit 24543d5dcd
+7 -3
View File
@@ -86,11 +86,15 @@ func uintToIP(v uint32) net.IP {
}
// New return Pool instance
func New(ipnet *net.IPNet, size int) (*Pool, error) {
min := ipToUint(ipnet.IP) + 2
func New(ipnet *net.IPNet, offset, size int) (*Pool, error) {
if offset < 2 {
return nil, errors.New("offset must not less than 2")
}
min := ipToUint(ipnet.IP) + uint32(offset)
ones, bits := ipnet.Mask.Size()
total := 1<<uint(bits-ones) - 2
total := 1<<uint(bits-ones) - uint32(offset)
if total <= 0 {
return nil, errors.New("ipnet don't have valid ip")