fix whitespace mismatch

This commit is contained in:
snow flurry 2022-03-21 19:37:56 -07:00
parent 0d9a2f9d68
commit 5181a06304
1 changed files with 40 additions and 40 deletions

View File

@ -6,12 +6,12 @@
package tun
import (
"errors"
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"sync"
"sync"
"syscall"
"unsafe"
@ -27,18 +27,18 @@ type ifreq_mtu struct {
}
const (
_TUNGIFHEAD = 0x40047441
_TUNSIFMODE = 0x80047458
_TUNSIFHEAD = 0x80047442
_TUNGIFHEAD = 0x40047441
_TUNSIFMODE = 0x80047458
_TUNSIFHEAD = 0x80047442
)
type NativeTun struct {
name string
tunFile *os.File
events chan Event
errors chan error
name string
tunFile *os.File
events chan Event
errors chan error
routeSocket int
closeOnce sync.Once
closeOnce sync.Once
}
func (tun *NativeTun) routineRouteListener(tunIfindex int) {
@ -148,29 +148,29 @@ func CreateTUN(name string, mtu int) (Device, error) {
// Enable ifhead mode, otherwise tun will complain if it gets a non-AF_INET packet
ifheadmode := 1
var errno syscall.Errno
_, _, errno = unix.Syscall(
unix.SYS_IOCTL,
tunfile.Fd(),
uintptr(_TUNSIFHEAD),
uintptr(unsafe.Pointer(&ifheadmode)),
)
_, _, errno = unix.Syscall(
unix.SYS_IOCTL,
tunfile.Fd(),
uintptr(_TUNSIFHEAD),
uintptr(unsafe.Pointer(&ifheadmode)),
)
if errno != 0 {
tunfile.Close()
return nil, fmt.Errorf("Unable to put into IFHEAD mode: %v", errno)
}
if errno != 0 {
tunfile.Close()
return nil, fmt.Errorf("Unable to put into IFHEAD mode: %v", errno)
}
_, _, errno = unix.Syscall(
unix.SYS_IOCTL,
tunfile.Fd(),
uintptr(_TUNGIFHEAD),
uintptr(unsafe.Pointer(&ifheadmode)),
)
_, _, errno = unix.Syscall(
unix.SYS_IOCTL,
tunfile.Fd(),
uintptr(_TUNGIFHEAD),
uintptr(unsafe.Pointer(&ifheadmode)),
)
if errno != 0 || ifheadmode == 0 {
tunfile.Close()
return nil, fmt.Errorf("Unable to validate IFHEAD mode: %v (ifheadmode = %d)", errno, ifheadmode)
}
if errno != 0 || ifheadmode == 0 {
tunfile.Close()
return nil, fmt.Errorf("Unable to validate IFHEAD mode: %v (ifheadmode = %d)", errno, ifheadmode)
}
if err == nil && name == "tun" {
fname := os.Getenv("WG_TUN_NAME_FILE")
@ -289,16 +289,16 @@ func (tun *NativeTun) Flush() error {
func (tun *NativeTun) Close() error {
var err1, err2 error
tun.closeOnce.Do(func () {
err1 = tun.tunFile.Close()
if tun.routeSocket != -1 {
unix.Shutdown(tun.routeSocket, unix.SHUT_RDWR)
err2 = unix.Close(tun.routeSocket)
tun.routeSocket = -1
} else if tun.events != nil {
close(tun.events)
}
})
tun.closeOnce.Do(func () {
err1 = tun.tunFile.Close()
if tun.routeSocket != -1 {
unix.Shutdown(tun.routeSocket, unix.SHUT_RDWR)
err2 = unix.Close(tun.routeSocket)
tun.routeSocket = -1
} else if tun.events != nil {
close(tun.events)
}
})
if err1 != nil {
return err1
}