summaryrefslogtreecommitdiffhomepage
path: root/tun
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2020-01-15 13:39:37 -0500
committerJason A. Donenfeld <Jason@zx2c4.com>2020-01-15 13:39:37 -0500
commitcaebdfe9d05901230dd7c6b7569be2903fd8ac87 (patch)
treecbb90a15b8c7dc3b2cd06f46edf250faf688950e /tun
parent4fa2ea6a2dabad50eb5585d0a56c3a6966604fa6 (diff)
tun: darwin: ignore ENOMEM errors
Coauthored-by: Andrej Mihajlov <and@mullvad.net>
Diffstat (limited to 'tun')
-rw-r--r--tun/tun_darwin.go19
1 files changed, 18 insertions, 1 deletions
diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go
index 6d2e6dd..f19a7df 100644
--- a/tun/tun_darwin.go
+++ b/tun/tun_darwin.go
@@ -11,6 +11,7 @@ import (
"net"
"os"
"syscall"
+ "time"
"unsafe"
"golang.org/x/net/ipv6"
@@ -42,6 +43,22 @@ type NativeTun struct {
var sockaddrCtlSize uintptr = 32
+func retryInterfaceByIndex(index int) (iface *net.Interface, err error) {
+ for i := 0; i < 20; i++ {
+ iface, err = net.InterfaceByIndex(index)
+ if err != nil {
+ if opErr, ok := err.(*net.OpError); ok {
+ if syscallErr, ok := opErr.Err.(*os.SyscallError); ok && syscallErr.Err == syscall.ENOMEM {
+ time.Sleep(time.Duration(i) * time.Second / 3)
+ continue
+ }
+ }
+ }
+ return iface, err
+ }
+ return nil, err
+}
+
func (tun *NativeTun) routineRouteListener(tunIfindex int) {
var (
statusUp bool
@@ -74,7 +91,7 @@ func (tun *NativeTun) routineRouteListener(tunIfindex int) {
continue
}
- iface, err := net.InterfaceByIndex(ifindex)
+ iface, err := retryInterfaceByIndex(ifindex)
if err != nil {
tun.errors <- err
return