Disappointing anti-sticky experiment

This commit is contained in:
Jason A. Donenfeld 2018-05-26 02:59:26 +02:00
parent 2496cdd8e6
commit fc3a7635e5
4 changed files with 22 additions and 29 deletions

View file

@ -1,4 +1,4 @@
// +build !linux // +build !linux android
/* SPDX-License-Identifier: GPL-2.0 /* SPDX-License-Identifier: GPL-2.0
* *

View file

@ -1,3 +1,5 @@
// +build !android
/* SPDX-License-Identifier: GPL-2.0 /* SPDX-License-Identifier: GPL-2.0
* *
* Copyright (C) 2017-2018 Jason A. Donenfeld <Jason@zx2c4.com>. All Rights Reserved. * 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 { type NativeBind struct {
sock4 int sock4 int
sock6 int sock6 int
netlinkSock int netlinkSock int
netlinkCancel *rwcancel.RWCancel netlinkCancel *rwcancel.RWCancel
lastMark uint32 lastMark uint32
clearSourceOnAllRouteChanges bool
} }
var _ Endpoint = (*NativeEndpoint)(nil) var _ Endpoint = (*NativeEndpoint)(nil)
@ -583,16 +584,6 @@ func (bind *NativeBind) routineRouteListener(device *Device) {
switch hdr.Type { switch hdr.Type {
case unix.RTM_NEWROUTE, unix.RTM_DELROUTE: 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 hdr.Seq <= MaxPeers && hdr.Seq > 0 {
if uint(len(remain)) < uint(hdr.Len) { if uint(len(remain)) < uint(hdr.Len) {
break break

11
peer.go
View file

@ -258,3 +258,14 @@ func (peer *Peer) Stop() {
peer.ZeroAndFlushAll() peer.ZeroAndFlushAll()
} }
var roamingDisabled bool
func (peer *Peer) SetEndpointFromPacket(endpoint Endpoint) {
if roamingDisabled {
return
}
peer.mutex.Lock()
peer.endpoint = endpoint
peer.mutex.Unlock()
}

View file

@ -440,10 +440,7 @@ func (device *Device) RoutineHandshake() {
peer.timersAnyAuthenticatedPacketReceived() peer.timersAnyAuthenticatedPacketReceived()
// update endpoint // update endpoint
peer.SetEndpointFromPacket(elem.endpoint)
peer.mutex.Lock()
peer.endpoint = elem.endpoint
peer.mutex.Unlock()
logDebug.Println(peer, "- Received handshake initiation") logDebug.Println(peer, "- Received handshake initiation")
@ -473,10 +470,7 @@ func (device *Device) RoutineHandshake() {
} }
// update endpoint // update endpoint
peer.SetEndpointFromPacket(elem.endpoint)
peer.mutex.Lock()
peer.endpoint = elem.endpoint
peer.mutex.Unlock()
logDebug.Println(peer, "- Received handshake response") logDebug.Println(peer, "- Received handshake response")
@ -549,10 +543,7 @@ func (peer *Peer) RoutineSequentialReceiver() {
} }
// update endpoint // update endpoint
peer.SetEndpointFromPacket(elem.endpoint)
peer.mutex.Lock()
peer.endpoint = elem.endpoint
peer.mutex.Unlock()
// check if using new keypair // check if using new keypair
if peer.ReceivedWithKeypair(elem.keypair) { if peer.ReceivedWithKeypair(elem.keypair) {