aboutsummaryrefslogtreecommitdiffstats
path: root/tun/tun_darwin.go (follow)
Commit message (Collapse)AuthorAgeFilesLines
* global: buff -> bufJason A. Donenfeld2023-03-131-6/+6
| | | | | | This always struck me as kind of weird and non-standard. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* conn, device, tun: implement vectorized I/O plumbingJordan Whited2023-03-101-30/+35
| | | | | | | | | | | | | | | | | | | | Accept packet vectors for reading and writing in the tun.Device and conn.Bind interfaces, so that the internal plumbing between these interfaces now passes a vector of packets. Vectors move untouched between these interfaces, i.e. if 128 packets are received from conn.Bind.Read(), 128 packets are passed to tun.Device.Write(). There is no internal buffering. Currently, existing implementations are only adjusted to have vectors of length one. Subsequent patches will improve that. Also, as a related fixup, use the unix and windows packages rather than the syscall package when possible. Co-authored-by: James Tucker <james@tailscale.com> Signed-off-by: James Tucker <james@tailscale.com> Signed-off-by: Jordan Whited <jordan@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: guard Device.Events() against chan writesJordan Whited2023-02-091-1/+1
| | | | | Signed-off-by: Jordan Whited <jordan@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: bump copyright yearJason A. Donenfeld2023-02-071-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: bump copyright yearJason A. Donenfeld2022-09-201-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* conn, device, tun: set CLOEXEC on fdsBrad Fitzpatrick2022-07-041-4/+16
| | | | | Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: apply gofumptJason A. Donenfeld2021-12-091-4/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: avoid leaking sock fd in CreateTUN error casesTobias Klauser2021-09-231-2/+4
| | | | | | | | At these points, the socket file descriptor is not yet wrapped in an *os.File, so it needs to be closed explicitly on error. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: make NativeTun.Close well behaved, not crash on double closeBrad Fitzpatrick2021-02-221-8/+12
| | | | Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
* global: stop using ioutilJason A. Donenfeld2021-02-171-2/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: use errors.Is for unwrappingJason A. Donenfeld2021-02-091-7/+4
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: bump copyrightJason A. Donenfeld2021-01-281-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: use SockaddrCtl from golang.org/x/sys/unix on macOSTobias Klauser2020-10-271-29/+6
| | | | | | | | | Direct syscalls using unix.Syscall(unix.SYS_*, ...) are discouraged on macOS and might not be supported in future versions. Switch to use unix.Connect with unix.SockaddrCtl instead. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: use Ioctl{Get,Set}IfreqMTU from golang.org/x/sys/unix on macOSTobias Klauser2020-10-271-35/+10
| | | | | | | | | Direct syscalls using unix.Syscall(unix.SYS_*, ...) are discouraged on macOS and might not be supported in future versions. Switch to use unix.Ioctl{Get,Set}IfreqMTU to get and set an interface's MTU. Signed-off-by: Tobias Klauser <tklauser@distanz.ch> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: use IoctlCtlInfo from golang.org/x/sys/unix on macOSTobias Klauser2020-10-271-20/+6
| | | | | | | | | 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>
* tun: use GetsockoptString in (*NativeTun).Name on macOSTobias Klauser2020-10-271-14/+6
| | | | | | | | | 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>
* global: update header comments and modulesJason A. Donenfeld2020-05-021-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: darwin: ignore ENOMEM errorsJason A. Donenfeld2020-01-151-1/+18
| | | | Coauthored-by: Andrej Mihajlov <and@mullvad.net>
* tun: darwin: do not attempt to close tun.event twiceJason A. Donenfeld2019-08-021-4/+1
| | | | | Previously it was possible for this to race. It turns out we really don't need to set anything to -1 anyway.
* tun: remove TUN prefix from types to reduce stutter elsewhereMatt Layher2019-06-141-8/+8
| | | | Signed-off-by: Matt Layher <mdlayher@gmail.com>
* global: fixup TODO comment spacingJason A. Donenfeld2019-06-061-1/+1
|
* global: regroup all importsJason A. Donenfeld2019-05-141-2/+3
|
* tun: darwin: write routeSocket variable in helperJason A. Donenfeld2019-04-191-2/+4
| | | | Otherwise the race detector "complains".
* receive: implement flush semanticsJason A. Donenfeld2019-03-211-0/+5
|
* tun: import mobile particularitiesJason A. Donenfeld2019-03-041-5/+7
|
* tun: allow special methods in NativeTunJason A. Donenfeld2019-03-011-12/+12
|
* tun: use netpoll instead of rwcancelJason A. Donenfeld2019-02-271-32/+9
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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") }
* tun: use sysconn instead of .Fd with Go 1.12Jason A. Donenfeld2019-02-271-13/+14
|
* Change package pathJason A. Donenfeld2019-02-181-1/+1
|
* Update copyrightJason A. Donenfeld2019-02-051-2/+2
|
* Use darwin tun on iosJason A. Donenfeld2018-11-061-2/+0
|
* tun: only call .Fd() onceJason A. Donenfeld2018-10-171-14/+16
| | | | | Doing so tends to make the tunnel blocking, so we only retrieve it once before we call SetNonblock, and then cache the result.
* global: fix up copyright headersJason A. Donenfeld2018-09-161-2/+1
|
* Do not build tun device on iosJason A. Donenfeld2018-06-091-0/+2
|
* Catch EINTRJason A. Donenfeld2018-05-241-2/+7
|
* Adopt GOPATHJason A. Donenfeld2018-05-231-1/+1
| | | | | GOPATH is annoying, but the Go community pushing me to adopt it is even more annoying.
* Move tun to subpackageJason A. Donenfeld2018-05-231-0/+382