Refactor: move logging of ipset entries down to ipset package
This commit is contained in:
1 parent
9d29da8d27
commit
fa56ad8bc3
3 files changed
+7
-5
No files matched your search
+6
-2
@@ -1,6 +1,7 @@
|
|||||||
package ipset
|
package ipset
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@@ -31,10 +32,11 @@ type Interface interface {
|
|||||||
|
|
||||||
type ipset struct {
|
type ipset struct {
|
||||||
refCount
|
refCount
|
||||||
|
*log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
func New() Interface {
|
func New(logger *log.Logger) Interface {
|
||||||
return &ipset{refCount: newRefCount()}
|
return &ipset{refCount: newRefCount(), Logger: logger}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *ipset) Create(ipsetName Name, ipsetType Type) error {
|
func (i *ipset) Create(ipsetName Name, ipsetType Type) error {
|
||||||
@@ -42,6 +44,7 @@ func (i *ipset) Create(ipsetName Name, ipsetType Type) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *ipset) AddEntry(ipsetName Name, entry string) error {
|
func (i *ipset) AddEntry(ipsetName Name, entry string) error {
|
||||||
|
i.Logger.Printf("adding entry %s to %s", entry, ipsetName)
|
||||||
if i.inc(ipsetName, entry) > 1 { // already in the set
|
if i.inc(ipsetName, entry) > 1 { // already in the set
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -49,6 +52,7 @@ func (i *ipset) AddEntry(ipsetName Name, entry string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (i *ipset) DelEntry(ipsetName Name, entry string) error {
|
func (i *ipset) DelEntry(ipsetName Name, entry string) error {
|
||||||
|
i.Logger.Printf("deleting entry %s from %s", entry, ipsetName)
|
||||||
if i.dec(ipsetName, entry) > 0 { // still needed
|
if i.dec(ipsetName, entry) > 0 { // still needed
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,12 +43,10 @@ func (s *selector) matches(labelMap map[string]string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *selector) addEntry(entry string) error {
|
func (s *selector) addEntry(entry string) error {
|
||||||
common.Log.Infof("adding entry %s to %s", entry, s.spec.ipsetName)
|
|
||||||
return s.ips.AddEntry(s.spec.ipsetName, entry)
|
return s.ips.AddEntry(s.spec.ipsetName, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *selector) delEntry(entry string) error {
|
func (s *selector) delEntry(entry string) error {
|
||||||
common.Log.Infof("deleting entry %s from %s", entry, s.spec.ipsetName)
|
|
||||||
return s.ips.DelEntry(s.spec.ipsetName, entry)
|
return s.ips.DelEntry(s.spec.ipsetName, entry)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ func root(cmd *cobra.Command, args []string) {
|
|||||||
ipt, err := iptables.New()
|
ipt, err := iptables.New()
|
||||||
handleError(err)
|
handleError(err)
|
||||||
|
|
||||||
ips := ipset.New()
|
ips := ipset.New(common.LogLogger())
|
||||||
|
|
||||||
handleError(resetIPTables(ipt))
|
handleError(resetIPTables(ipt))
|
||||||
handleError(resetIPSets(ips))
|
handleError(resetIPSets(ips))
|
||||||
|
|||||||
Reference in new issue
Block a user