aboutsummaryrefslogtreecommitdiffstats
path: root/tun/tun_linux.go (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tun: avoid leaking sock fd in CreateTUN error casesTobias Klauser2021-09-231-4/+7
| | | | | | | | 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: linux: account for interface removal from outsideJason A. Donenfeld2021-05-201-25/+28
| | | | | | | | On Linux we can run `ip link del wg0`, in which case the fd becomes stale, and we should exit. Since this is an intentional action, don't treat it as an error. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: linux: do not spam events every second from hack listenerJason A. Donenfeld2021-03-111-6/+17
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: make NativeTun.Close well behaved, not crash on double closeBrad Fitzpatrick2021-02-221-10/+13
| | | | Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
* rwcancel: add an explicit close callJason A. Donenfeld2021-02-091-0/+1
| | | | | | This lets us collect FDs even if the GC doesn't do it for us. 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 %w for errors on linuxJason A. Donenfeld2021-01-271-9/+8
| | | | 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: return a better error message if /dev/net/tun doesn't existBrad Fitzpatrick2020-05-021-0/+3
| | | | | | | It was just returning "no such file or directory" (the String of the syscall.Errno returned by CreateTUN). Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
* tun: NetlinkListener: don't send EventDown before sending EventUpAvery Pennarun2020-05-021-1/+13
| | | | | | | | | | | | | | | | | | This works around a startup race condition when competing with HackListener, which is trying to do the same job. If HackListener detects that the tundev is running while there is still an event in the netlink queue that says it isn't running, then the device receives a string of events like EventUp (HackListener) EventDown (NetlinkListener) EventUp (NetlinkListener) Unfortunately, after the first EventDown, the device stops itself, thinking incorrectly that the administrator has downed its tundev. The device is ignoring the initial EventDown anyway, so just don't emit it. Signed-off-by: Avery Pennarun <apenwarr@tailscale.com>
* tun: fix data race on name fieldBrad Fitzpatrick2020-05-021-13/+31
| | | | Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
* tun: remove unused isUp methodBrad Fitzpatrick2020-05-021-6/+0
| | | | Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
* global: use RTMGRP_* consts from x/sys/unixTobias Klauser2020-03-171-1/+1
| | | | | | | | Update the golang.org/x/sys/unix dependency and use the newly introduced RTMGRP_* consts instead of using the corresponding RTNLGRP_* const to create a mask. Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
* global: fix a few typos courtesy of codespellJonathan Tooker2019-10-221-1/+1
| | | | Signed-off-by: Jonathan Tooker <jonathan.tooker@netprotect.com>
* tun: remove TUN prefix from types to reduce stutter elsewhereMatt Layher2019-06-141-16/+16
| | | | 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-3/+4
|
* receive: implement flush semanticsJason A. Donenfeld2019-03-211-0/+5
|
* tun: linux: work out netpoll trickJason A. Donenfeld2019-03-071-54/+46
|
* tun: import mobile particularitiesJason A. Donenfeld2019-03-041-0/+22
|
* tun: allow special methods in NativeTunJason A. Donenfeld2019-03-011-14/+14
|
* tun: linux: netpoll is broken for tun's epollJason A. Donenfeld2019-02-271-27/+48
| | | | | | So this mostly reverts the switch to Sysconn for Linux. Issue: https://github.com/golang/go/issues/30426
* tun: linux: netlink sock needs cleaning up but file will be gc'dJason A. Donenfeld2019-02-271-4/+2
|
* tun: use netpoll instead of rwcancelJason A. Donenfeld2019-02-271-41/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-24/+21
|
* Change package pathJason A. Donenfeld2019-02-181-1/+1
|
* Update copyrightJason A. Donenfeld2019-02-051-2/+2
|
* tun: remove nonblock hack for linuxJason A. Donenfeld2018-12-061-10/+0
| | | | | | This is no longer necessary and actually breaks things Reported-by: Chris Branch <cbranch@cloudflare.com>
* tun: only call .Fd() onceJason A. Donenfeld2018-10-171-15/+17
| | | | | 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
|
* Fix duplicate copyright lineJason A. Donenfeld2018-07-301-2/+0
|
* Catch EINTRJason A. Donenfeld2018-05-241-3/+3
|
* 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/+468