From 201321f3909e4c66cf0905140cbe45100f43b5cd Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Tue, 14 Feb 2017 10:36:18 +0000 Subject: [PATCH] Remove refcounts on destroy and flush --- npc/ipset/ipset.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/npc/ipset/ipset.go b/npc/ipset/ipset.go index 38b343cd..3a27327b 100644 --- a/npc/ipset/ipset.go +++ b/npc/ipset/ipset.go @@ -53,18 +53,22 @@ func (i *ipset) DelEntry(ipsetName Name, entry string) error { } func (i *ipset) Flush(ipsetName Name) error { + i.removeSet(ipsetName) return doExec("flush", string(ipsetName)) } func (i *ipset) FlushAll() error { + i.refCount = newRefCount() return doExec("flush") } func (i *ipset) Destroy(ipsetName Name) error { + i.removeSet(ipsetName) return doExec("destroy", string(ipsetName)) } func (i *ipset) DestroyAll() error { + i.refCount = newRefCount() return doExec("destroy") } @@ -101,3 +105,11 @@ func (rc *refCount) dec(ipsetName Name, entry string) int { rc.ref[k]-- return rc.ref[k] } + +func (rc *refCount) removeSet(ipsetName Name) { + for k := range rc.ref { + if k.ipsetName == ipsetName { + delete(rc.ref, k) + } + } +}