]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
Added cross namespace TUN status detection
authorMathias Hall-Andersen <mathias@hall-andersen.dk>
Wed, 29 Nov 2017 17:46:31 +0000 (18:46 +0100)
committerMathias Hall-Andersen <mathias@hall-andersen.dk>
Wed, 29 Nov 2017 17:46:31 +0000 (18:46 +0100)
src/conn.go
src/receive.go
src/tests/netns.sh
src/timers.go
src/tun_linux.go

index b17ac7092670249a0cc6c47af70d45124f83fffe..6d292d36f74af8648e58bcb374ca2f5c7fa6dfe1 100644 (file)
@@ -114,8 +114,8 @@ func updateBind(device *Device) error {
 
                // decrease waitgroup to 0
 
-               go device.RoutineReceiveIncomming(ipv4.Version, netc.bind)
-               go device.RoutineReceiveIncomming(ipv6.Version, netc.bind)
+               go device.RoutineReceiveIncoming(ipv4.Version, netc.bind)
+               go device.RoutineReceiveIncoming(ipv6.Version, netc.bind)
 
                device.log.Debug.Println("UDP bind has been updated")
        }
index 27fdb8ac044a1b358c55579dbd0835293c5a9b7a..0b0efbffbba61017eb7214da29911881677d8fb5 100644 (file)
@@ -93,10 +93,10 @@ func (device *Device) addToHandshakeQueue(
        }
 }
 
-func (device *Device) RoutineReceiveIncomming(IP int, bind Bind) {
+func (device *Device) RoutineReceiveIncoming(IP int, bind Bind) {
 
        logDebug := device.log.Debug
-       logDebug.Println("Routine, receive incomming, IP version:", IP)
+       logDebug.Println("Routine, receive incoming, IP version:", IP)
 
        for {
 
index 22abea8d6f4526347e080ec4207af03f8fbbfd4c..02d428b1474097ffa523bd7f18276f44379b9480 100755 (executable)
@@ -120,6 +120,7 @@ configure_peers() {
 
     ip1 link set up dev wg1
     ip2 link set up dev wg2
+    sleep 1
 }
 configure_peers
 
index 31165a3bd0e5e1cbbc8a84579f6e98323d5859d9..d372b0d0c0930f9ee400e2f70811bc3633da26e4 100644 (file)
@@ -321,8 +321,14 @@ func (peer *Peer) RoutineHandshakeInitiator() {
                                goto BeginHandshakes\r
 \r
                        case <-timeout.C:\r
-                               // TODO: Clear source address for peer\r
-                               continue\r
+\r
+                               // clear source address of peer\r
+\r
+                               peer.mutex.Lock()\r
+                               if peer.endpoint != nil {\r
+                                       peer.endpoint.ClearSrc()\r
+                               }\r
+                               peer.mutex.Unlock()\r
                        }\r
                }\r
 \r
index a728a488f83616ed2d346ab7553a7d7417d0eff5..81f1bbbed5221c7b9871456f993c8fe5b828cf6c 100644 (file)
@@ -11,6 +11,7 @@ import (
        "net"
        "os"
        "strings"
+       "time"
        "unsafe"
 )
 
@@ -60,15 +61,32 @@ func (tun *NativeTun) File() *os.File {
        return tun.fd
 }
 
+func (tun *NativeTun) RoutineHackListener() {
+       /* This is needed for the detection to work accross network namespaces
+        * If you are reading this and know a better method, please get in touch.
+        */
+       fd := int(tun.fd.Fd())
+       for {
+               _, err := unix.Write(fd, nil)
+               switch err {
+               case unix.EINVAL:
+                       tun.events <- TUNEventUp
+               case unix.EIO:
+                       tun.events <- TUNEventDown
+               default:
+               }
+               time.Sleep(time.Second / 10)
+       }
+}
+
 func (tun *NativeTun) RoutineNetlinkListener() {
+
        sock := int(C.bind_rtmgrp())
        if sock < 0 {
                tun.errors <- errors.New("Failed to create netlink event listener")
                return
        }
 
-       tun.events <- TUNEventUp // TODO: Fix network namespace problem
-
        for msg := make([]byte, 1<<16); ; {
 
                msgn, _, _, _, err := unix.Recvmsg(sock, msg[:], nil, 0)
@@ -269,6 +287,7 @@ func CreateTUNFromFile(name string, fd *os.File) (TUNDevice, error) {
        }
 
        go device.RoutineNetlinkListener()
+       go device.RoutineHackListener() // cross namespace
 
        // set default MTU
 
@@ -324,6 +343,7 @@ func CreateTUN(name string) (TUNDevice, error) {
        }
 
        go device.RoutineNetlinkListener()
+       go device.RoutineHackListener() // cross namespace
 
        // set default MTU