Refactor: move logging of ipset entries down to ipset package

This commit is contained in:
Bryan Boreham committed 2017-05-30 14:11:33 +00:00
1 parent 9d29da8d27
commit fa56ad8bc3
3 files changed
+7 -5

No files matched your search

+6 -2
View File
@@ -1,6 +1,7 @@
package ipset
import (
"log"
"os/exec"
"strings"
@@ -31,10 +32,11 @@ type Interface interface {
type ipset struct {
refCount
*log.Logger
}
func New() Interface {
return &ipset{refCount: newRefCount()}
func New(logger *log.Logger) Interface {
return &ipset{refCount: newRefCount(), Logger: logger}
}
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 {
i.Logger.Printf("adding entry %s to %s", entry, ipsetName)
if i.inc(ipsetName, entry) > 1 { // already in the set
return nil
}
@@ -49,6 +52,7 @@ func (i *ipset) AddEntry(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
return nil
}
-2
View File
@@ -43,12 +43,10 @@ func (s *selector) matches(labelMap map[string]string) bool {
}
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)
}
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)
}
+1 -1
View File
@@ -135,7 +135,7 @@ func root(cmd *cobra.Command, args []string) {
ipt, err := iptables.New()
handleError(err)
ips := ipset.New()
ips := ipset.New(common.LogLogger())
handleError(resetIPTables(ipt))
handleError(resetIPSets(ips))