Further "rebase" tun_netbsd against tun_openbsd

Cleaning out some stuff from the older version of wireguard-go.
This commit is contained in:
snow flurry 2022-03-21 19:58:54 -07:00
parent 470f2f0248
commit 515908773f

View file

@ -1,6 +1,6 @@
/* SPDX-License-Identifier: MIT
*
* Copyright (C) 2017-2020 WireGuard LLC. All Rights Reserved.
* Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
*/
package tun
@ -8,7 +8,6 @@ package tun
import (
"errors"
"fmt"
"io/ioutil"
"net"
"os"
"sync"
@ -26,11 +25,7 @@ type ifreq_mtu struct {
Pad0 [12]byte
}
const (
_TUNGIFHEAD = 0x40047441
_TUNSIFMODE = 0x80047458
_TUNSIFHEAD = 0x80047442
)
const _TUNSIFHEAD = 0x80047442
type NativeTun struct {
name string
@ -106,16 +101,6 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) {
}
}
func errorIsEBUSY(err error) bool {
if pe, ok := err.(*os.PathError); ok {
err = pe.Err
}
if errno, ok := err.(syscall.Errno); ok && errno == syscall.EBUSY {
return true
}
return false
}
func CreateTUN(name string, mtu int) (Device, error) {
ifIndex := -1
if name != "tun" {
@ -131,7 +116,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if ifIndex != -1 {
tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0)
} else {
for ifIndex = 0; ifIndex < 256; ifIndex += 1 {
for ifIndex = 0; ifIndex < 256; ifIndex++ {
tunfile, err = os.OpenFile(fmt.Sprintf("/dev/tun%d", ifIndex), unix.O_RDWR, 0)
if err == nil || !errors.Is(err, syscall.EBUSY) {
break
@ -175,7 +160,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if err == nil && name == "tun" {
fname := os.Getenv("WG_TUN_NAME_FILE")
if fname != "" {
ioutil.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0400)
os.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0o400)
}
}
@ -315,7 +300,6 @@ func (tun *NativeTun) setMTU(n int) error {
unix.SOCK_DGRAM,
0,
)
if err != nil {
return err
}
@ -350,7 +334,6 @@ func (tun *NativeTun) MTU() (int, error) {
unix.SOCK_DGRAM,
0,
)
if err != nil {
return 0, err
}