From 04aad6a34b8247e98952e5f89e82c78286f9cf0e Mon Sep 17 00:00:00 2001 From: ston1th Date: Sun, 26 Sep 2021 19:47:17 +0200 Subject: [PATCH] added CIDR method --- alloc.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/alloc.go b/alloc.go index c4aab2b..5bb635b 100644 --- a/alloc.go +++ b/alloc.go @@ -47,7 +47,7 @@ func (a *GenericAlloc) Alloc() (ip *net.IPAddr, err error) { last := c.Last() for ; pos != nil && pos != last; pos = c.Next() { net := &net.IPAddr{IP: pos.IP} - cidr := CIDR(a.prefix, net) + cidr := a.CIDR(net) ok, e := a.store.Exists(cidr) if e != nil { return nil, e @@ -67,13 +67,13 @@ func (a *GenericAlloc) AllocCIDR() (cidr string, err error) { if err != nil { return } - return CIDR(a.prefix, ip), nil + return a.CIDR(ip), nil } func (a *GenericAlloc) Free(ip *net.IPAddr) (err error) { a.store.Lock() defer a.store.Unlock() - cidr := CIDR(a.prefix, ip) + cidr := a.CIDR(ip) a.store.Delete(cidr) return } @@ -86,6 +86,10 @@ func (a *GenericAlloc) FreeCIDR(cidr string) (err error) { 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) { a.store = store }