]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Trick for being extra sensitive to route changes
authorJason A. Donenfeld <Jason@zx2c4.com>
Thu, 24 May 2018 16:00:45 +0000 (18:00 +0200)
committerJason A. Donenfeld <Jason@zx2c4.com>
Thu, 24 May 2018 16:21:14 +0000 (18:21 +0200)
conn_linux.go

index bde441617f0ac57ccee098be2ac3af9902839da2..396c4031089964f97c5d3d5dc174fac8e6cb0aa1 100644 (file)
@@ -58,11 +58,12 @@ func (endpoint *NativeEndpoint) dst6() *unix.SockaddrInet6 {
 }
 
 type NativeBind struct {
-       sock4         int
-       sock6         int
-       netlinkSock   int
-       netlinkCancel *rwcancel.RWCancel
-       lastMark      uint32
+       sock4                        int
+       sock6                        int
+       netlinkSock                  int
+       netlinkCancel                *rwcancel.RWCancel
+       lastMark                     uint32
+       clearSourceOnAllRouteChanges bool
 }
 
 var _ Endpoint = (*NativeEndpoint)(nil)
@@ -582,6 +583,16 @@ 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