diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-13 23:14:43 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2018-05-13 23:20:13 +0200 |
commit | b56af1829d0368c893f8e9e14894f9563afb60ef (patch) | |
tree | bf8aaeefe196ff6672819c1c858c7b5d19352577 /conn.go | |
parent | 729773fdf3cbec5f75d5981fc1fe6f7f21b0e00c (diff) |
More refactoring
Diffstat (limited to 'conn.go')
-rw-r--r-- | conn.go | 20 |
1 files changed, 14 insertions, 6 deletions
@@ -74,9 +74,6 @@ func (device *Device) BindSetMark(mark uint32) error { device.net.mutex.Lock() defer device.net.mutex.Unlock() - device.peers.mutex.Lock() - defer device.peers.mutex.Unlock() - // check if modified if device.net.fwmark == mark { @@ -92,6 +89,18 @@ func (device *Device) BindSetMark(mark uint32) error { } } + // clear cached source addresses + + device.peers.mutex.RLock() + for _, peer := range device.peers.keyMap { + peer.mutex.Lock() + defer peer.mutex.Unlock() + if peer.endpoint != nil { + peer.endpoint.ClearSrc() + } + } + device.peers.mutex.RUnlock() + return nil } @@ -100,9 +109,6 @@ func (device *Device) BindUpdate() error { device.net.mutex.Lock() defer device.net.mutex.Unlock() - device.peers.mutex.Lock() - defer device.peers.mutex.Unlock() - // close existing sockets if err := unsafeCloseBind(device); err != nil { @@ -135,6 +141,7 @@ func (device *Device) BindUpdate() error { // clear cached source addresses + device.peers.mutex.RLock() for _, peer := range device.peers.keyMap { peer.mutex.Lock() defer peer.mutex.Unlock() @@ -142,6 +149,7 @@ func (device *Device) BindUpdate() error { peer.endpoint.ClearSrc() } } + device.peers.mutex.RUnlock() // start receiving routines |