// Release allows releasing the address from the specified address space func (a *Allocator) Release(addrSpace AddressSpace, address net.IP) { var ( space *bitseq.Handle sub *net.IPNet ) if address == nil { log.Debugf("Requested to remove nil address from address space %s", addrSpace) return } ver := getAddressVersion(address) if ver == v4 { address = address.To4() } // Find the subnet containing the address for _, subKey := range a.getSubnetList(addrSpace, ver) { sub = subKey.canonicalChildSubnet() if sub.Contains(address) { a.Lock() space = a.addresses[subKey] a.Unlock() break } } if space == nil { log.Debugf("Could not find subnet on address space %s containing %s on release", addrSpace, address.String()) return } // Retrieve correspondent ordinal in the subnet hostPart, err := types.GetHostPartIP(address, sub.Mask) if err != nil { log.Warnf("Failed to release address %s on address space %s because of internal error: %v", address.String(), addrSpace, err) return } ordinal := ipToUint32(hostPart) // Release it if err := space.Unset(ordinal); err != nil { log.Warnf("Failed to release address %s on address space %s because of internal error: %v", address.String(), addrSpace, err) } }