Check validity of IP subnets

Be more consistent about this - check in the same way whether at startup
or during allocation.
This commit is contained in:
Bryan Boreham committed 2016-05-26 14:31:17 +00:00
1 parent d9d1956e0c
commit cda1084777
4 files changed
+29 -20

No files matched your search

+14
View File
@@ -111,6 +111,20 @@ func NewAllocator(config Config) *Allocator {
}
}
func ParseCIDRSubnet(cidrStr string) (cidr address.CIDR, err error) {
cidr, err = address.ParseCIDR(cidrStr)
if err != nil {
return
}
if !cidr.IsSubnet() {
err = fmt.Errorf("invalid subnet - bits after network prefix are not all zero: %s", cidrStr)
}
if cidr.Size() < MinSubnetSize {
err = fmt.Errorf("invalid subnet - smaller than minimum size %d: %s", MinSubnetSize, cidrStr)
}
return
}
// Start runs the allocator goroutine
func (alloc *Allocator) Start() {
loadedPersistedData := alloc.loadPersistedData()