diff --git a/config.go b/config.go index 8e9a7c8..3dbfec8 100644 --- a/config.go +++ b/config.go @@ -23,7 +23,7 @@ type Config struct { } `yaml:"network"` IPv4Nodes map[uint32]string - Lock sync.Mutex + lock sync.Mutex } var config = NewConfig() @@ -56,3 +56,9 @@ func NewConfig() *Config { return cnf } + +func (cnf *Config) Lock(do func()) { + cnf.lock.Lock() + defer cnf.lock.Unlock() + do() +} diff --git a/tap.go b/tap.go index 103f49a..4035019 100644 --- a/tap.go +++ b/tap.go @@ -167,12 +167,15 @@ func (nc *NetCard) runRead() { continue } - var realAddr string - config.Lock.Lock() - if _, ok = config.IPv4Nodes[binary.LittleEndian.Uint32([]byte(waterutil.IPv4Destination(rframe)))]; !ok { + var realAddr string = "" + config.Lock(func() { + if realAddr, ok = config.IPv4Nodes[binary.LittleEndian.Uint32([]byte(waterutil.IPv4Destination(rframe)))]; !ok { + return + } + }) + if realAddr == "" { continue } - config.Lock.Unlock() // log.Printf("Payload: % x\n", rframe.Payload())