From 268fe30aba02cbe2064aca2f489e03aee022ce9a Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sun, 24 Aug 2025 19:28:39 +0800 Subject: [PATCH] fix: better unprivileged ping handle --- go.mod | 2 +- go.sum | 4 ++-- listener/sing_tun/prepare.go | 10 ++++++++-- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/go.mod b/go.mod index 55d30c9a..3e031d23 100644 --- a/go.mod +++ b/go.mod @@ -30,7 +30,7 @@ require ( github.com/metacubex/sing-shadowsocks v0.2.12 github.com/metacubex/sing-shadowsocks2 v0.2.6 github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 - github.com/metacubex/sing-tun v0.4.8-0.20250824074636-ed85839886a2 + github.com/metacubex/sing-tun v0.4.8-0.20250824112656-4a76abfeb316 github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0 github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f github.com/metacubex/smux v0.0.0-20250503055512-501391591dee diff --git a/go.sum b/go.sum index 4bc88f0e..90b232e0 100644 --- a/go.sum +++ b/go.sum @@ -129,8 +129,8 @@ github.com/metacubex/sing-shadowsocks2 v0.2.6 h1:ZR1kYT0f0Vi64iQSS09OdhFfppiNkh7 github.com/metacubex/sing-shadowsocks2 v0.2.6/go.mod h1:vOEbfKC60txi0ca+yUlqEwOGc3Obl6cnSgx9Gf45KjE= github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2 h1:gXU+MYPm7Wme3/OAY2FFzVq9d9GxPHOqu5AQfg/ddhI= github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2/go.mod h1:mbfboaXauKJNIHJYxQRa+NJs4JU9NZfkA+I33dS2+9E= -github.com/metacubex/sing-tun v0.4.8-0.20250824074636-ed85839886a2 h1:pW5e0yVRGInQnG25xgVW6VSbFRV9OBpPbAr7BhLPhJg= -github.com/metacubex/sing-tun v0.4.8-0.20250824074636-ed85839886a2/go.mod h1:/i53ifwthzZaUrhyxgrR/ihQDjoEgfJf+TJ0FivBtdI= +github.com/metacubex/sing-tun v0.4.8-0.20250824112656-4a76abfeb316 h1:j4b/gmoPf5Wg/V6a+IVzMa3xo8ROwWDVKeRQYOGu8ZI= +github.com/metacubex/sing-tun v0.4.8-0.20250824112656-4a76abfeb316/go.mod h1:/i53ifwthzZaUrhyxgrR/ihQDjoEgfJf+TJ0FivBtdI= github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0 h1:WZepq4TOZa6WewB8tGAZrrL+bL2R2ivoBzuEgAeolWc= github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0/go.mod h1:21R5R1u90uUvBQF0owoooEu96/SAYYD56nDrwm6nFaM= github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f h1:Sr/DYKYofKHKc4GF3qkRGNuj6XA6c0eqPgEDN+VAsYU= diff --git a/listener/sing_tun/prepare.go b/listener/sing_tun/prepare.go index d94d5e2b..0ee3eb37 100644 --- a/listener/sing_tun/prepare.go +++ b/listener/sing_tun/prepare.go @@ -2,8 +2,10 @@ package sing_tun import ( "context" + "time" "github.com/metacubex/mihomo/component/dialer" + "github.com/metacubex/mihomo/component/resolver" "github.com/metacubex/mihomo/log" tun "github.com/metacubex/sing-tun" @@ -12,11 +14,15 @@ import ( N "github.com/metacubex/sing/common/network" ) -func (h *ListenerHandler) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr, routeContext tun.DirectRouteContext) (tun.DirectRouteDestination, error) { +func (h *ListenerHandler) PrepareConnection(network string, source M.Socksaddr, destination M.Socksaddr, routeContext tun.DirectRouteContext, timeout time.Duration) (tun.DirectRouteDestination, error) { switch network { case N.NetworkICMPv4, N.NetworkICMPv6: // our fork only send those type to PrepareConnection now + if resolver.IsFakeIP(destination.Addr) { // skip fakeip + log.Infoln("[ICMP] %s %s --> %s using fake ping echo", network, source, destination) + return nil, nil + } log.Infoln("[ICMP] %s %s --> %s using DIRECT", network, source, destination) - directRouteDestination, err := ping.ConnectDestination(context.TODO(), log.SingLogger, dialer.ICMPControl(destination.Addr), destination.Addr, routeContext) + directRouteDestination, err := ping.ConnectDestination(context.TODO(), log.SingLogger, dialer.ICMPControl(destination.Addr), destination.Addr, routeContext, timeout) if err != nil { log.Warnln("[ICMP] failed to connect to %s", destination) return nil, err