From 12ce53271baa04a8a8a2c491e1604c53d5f05cfb Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Tue, 23 Mar 2021 12:41:34 -0600 Subject: tun: freebsd: use broadcast mode instead of PPP mode It makes the routing configuration simpler. Signed-off-by: Jason A. Donenfeld --- tun/tun_freebsd.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'tun/tun_freebsd.go') diff --git a/tun/tun_freebsd.go b/tun/tun_freebsd.go index 1883aad..c2ad65f 100644 --- a/tun/tun_freebsd.go +++ b/tun/tun_freebsd.go @@ -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, -- cgit v1.2.3-59-g8ed1b