From f08c72151967a6d8f00aeac0e29af3ca233492ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 1 Oct 2023 13:36:51 +0800 Subject: [PATCH] Update gVisor to 20230814.0 --- experimental/libbox/monitor.go | 11 +++++++++++ go.mod | 4 ++-- go.sum | 8 ++++---- route/router.go | 5 ++--- transport/wireguard/device_stack.go | 4 ++++ 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/experimental/libbox/monitor.go b/experimental/libbox/monitor.go index 1cd29139..575466c9 100644 --- a/experimental/libbox/monitor.go +++ b/experimental/libbox/monitor.go @@ -65,6 +65,17 @@ func (m *platformDefaultInterfaceMonitor) DefaultInterfaceIndex(destination neti return m.defaultInterfaceIndex } +func (m *platformDefaultInterfaceMonitor) DefaultInterface(destination netip.Addr) (string, int) { + for _, address := range m.networkAddresses { + for _, prefix := range address.addresses { + if prefix.Contains(destination) { + return address.interfaceName, address.interfaceIndex + } + } + } + return m.defaultInterfaceName, m.defaultInterfaceIndex +} + func (m *platformDefaultInterfaceMonitor) OverrideAndroidVPN() bool { return false } diff --git a/go.mod b/go.mod index eecbf0d5..4749954e 100644 --- a/go.mod +++ b/go.mod @@ -22,7 +22,7 @@ require ( github.com/oschwald/maxminddb-golang v1.12.0 github.com/sagernet/cloudflare-tls v0.0.0-20230829051644-4a68352d0c4a github.com/sagernet/gomobile v0.0.0-20230915142329-c6740b6d2950 - github.com/sagernet/gvisor v0.0.0-20230627031050-1ab0276e0dd2 + github.com/sagernet/gvisor v0.0.0-20230930141345-5fef6f2e17ab github.com/sagernet/quic-go v0.0.0-20230919101909-0cc6c5dcecee github.com/sagernet/reality v0.0.0-20230406110435-ee17307e7691 github.com/sagernet/sing v0.2.13-0.20231001070509-81a98bf16263 @@ -32,7 +32,7 @@ require ( github.com/sagernet/sing-shadowsocks v0.2.5 github.com/sagernet/sing-shadowsocks2 v0.1.4 github.com/sagernet/sing-shadowtls v0.1.4 - github.com/sagernet/sing-tun v0.1.14 + github.com/sagernet/sing-tun v0.1.15-0.20231003035000-3ae726d9f02b github.com/sagernet/sing-vmess v0.1.8 github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 github.com/sagernet/tfo-go v0.0.0-20230816093905-5a5c285d44a6 diff --git a/go.sum b/go.sum index ad12ecbf..f310fe94 100644 --- a/go.sum +++ b/go.sum @@ -98,8 +98,8 @@ github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61 h1:5+m7c github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61/go.mod h1:QUQ4RRHD6hGGHdFMEtR8T2P6GS6R3D/CXKdaYHKKXms= github.com/sagernet/gomobile v0.0.0-20230915142329-c6740b6d2950 h1:hUz/2mJLgi7l2H36JGpDY+jou9FmI6kAm0ZkU+xPpgE= github.com/sagernet/gomobile v0.0.0-20230915142329-c6740b6d2950/go.mod h1:5YE39YkJkCcMsfq1jMKkjsrM2GfBoF9JVWnvU89hmvU= -github.com/sagernet/gvisor v0.0.0-20230627031050-1ab0276e0dd2 h1:dnkKrzapqtAwjTSWt6hdPrARORfoYvuUczynvRLrueo= -github.com/sagernet/gvisor v0.0.0-20230627031050-1ab0276e0dd2/go.mod h1:1JUiV7nGuf++YFm9eWZ8q2lrwHmhcUGzptMl/vL1+LA= +github.com/sagernet/gvisor v0.0.0-20230930141345-5fef6f2e17ab h1:u+xQoi/Yc6bNUvTfrDD6HhGRybn2lzrhf5vmS+wb4Ho= +github.com/sagernet/gvisor v0.0.0-20230930141345-5fef6f2e17ab/go.mod h1:3akUhSHSVtLuJaYcW5JPepUraBOW06Ibz2HKwaK5rOk= github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97 h1:iL5gZI3uFp0X6EslacyapiRz7LLSJyr4RajF/BhMVyE= github.com/sagernet/netlink v0.0.0-20220905062125-8043b4a9aa97/go.mod h1:xLnfdiJbSp8rNqYEdIW/6eDO4mVoogml14Bh2hSiFpM= github.com/sagernet/quic-go v0.0.0-20230919101909-0cc6c5dcecee h1:ykuhl9jCS638N+jw1vC9AvT9bbQn6xRNScP2FWPV9dM= @@ -122,8 +122,8 @@ github.com/sagernet/sing-shadowsocks2 v0.1.4 h1:vht2M8t3m5DTgXR2j24KbYOygG5aOp+M github.com/sagernet/sing-shadowsocks2 v0.1.4/go.mod h1:Mgdee99NxxNd5Zld3ixIs18yVs4x2dI2VTDDE1N14Wc= github.com/sagernet/sing-shadowtls v0.1.4 h1:aTgBSJEgnumzFenPvc+kbD9/W0PywzWevnVpEx6Tw3k= github.com/sagernet/sing-shadowtls v0.1.4/go.mod h1:F8NBgsY5YN2beQavdgdm1DPlhaKQlaL6lpDdcBglGK4= -github.com/sagernet/sing-tun v0.1.14 h1:Vsval4r78kngCsZsz0FExT6p6akiUeRuiVXjfgnN3Ok= -github.com/sagernet/sing-tun v0.1.14/go.mod h1:Z2WibDUoQh/3wwFCfkIzIG0n/NlAlPuEbLTq3rD1aQY= +github.com/sagernet/sing-tun v0.1.15-0.20231003035000-3ae726d9f02b h1:lg4ddG9BaVVsLAx4972MefhLI7xYlTuE6q7SHK9nLfU= +github.com/sagernet/sing-tun v0.1.15-0.20231003035000-3ae726d9f02b/go.mod h1:D+13Yc2j9CJ/EP25hs0vHn4kgH9JVfe0PIpdZwIbYZs= github.com/sagernet/sing-vmess v0.1.8 h1:XVWad1RpTy9b5tPxdm5MCU8cGfrTGdR8qCq6HV2aCNc= github.com/sagernet/sing-vmess v0.1.8/go.mod h1:vhx32UNzTDUkNwOyIjcZQohre1CaytquC5mPplId8uA= github.com/sagernet/smux v0.0.0-20230312102458-337ec2a5af37 h1:HuE6xSwco/Xed8ajZ+coeYLmioq0Qp1/Z2zczFaV8as= diff --git a/route/router.go b/route/router.go index 9b302d5e..c1dc228d 100644 --- a/route/router.go +++ b/route/router.go @@ -920,9 +920,8 @@ func (r *Router) AutoDetectInterfaceFunc() control.Func { return control.BindToInterfaceFunc(r.InterfaceFinder(), func(network string, address string) (interfaceName string, interfaceIndex int, err error) { remoteAddr := M.ParseSocksaddr(address).Addr if C.IsLinux { - interfaceName = r.InterfaceMonitor().DefaultInterfaceName(remoteAddr) - interfaceIndex = -1 - if interfaceName == "" { + interfaceName, interfaceIndex = r.InterfaceMonitor().DefaultInterface(remoteAddr) + if interfaceIndex == -1 { err = tun.ErrNoRoute } } else { diff --git a/transport/wireguard/device_stack.go b/transport/wireguard/device_stack.go index 21599305..4ddaffe1 100644 --- a/transport/wireguard/device_stack.go +++ b/transport/wireguard/device_stack.go @@ -286,6 +286,10 @@ func (ep *wireEndpoint) ARPHardwareType() header.ARPHardwareType { func (ep *wireEndpoint) AddHeader(buffer stack.PacketBufferPtr) { } +func (ep *wireEndpoint) ParseHeader(ptr stack.PacketBufferPtr) bool { + return true +} + func (ep *wireEndpoint) WritePackets(list stack.PacketBufferList) (int, tcpip.Error) { for _, packetBuffer := range list.AsSlice() { packetBuffer.IncRef()