}
fd, err := unix.Socket(unix.AF_SYSTEM, unix.SOCK_DGRAM, 2)
-
if err != nil {
return nil, err
}
copy(ctlInfo.Name[:], []byte(utunControlName))
err = unix.IoctlCtlInfo(fd, ctlInfo)
if err != nil {
+ unix.Close(fd)
return nil, fmt.Errorf("IoctlGetCtlInfo: %w", err)
}
err = unix.Connect(fd, sc)
if err != nil {
+ unix.Close(fd)
return nil, err
}
- err = syscall.SetNonblock(fd, true)
+ err = unix.SetNonblock(fd, true)
if err != nil {
+ unix.Close(fd)
return nil, err
}
tun, err := CreateTUNFromFile(os.NewFile(uintptr(fd), ""), mtu)
var flags uint16 = unix.IFF_TUN // | unix.IFF_NO_PI (disabled for TUN status hack)
nameBytes := []byte(name)
if len(nameBytes) >= unix.IFNAMSIZ {
+ unix.Close(nfd)
return nil, fmt.Errorf("interface name too long: %w", unix.ENAMETOOLONG)
}
copy(ifr[:], nameBytes)
uintptr(unsafe.Pointer(&ifr[0])),
)
if errno != 0 {
+ unix.Close(nfd)
return nil, errno
}
- err = unix.SetNonblock(nfd, true)
-
- // Note that the above -- open,ioctl,nonblock -- must happen prior to handing it to netpoll as below this line.
- fd := os.NewFile(uintptr(nfd), cloneDevicePath)
+ err = unix.SetNonblock(nfd, true)
if err != nil {
+ unix.Close(nfd)
return nil, err
}
+ // Note that the above -- open,ioctl,nonblock -- must happen prior to handing it to netpoll as below this line.
+
+ fd := os.NewFile(uintptr(nfd), cloneDevicePath)
return CreateTUNFromFile(fd, mtu)
}