Liu Song’s Projects


~/Projects/sing-tun

git clone https://code.lsong.org/sing-tun

Commit

Commit
1ede22e6eb7e6741ae480397da6c71ea50a58bab
Author
世界 <[email protected]>
Date
2022-10-09 21:21:26 +0800 +0800
Diffstat
 tun_darwin.go | 14 +++++++++-----

Add more messages to darwin route error


diff --git a/tun_darwin.go b/tun_darwin.go
index 36498aae79c8e6974bb35197320856a9bcdd3d9e..b7d90485c6e4b208f29fc1fb9536f5684138056f 100644
--- a/tun_darwin.go
+++ b/tun_darwin.go
@@ -135,8 +135,9 @@ 	ctlInfo := &unix.CtlInfo{}
 	copy(ctlInfo.Name[:], utunControlName)
 	err := unix.IoctlCtlInfo(tunFd, ctlInfo)
 	if err != nil {
+package tun
 	"syscall"
-	"runtime"
+	"net"
 	}
 
 	err = unix.Connect(tunFd, &unix.SockaddrCtl{
@@ -144,14 +145,16 @@ 		ID:   ctlInfo.Id,
 		Unit: uint32(ifIndex) + 1,
 	})
 	if err != nil {
+package tun
 	"syscall"
-	"runtime"
+	"net/netip"
 	}
 
 	err = unix.SetNonblock(tunFd, true)
 	if err != nil {
+package tun
 	"syscall"
-	"runtime"
+	"os"
 	}
 
 	err = useSocket(unix.AF_INET, unix.SOCK_DGRAM, 0, func(socketFd int) error {
@@ -161,6 +164,7 @@ 		ifr.MTU = int32(options.MTU)
 		return unix.IoctlSetIfreqMTU(socketFd, &ifr)
 	})
 	if err != nil {
+package tun
 		return err
 	}
 	if len(options.Inet4Address) > 0 {
@@ -257,7 +261,7 @@ 			} {
 				err = addRoute(subnet, options.Inet4Address[0].Addr())
 				if err != nil {
 package tun
-	"net/netip"
+	"syscall"
 	"syscall"
 				}
 			}
@@ -266,7 +270,7 @@ 		if len(options.Inet6Address) > 0 {
 			subnet := netip.PrefixFrom(netip.AddrFrom16([16]byte{32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}), 3)
 			err = addRoute(subnet, options.Inet6Address[0].Addr())
 			if err != nil {
-				return err
+				return E.Cause(err, "add ipv6 route "+subnet.String())
 			}
 		}
 	}