added CIDR method
This commit is contained in:
parent
aac88a8fad
commit
04aad6a34b
1 changed files with 7 additions and 3 deletions
10
alloc.go
10
alloc.go
|
|
@ -47,7 +47,7 @@ func (a *GenericAlloc) Alloc() (ip *net.IPAddr, err error) {
|
||||||
last := c.Last()
|
last := c.Last()
|
||||||
for ; pos != nil && pos != last; pos = c.Next() {
|
for ; pos != nil && pos != last; pos = c.Next() {
|
||||||
net := &net.IPAddr{IP: pos.IP}
|
net := &net.IPAddr{IP: pos.IP}
|
||||||
cidr := CIDR(a.prefix, net)
|
cidr := a.CIDR(net)
|
||||||
ok, e := a.store.Exists(cidr)
|
ok, e := a.store.Exists(cidr)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
return nil, e
|
return nil, e
|
||||||
|
|
@ -67,13 +67,13 @@ func (a *GenericAlloc) AllocCIDR() (cidr string, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return CIDR(a.prefix, ip), nil
|
return a.CIDR(ip), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a *GenericAlloc) Free(ip *net.IPAddr) (err error) {
|
func (a *GenericAlloc) Free(ip *net.IPAddr) (err error) {
|
||||||
a.store.Lock()
|
a.store.Lock()
|
||||||
defer a.store.Unlock()
|
defer a.store.Unlock()
|
||||||
cidr := CIDR(a.prefix, ip)
|
cidr := a.CIDR(ip)
|
||||||
a.store.Delete(cidr)
|
a.store.Delete(cidr)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -86,6 +86,10 @@ func (a *GenericAlloc) FreeCIDR(cidr string) (err error) {
|
||||||
return a.Free(&net.IPAddr{IP: ip})
|
return a.Free(&net.IPAddr{IP: ip})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *GenericAlloc) CIDR(ip *net.IPAddr) string {
|
||||||
|
return CIDR(a.prefix, ip)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *GenericAlloc) SetStore(store Store) {
|
func (a *GenericAlloc) SetStore(store Store) {
|
||||||
a.store = store
|
a.store = store
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue