From 0f363d2ba4fcddd92ea51175ea4471a0938756f4 Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Mon, 6 Oct 2025 18:09:35 +0330 Subject: [PATCH 1/2] Router: Use built-in-dns only once for all rules(in "IPOnDemand"/"IPIfNonMatch" mode) --- features/routing/dns/context.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/features/routing/dns/context.go b/features/routing/dns/context.go index a65895f6b29d..1693a27e6a71 100644 --- a/features/routing/dns/context.go +++ b/features/routing/dns/context.go @@ -14,14 +14,24 @@ type ResolvableContext struct { routing.Context dnsClient dns.Client resolvedIPs []net.IP + hasError bool } // GetTargetIPs overrides original routing.Context's implementation. func (ctx *ResolvableContext) GetTargetIPs() []net.IP { + + if ips := ctx.Context.GetTargetIPs(); len(ips) != 0 { + return ips + } + if len(ctx.resolvedIPs) > 0 { return ctx.resolvedIPs } + if ctx.hasError { + return nil + } + if domain := ctx.GetTargetDomain(); len(domain) != 0 { ips, _, err := ctx.dnsClient.LookupIP(domain, dns.IPOption{ IPv4Enable: true, @@ -32,13 +42,10 @@ func (ctx *ResolvableContext) GetTargetIPs() []net.IP { ctx.resolvedIPs = ips return ips } + ctx.hasError = true errors.LogInfoInner(context.Background(), err, "resolve ip for ", domain) } - if ips := ctx.Context.GetTargetIPs(); len(ips) != 0 { - return ips - } - return nil } From ba1bc6daafcd329f9b9893969af90d7882da1927 Mon Sep 17 00:00:00 2001 From: patterniha <71074308+patterniha@users.noreply.github.com> Date: Mon, 6 Oct 2025 19:07:41 +0330 Subject: [PATCH 2/2] fix --- features/routing/dns/context.go | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/features/routing/dns/context.go b/features/routing/dns/context.go index 1693a27e6a71..2cf9d2616616 100644 --- a/features/routing/dns/context.go +++ b/features/routing/dns/context.go @@ -12,20 +12,15 @@ import ( // ResolvableContext is an implementation of routing.Context, with domain resolving capability. type ResolvableContext struct { routing.Context - dnsClient dns.Client - resolvedIPs []net.IP - hasError bool + dnsClient dns.Client + cacheIPs []net.IP + hasError bool } // GetTargetIPs overrides original routing.Context's implementation. func (ctx *ResolvableContext) GetTargetIPs() []net.IP { - - if ips := ctx.Context.GetTargetIPs(); len(ips) != 0 { - return ips - } - - if len(ctx.resolvedIPs) > 0 { - return ctx.resolvedIPs + if len(ctx.cacheIPs) > 0 { + return ctx.cacheIPs } if ctx.hasError { @@ -39,13 +34,18 @@ func (ctx *ResolvableContext) GetTargetIPs() []net.IP { FakeEnable: false, }) if err == nil { - ctx.resolvedIPs = ips + ctx.cacheIPs = ips return ips } - ctx.hasError = true errors.LogInfoInner(context.Background(), err, "resolve ip for ", domain) } + if ips := ctx.Context.GetTargetIPs(); len(ips) != 0 { + ctx.cacheIPs = ips + return ips + } + + ctx.hasError = true return nil }