summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2021-04-19 15:01:36 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2021-04-19 15:02:44 -0600
commit0687dc06c873d4dac0b604d642d724c2f5abb6b6 (patch)
treef4c146645ae88c5b9d0f1405f39ed5f76d8482d1
parent71aefa374d141776abfb8dede5c3af3fe796842e (diff)
tun: freebsd: become controlling process when reopening tun FD
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>
-rw-r--r--tun/tun_freebsd.go10
1 files changed, 10 insertions, 0 deletions
diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go
index 53d4f41..37f1a0c 100644
--- a/tun/tun_freebsd.go
+++ b/tun/tun_freebsd.go
@@ -21,6 +21,7 @@ const (
_TUNSIFHEAD = 0x80047460
_TUNSIFMODE = 0x8004745e
_TUNGIFNAME = 0x4020745d
+ _TUNSIFPID = 0x2000745f
_SIOCGIFINFO_IN6 = 0xc048696c
_SIOCSIFINFO_IN6 = 0xc048696d
@@ -266,6 +267,15 @@ func CreateTUNFromFile(file *os.File, mtu int) (Device, error) {
errors: make(chan error, 1),
}
+ var errno syscall.Errno
+ tun.operateOnFd(func(fd uintptr) {
+ _, _, errno = unix.Syscall(unix.SYS_IOCTL, fd, _TUNSIFPID, uintptr(0))
+ })
+ if errno != 0 {
+ tun.tunFile.Close()
+ return nil, fmt.Errorf("unable to become controlling TUN process: %w", errno)
+ }
+
name, err := tun.Name()
if err != nil {
tun.tunFile.Close()