aboutsummaryrefslogtreecommitdiffstats
path: root/tun/tun_freebsd.go (follow)
Commit message (Collapse)AuthorAgeFilesLines
* tun: formatJason A. Donenfeld2021-05-071-2/+2
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: avoid OOB writesJason A. Donenfeld2021-04-191-0/+7
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: become controlling process when reopening tun FDJason A. Donenfeld2021-04-191-0/+10
| | | | | | | When we pass the TUN FD to the child, we have to call TUNSIFPID; otherwise when we close the device, we get a splat in dmesg. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: restructure and cleanupJason A. Donenfeld2021-04-191-166/+66
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: remove horrific hack for getting tunnel nameJason A. Donenfeld2021-04-191-84/+13
| | | | | | As of FreeBSD 12.1, there's TUNGIFNAME. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: set IFF_MULTICAST for routing daemonsJason A. Donenfeld2021-04-181-4/+4
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: use broadcast mode instead of PPP modeJason A. Donenfeld2021-03-231-0/+17
| | | | | | It makes the routing configuration simpler. Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: freebsd: allow empty namesKay Diam2021-03-081-16/+18
| | | | | | | | | This change allows omitting the tun interface name setting. When the name is not set, the kernel automatically picks up the tun name and index. Signed-off-by: Kay Diam <kay.diam@gmail.com> Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* tun: make NativeTun.Close well behaved, not crash on double closeBrad Fitzpatrick2021-02-221-10/+14
| | | | Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
* global: bump copyrightJason A. Donenfeld2021-01-281-1/+1
| | | | Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
* global: switch to using %w instead of %v for ErrorfJason A. Donenfeld2020-11-071-4/+4
| | | | 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: 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-2/+2
|
* global: regroup all importsJason A. Donenfeld2019-05-141-2/+3
|
* tun: freebsd: work around numerous kernel panics on shutdownJason A. Donenfeld2019-04-231-23/+82
| | | | | | | | | There are numerous race conditions. But even this will crash it: while true; do ifconfig tun0 create; ifconfig tun0 destroy; done It seems like LLv6 is related, which we're not using anyway, so explicitly disable it on the interface.
* receive: implement flush semanticsJason A. Donenfeld2019-03-211-0/+5
|
* tun: allow special methods in NativeTunJason A. Donenfeld2019-03-011-12/+12
|
* tun: use netpoll instead of rwcancelJason A. Donenfeld2019-02-271-32/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-14/+24
|
* Change package pathJason A. Donenfeld2019-02-181-1/+1
|
* Update copyrightJason A. Donenfeld2019-02-051-2/+2
|
* tun: only call .Fd() onceJason A. Donenfeld2018-10-171-19/+21
| | | | | 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-1/+1
|
* Disable broadcast mode on *BSDJason A. Donenfeld2018-05-271-13/+0
| | | | Keeping it on makes IPv6 problematic and confuses routing daemons.
* 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/+518