mirror of
https://github.com/MetaCubeX/mihomo.git
synced 2025-12-23 19:30:09 +08:00
fix: better unprivileged ping handle
This commit is contained in:
parent
75c730bbc3
commit
268fe30aba
2
go.mod
2
go.mod
@ -30,7 +30,7 @@ require (
|
|||||||
github.com/metacubex/sing-shadowsocks v0.2.12
|
github.com/metacubex/sing-shadowsocks v0.2.12
|
||||||
github.com/metacubex/sing-shadowsocks2 v0.2.6
|
github.com/metacubex/sing-shadowsocks2 v0.2.6
|
||||||
github.com/metacubex/sing-shadowtls v0.0.0-20250503063515-5d9f966d17a2
|
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-vmess v0.2.4-0.20250822020810-4856053566f0
|
||||||
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f
|
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f
|
||||||
github.com/metacubex/smux v0.0.0-20250503055512-501391591dee
|
github.com/metacubex/smux v0.0.0-20250503055512-501391591dee
|
||||||
|
|||||||
4
go.sum
4
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-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 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-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.20250824112656-4a76abfeb316 h1:j4b/gmoPf5Wg/V6a+IVzMa3xo8ROwWDVKeRQYOGu8ZI=
|
||||||
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/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 h1:WZepq4TOZa6WewB8tGAZrrL+bL2R2ivoBzuEgAeolWc=
|
||||||
github.com/metacubex/sing-vmess v0.2.4-0.20250822020810-4856053566f0/go.mod h1:21R5R1u90uUvBQF0owoooEu96/SAYYD56nDrwm6nFaM=
|
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=
|
github.com/metacubex/sing-wireguard v0.0.0-20250503063753-2dc62acc626f h1:Sr/DYKYofKHKc4GF3qkRGNuj6XA6c0eqPgEDN+VAsYU=
|
||||||
|
|||||||
@ -2,8 +2,10 @@ package sing_tun
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/metacubex/mihomo/component/dialer"
|
"github.com/metacubex/mihomo/component/dialer"
|
||||||
|
"github.com/metacubex/mihomo/component/resolver"
|
||||||
"github.com/metacubex/mihomo/log"
|
"github.com/metacubex/mihomo/log"
|
||||||
|
|
||||||
tun "github.com/metacubex/sing-tun"
|
tun "github.com/metacubex/sing-tun"
|
||||||
@ -12,11 +14,15 @@ import (
|
|||||||
N "github.com/metacubex/sing/common/network"
|
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 {
|
switch network {
|
||||||
case N.NetworkICMPv4, N.NetworkICMPv6: // our fork only send those type to PrepareConnection now
|
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)
|
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 {
|
if err != nil {
|
||||||
log.Warnln("[ICMP] failed to connect to %s", destination)
|
log.Warnln("[ICMP] failed to connect to %s", destination)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user