fix whitespace mismatch

This commit is contained in:
snow flurry 2022-03-21 19:37:56 -07:00
parent 0d9a2f9d68
commit 5181a06304

View file

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