This commit is contained in:
黄思敏 2022-08-26 09:57:09 +08:00
parent 676acb3198
commit 4d0f25400a
2 changed files with 14 additions and 5 deletions

View File

@ -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()
}

11
tap.go
View File

@ -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())