summaryrefslogtreecommitdiff
path: root/conn.go
diff options
context:
space:
mode:
Diffstat (limited to 'conn.go')
-rw-r--r--conn.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/conn.go b/conn.go
index 082bbca..4b347ec 100644
--- a/conn.go
+++ b/conn.go
@@ -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