host-local: don't allocate past RangeEnd
When RangeEnd is given, a.end = RangeEnd+1. If when getSearchRange() is called and lastReservedIP equals RangeEnd, a.nextIP() only compares lastReservedIP (which in this example is RangeEnd) against a.end (which in this example is RangeEnd+1) and they clearly don't match, so a.nextIP() returns start=RangeEnd+1 and end=RangeEnd. Get() happily allocates RangeEnd+1 because it only compares 'cur' to the end returned by getSearchRange(), not to a.end, and thus allocates past RangeEnd. Since a.end is inclusive (eg, host-local will allocate a.end) the fix is to simply set a.end equal to RangeEnd.
This commit is contained in:
@@ -25,7 +25,9 @@ import (
|
||||
)
|
||||
|
||||
type IPAllocator struct {
|
||||
// start is inclusive and may be allocated
|
||||
start net.IP
|
||||
// end is inclusive and may be allocated
|
||||
end net.IP
|
||||
conf *IPAMConfig
|
||||
store backend.Store
|
||||
@@ -56,7 +58,7 @@ func NewIPAllocator(conf *IPAMConfig, store backend.Store) (*IPAllocator, error)
|
||||
return nil, err
|
||||
}
|
||||
// RangeEnd is inclusive
|
||||
end = ip.NextIP(conf.RangeEnd)
|
||||
end = conf.RangeEnd
|
||||
}
|
||||
return &IPAllocator{start, end, conf, store}, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user