// 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")
}
}
}
-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 {
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
"net"
"os"
"strings"
+ "time"
"unsafe"
)
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)
}
go device.RoutineNetlinkListener()
+ go device.RoutineHackListener() // cross namespace
// set default MTU
}
go device.RoutineNetlinkListener()
+ go device.RoutineHackListener() // cross namespace
// set default MTU