summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2018-05-26 02:59:26 +0200
committerJason A. Donenfeld <Jason@zx2c4.com>2018-05-27 22:55:15 +0200
commitfc3a7635e56a336ae06277ce3157b1b14fdd2fa8 (patch)
treef11ddb7168799c81fc6f5a73949a58e646d627a2
parent2496cdd8e6078e2a6955b7facb239e4cf2fe5e55 (diff)
Disappointing anti-sticky experiment
-rw-r--r--conn_default.go2
-rw-r--r--conn_linux.go23
-rw-r--r--peer.go11
-rw-r--r--receive.go15
4 files changed, 22 insertions, 29 deletions
diff --git a/conn_default.go b/conn_default.go
index bd1b08b..14ed56c 100644
--- a/conn_default.go
+++ b/conn_default.go
@@ -1,4 +1,4 @@
-// +build !linux
+// +build !linux android
/* SPDX-License-Identifier: GPL-2.0
*
diff --git a/conn_linux.go b/conn_linux.go
index 396c403..0227f04 100644
--- a/conn_linux.go
+++ b/conn_linux.go
@@ -1,3 +1,5 @@
+// +build !android
+
/* SPDX-License-Identifier: GPL-2.0
*
* Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved.
@@ -58,12 +60,11 @@ func (endpoint *NativeEndpoint) dst6() *unix.SockaddrInet6 {
}
type NativeBind struct {
- sock4 int
- sock6 int
- netlinkSock int
- netlinkCancel *rwcancel.RWCancel
- lastMark uint32
- clearSourceOnAllRouteChanges bool
+ sock4 int
+ sock6 int
+ netlinkSock int
+ netlinkCancel *rwcancel.RWCancel
+ lastMark uint32
}
var _ Endpoint = (*NativeEndpoint)(nil)
@@ -583,16 +584,6 @@ func (bind *NativeBind) routineRouteListener(device *Device) {
switch hdr.Type {
case unix.RTM_NEWROUTE, unix.RTM_DELROUTE:
- if bind.clearSourceOnAllRouteChanges {
- for _, peer := range device.peers.keyMap {
- peer.mutex.Lock()
- if peer.endpoint != nil && peer.endpoint.(*NativeEndpoint) != nil {
- peer.endpoint.(*NativeEndpoint).ClearSrc()
- }
- peer.mutex.Unlock()
- }
- break
- }
if hdr.Seq <= MaxPeers && hdr.Seq > 0 {
if uint(len(remain)) < uint(hdr.Len) {
break
diff --git a/peer.go b/peer.go
index a279d96..228dc5e 100644
--- a/peer.go
+++ b/peer.go
@@ -258,3 +258,14 @@ func (peer *Peer) Stop() {
peer.ZeroAndFlushAll()
}
+
+var roamingDisabled bool
+
+func (peer *Peer) SetEndpointFromPacket(endpoint Endpoint) {
+ if roamingDisabled {
+ return
+ }
+ peer.mutex.Lock()
+ peer.endpoint = endpoint
+ peer.mutex.Unlock()
+}
diff --git a/receive.go b/receive.go
index 30a63d0..86d1e69 100644
--- a/receive.go
+++ b/receive.go
@@ -440,10 +440,7 @@ func (device *Device) RoutineHandshake() {
peer.timersAnyAuthenticatedPacketReceived()
// update endpoint
-
- peer.mutex.Lock()
- peer.endpoint = elem.endpoint
- peer.mutex.Unlock()
+ peer.SetEndpointFromPacket(elem.endpoint)
logDebug.Println(peer, "- Received handshake initiation")
@@ -473,10 +470,7 @@ func (device *Device) RoutineHandshake() {
}
// update endpoint
-
- peer.mutex.Lock()
- peer.endpoint = elem.endpoint
- peer.mutex.Unlock()
+ peer.SetEndpointFromPacket(elem.endpoint)
logDebug.Println(peer, "- Received handshake response")
@@ -549,10 +543,7 @@ func (peer *Peer) RoutineSequentialReceiver() {
}
// update endpoint
-
- peer.mutex.Lock()
- peer.endpoint = elem.endpoint
- peer.mutex.Unlock()
+ peer.SetEndpointFromPacket(elem.endpoint)
// check if using new keypair
if peer.ReceivedWithKeypair(elem.keypair) {