Tobias Klauser
8ae09213a7
tun: use IoctlCtlInfo from golang.org/x/sys/unix on macOS
...
Direct syscalls using unix.Syscall(unix.SYS_*, ...) are discouraged on
macOS and might not be supported in future versions. Switch to use
unix.IoctlCtlInfo to get the kernel control info.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-27 16:20:09 +01:00
Tobias Klauser
36dc8b6994
tun: use GetsockoptString in (*NativeTun).Name on macOS
...
Direct syscalls using unix.Syscall(unix.SYS_*, ...) are discouraged on
macOS and might not be supported in future versions. Instead, use the
existing unix.GetsockoptString wrapper to get the interface name.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-10-27 16:20:09 +01:00
Jason A. Donenfeld
db0aa39b76
global: update header comments and modules
...
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
2020-05-02 02:08:26 -06:00
Jason A. Donenfeld
caebdfe9d0
tun: darwin: ignore ENOMEM errors
...
Coauthored-by: Andrej Mihajlov <and@mullvad.net>
2020-01-15 13:39:37 -05:00
Jason A. Donenfeld
6d78f89557
tun: darwin: do not attempt to close tun.event twice
...
Previously it was possible for this to race. It turns out we really
don't need to set anything to -1 anyway.
2019-08-02 12:24:17 +02:00
Matt Layher
1f48971a80
tun: remove TUN prefix from types to reduce stutter elsewhere
...
Signed-off-by: Matt Layher <mdlayher@gmail.com>
2019-06-14 18:35:57 +02:00
Jason A. Donenfeld
eaf17becfa
global: fixup TODO comment spacing
2019-06-06 23:00:15 +02:00
Jason A. Donenfeld
3bf41b06ae
global: regroup all imports
2019-05-14 09:09:52 +02:00
Jason A. Donenfeld
d024393335
tun: darwin: write routeSocket variable in helper
...
Otherwise the race detector "complains".
2019-04-19 07:53:19 +09:00
Jason A. Donenfeld
6440f010ee
receive: implement flush semantics
2019-03-21 14:45:41 -06:00
Jason A. Donenfeld
68f0721c6a
tun: import mobile particularities
2019-03-04 16:37:11 +01:00
Jason A. Donenfeld
967d1a0f3d
tun: allow special methods in NativeTun
2019-03-01 00:05:57 +01:00
Jason A. Donenfeld
366cbd11a4
tun: use netpoll instead of rwcancel
...
The new sysconn function of Go 1.12 makes this possible:
package main
import "log"
import "os"
import "unsafe"
import "time"
import "syscall"
import "sync"
import "golang.org/x/sys/unix"
func main() {
fd, err := os.OpenFile("/dev/net/tun", os.O_RDWR, 0)
if err != nil {
log.Fatal(err)
}
var ifr [unix.IFNAMSIZ + 64]byte
copy(ifr[:], []byte("cheese"))
*(*uint16)(unsafe.Pointer(&ifr[unix.IFNAMSIZ])) = unix.IFF_TUN
var errno syscall.Errno
s, _ := fd.SyscallConn()
s.Control(func(fd uintptr) {
_, _, errno = unix.Syscall(
unix.SYS_IOCTL,
fd,
uintptr(unix.TUNSETIFF),
uintptr(unsafe.Pointer(&ifr[0])),
)
})
if errno != 0 {
log.Fatal(errno)
}
b := [4]byte{}
wait := sync.WaitGroup{}
wait.Add(1)
go func() {
_, err := fd.Read(b[:])
log.Print("Read errored: ", err)
wait.Done()
}()
time.Sleep(time.Second)
log.Print("Closing")
err = fd.Close()
if err != nil {
log.Print("Close errored: " , err)
}
wait.Wait()
log.Print("Exiting")
}
2019-02-27 01:52:55 +01:00
Jason A. Donenfeld
ab0f442daf
tun: use sysconn instead of .Fd with Go 1.12
2019-02-27 01:34:11 +01:00
Jason A. Donenfeld
42c6d0e261
Change package path
2019-02-18 05:11:39 +01:00
Jason A. Donenfeld
dff424baf8
Update copyright
2019-02-05 12:59:42 +01:00
Jason A. Donenfeld
276bf973e8
Use darwin tun on ios
2018-11-06 16:24:35 +01:00
Jason A. Donenfeld
2e772194cf
tun: only call .Fd() once
...
Doing so tends to make the tunnel blocking, so we only retrieve it once
before we call SetNonblock, and then cache the result.
2018-10-17 21:31:42 +02:00
Jason A. Donenfeld
5be541d147
global: fix up copyright headers
2018-09-16 18:49:19 +02:00
Jason A. Donenfeld
0ba551807f
Do not build tun device on ios
2018-06-09 03:31:17 +02:00
Jason A. Donenfeld
2f2eca8947
Catch EINTR
2018-05-24 15:36:29 +02:00
Jason A. Donenfeld
588b9f01ae
Adopt GOPATH
...
GOPATH is annoying, but the Go community pushing me to adopt it is even
more annoying.
2018-05-23 05:18:13 +02:00
Jason A. Donenfeld
0a63188afa
Move tun to subpackage
2018-05-23 03:58:27 +02:00