From d48bcf1e1ed99b3c863184bd0eb093ebb8c2e890 Mon Sep 17 00:00:00 2001 From: wwqgtxx Date: Sun, 9 Nov 2025 19:12:44 +0800 Subject: [PATCH] fix: fakeip6 logic not work correctly --- dns/enhancer.go | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/dns/enhancer.go b/dns/enhancer.go index c84f8c32..7e349772 100644 --- a/dns/enhancer.go +++ b/dns/enhancer.go @@ -1,6 +1,7 @@ package dns import ( + "errors" "net/netip" "github.com/metacubex/mihomo/common/lru" @@ -31,11 +32,15 @@ func (h *ResolverEnhancer) IsExistFakeIP(ip netip.Addr) bool { } if pool := h.fakeIPPool; pool != nil { - return pool.Exist(ip) + if pool.Exist(ip) { + return true + } } if pool6 := h.fakeIPPool6; pool6 != nil { - return pool6.Exist(ip) + if pool6.Exist(ip) { + return true + } } return false @@ -47,11 +52,15 @@ func (h *ResolverEnhancer) IsFakeIP(ip netip.Addr) bool { } if pool := h.fakeIPPool; pool != nil { - return pool.IPNet().Contains(ip) && ip != pool.Gateway() && ip != pool.Broadcast() + if pool.IPNet().Contains(ip) && ip != pool.Gateway() && ip != pool.Broadcast() { + return true + } } if pool6 := h.fakeIPPool6; pool6 != nil { - return pool6.IPNet().Contains(ip) && ip != pool6.Gateway() && ip != pool6.Broadcast() + if pool6.IPNet().Contains(ip) && ip != pool6.Gateway() && ip != pool6.Broadcast() { + return true + } } return false @@ -63,11 +72,15 @@ func (h *ResolverEnhancer) IsFakeBroadcastIP(ip netip.Addr) bool { } if pool := h.fakeIPPool; pool != nil { - return pool.Broadcast() == ip + if pool.Broadcast() == ip { + return true + } } if pool6 := h.fakeIPPool6; pool6 != nil { - return pool6.Broadcast() == ip + if pool6.Broadcast() == ip { + return true + } } return false @@ -102,11 +115,19 @@ func (h *ResolverEnhancer) InsertHostByIP(ip netip.Addr, host string) { } func (h *ResolverEnhancer) FlushFakeIP() error { + var errs []error if pool := h.fakeIPPool; pool != nil { - return pool.FlushFakeIP() + if err := pool.FlushFakeIP(); err != nil { + errs = append(errs, err) + } } if pool6 := h.fakeIPPool6; pool6 != nil { - return pool6.FlushFakeIP() + if err := pool6.FlushFakeIP(); err != nil { + errs = append(errs, err) + } + } + if len(errs) > 0 { + return errors.Join(errs...) } return nil }