diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2020-10-27 14:39:34 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2020-10-27 16:20:09 +0100 |
commit | 8ae09213a7ba2520dd4c206c76d1730a55408519 (patch) | |
tree | 5b34938e2fe38d0e95d7a2f6ead379a719d07950 /tun | |
parent | 36dc8b6994514e42fcdf00ba91774148afbefc1c (diff) |
tun: use IoctlCtlInfo from golang.org/x/sys/unix on macOS
Direct syscalls using unix.Syscall(unix.SYS_*, ...) are discouraged on
macOS and might not be supported in future versions. Switch to use
unix.IoctlCtlInfo to get the kernel control info.
Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'tun')
-rw-r--r-- | tun/tun_darwin.go | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go index f04ace2..c30e733 100644 --- a/tun/tun_darwin.go +++ b/tun/tun_darwin.go @@ -20,9 +20,6 @@ import ( const utunControlName = "com.apple.net.utun_control" -// _CTLIOCGINFO value derived from /usr/include/sys/{kern_control,ioccom}.h -const _CTLIOCGINFO = (0x40000000 | 0x80000000) | ((100 & 0x1fff) << 16) | uint32(byte('N'))<<8 | 3 - // sockaddr_ctl specifeid in /usr/include/sys/kern_control.h type sockaddrCtl struct { scLen uint8 @@ -130,29 +127,18 @@ func CreateTUN(name string, mtu int) (Device, error) { return nil, err } - var ctlInfo = &struct { - ctlID uint32 - ctlName [96]byte - }{} - - copy(ctlInfo.ctlName[:], []byte(utunControlName)) - - _, _, errno := unix.Syscall( - unix.SYS_IOCTL, - uintptr(fd), - uintptr(_CTLIOCGINFO), - uintptr(unsafe.Pointer(ctlInfo)), - ) - - if errno != 0 { - return nil, fmt.Errorf("_CTLIOCGINFO: %v", errno) + ctlInfo := &unix.CtlInfo{} + copy(ctlInfo.Name[:], []byte(utunControlName)) + err = unix.IoctlCtlInfo(fd, ctlInfo) + if err != nil { + return nil, fmt.Errorf("IoctlGetCtlInfo: %w", err) } sc := sockaddrCtl{ scLen: uint8(sockaddrCtlSize), scFamily: unix.AF_SYSTEM, ssSysaddr: 2, - scID: ctlInfo.ctlID, + scID: ctlInfo.Id, scUnit: uint32(ifIndex) + 1, } |