]> git.ipfire.org Git - thirdparty/wireguard-go.git/commitdiff
tun: freebsd: use broadcast mode instead of PPP mode
authorJason A. Donenfeld <Jason@zx2c4.com>
Tue, 23 Mar 2021 18:41:34 +0000 (12:41 -0600)
committerJason A. Donenfeld <Jason@zx2c4.com>
Tue, 23 Mar 2021 18:41:34 +0000 (12:41 -0600)
It makes the routing configuration simpler.

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
tun/tun_freebsd.go

index 1883aad589156398ac8d0b1f3b041c138926da18..c2ad65f5612e2870745f45e88f2d4c76492ae263 100644 (file)
@@ -292,6 +292,23 @@ func CreateTUN(name string, mtu int) (Device, error) {
                return nil, fmt.Errorf("Unable to put into IFHEAD mode: %w", errno)
        }
 
+       // Get out of PPP mode.
+       ifflags := syscall.IFF_BROADCAST
+       tun.operateOnFd(func(fd uintptr) {
+               _, _, errno = unix.Syscall(
+                       unix.SYS_IOCTL,
+                       fd,
+                       uintptr(_TUNSIFMODE),
+                       uintptr(unsafe.Pointer(&ifflags)),
+               )
+       })
+
+       if errno != 0 {
+               tunFile.Close()
+               tunDestroy(assignedName)
+               return nil, fmt.Errorf("Unable to put into IFF_BROADCAST mode: %w", errno)
+       }
+
        // Open control sockets
        confd, err := unix.Socket(
                unix.AF_INET,