From 1c33bc9b83f5734c492051e93ca9f896bede85e6 Mon Sep 17 00:00:00 2001 From: "metre.ye" Date: Tue, 9 Jul 2024 11:21:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0UDP=E7=9A=84IP4P=E6=94=AF?= =?UTF-8?q?=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- adapter/outbound/util.go | 5 +++++ component/dialer/dialer.go | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/adapter/outbound/util.go b/adapter/outbound/util.go index 2c85c7c8..c2891021 100644 --- a/adapter/outbound/util.go +++ b/adapter/outbound/util.go @@ -11,6 +11,7 @@ import ( "strconv" "sync" + "github.com/metacubex/mihomo/component/dialer" "github.com/metacubex/mihomo/component/resolver" C "github.com/metacubex/mihomo/constant" "github.com/metacubex/mihomo/transport/socks5" @@ -108,6 +109,10 @@ func resolveUDPAddrWithPrefer(ctx context.Context, network, address string, pref } } + if ip.Is6() && dialer.IP4PEnable { + ip, port = dialer.LookupIP4P(ip, port) + } + if !ip.IsValid() && fallback.IsValid() { ip = fallback } diff --git a/component/dialer/dialer.go b/component/dialer/dialer.go index 54a1aa6a..68ff346c 100644 --- a/component/dialer/dialer.go +++ b/component/dialer/dialer.go @@ -408,3 +408,7 @@ func lookupIP4P(addr netip.Addr, port string) (netip.Addr, string) { } return addr, port } + +func LookupIP4P(addr netip.Addr, port string) (netip.Addr, string) { + return lookupIP4P(addr, port) +}