diff --git a/adapter/inbound.go b/adapter/inbound.go index 6a566dc2..59816cce 100644 --- a/adapter/inbound.go +++ b/adapter/inbound.go @@ -47,6 +47,7 @@ type InboundContext struct { GeoIPCode string ProcessInfo *process.Info FakeIP bool + IsFromDnsOutbound bool // dns cache diff --git a/outbound/dns.go b/outbound/dns.go index 3b2ad5e3..78f810f1 100644 --- a/outbound/dns.go +++ b/outbound/dns.go @@ -77,6 +77,7 @@ func (d *DNS) handleConnection(ctx context.Context, conn net.Conn, metadata adap return err } metadataInQuery := metadata + metadataInQuery.IsFromDnsOutbound = true go func() error { response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message) if err != nil { @@ -157,6 +158,7 @@ func (d *DNS) NewPacketConnection(ctx context.Context, conn N.PacketConn, metada timeout.Update() } metadataInQuery := metadata + metadataInQuery.IsFromDnsOutbound = true go func() error { response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message) if err != nil { @@ -235,6 +237,7 @@ func (d *DNS) newPacketConnection(ctx context.Context, conn N.PacketConn, readWa timeout.Update() } metadataInQuery := metadata + metadataInQuery.IsFromDnsOutbound = true go func() error { response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message) if err != nil { diff --git a/route/router_dns.go b/route/router_dns.go index 1532df94..e6228258 100644 --- a/route/router_dns.go +++ b/route/router_dns.go @@ -50,7 +50,7 @@ func (r *Router) matchDNS(ctx context.Context) (context.Context, dns.Transport, r.dnsLogger.ErrorContext(ctx, "transport not found: ", detour) continue } - if _, isFakeIP := transport.(adapter.FakeIPTransport); isFakeIP && metadata.FakeIP { + if _, isFakeIP := transport.(adapter.FakeIPTransport); isFakeIP && !metadata.IsFromDnsOutbound { continue } r.dnsLogger.DebugContext(ctx, "match[", i, "] ", rule.String(), " => ", detour)