Fix response fakeip when routing

This commit is contained in:
PuerNya 2023-10-16 02:02:09 +08:00
parent bc4545f2ef
commit b29e7e181b
3 changed files with 5 additions and 1 deletions

View File

@ -47,6 +47,7 @@ type InboundContext struct {
GeoIPCode string GeoIPCode string
ProcessInfo *process.Info ProcessInfo *process.Info
FakeIP bool FakeIP bool
IsFromDnsOutbound bool
// dns cache // dns cache

View File

@ -77,6 +77,7 @@ func (d *DNS) handleConnection(ctx context.Context, conn net.Conn, metadata adap
return err return err
} }
metadataInQuery := metadata metadataInQuery := metadata
metadataInQuery.IsFromDnsOutbound = true
go func() error { go func() error {
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message) response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
if err != nil { if err != nil {
@ -157,6 +158,7 @@ func (d *DNS) NewPacketConnection(ctx context.Context, conn N.PacketConn, metada
timeout.Update() timeout.Update()
} }
metadataInQuery := metadata metadataInQuery := metadata
metadataInQuery.IsFromDnsOutbound = true
go func() error { go func() error {
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message) response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
if err != nil { if err != nil {
@ -235,6 +237,7 @@ func (d *DNS) newPacketConnection(ctx context.Context, conn N.PacketConn, readWa
timeout.Update() timeout.Update()
} }
metadataInQuery := metadata metadataInQuery := metadata
metadataInQuery.IsFromDnsOutbound = true
go func() error { go func() error {
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message) response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
if err != nil { if err != nil {

View File

@ -50,7 +50,7 @@ func (r *Router) matchDNS(ctx context.Context) (context.Context, dns.Transport,
r.dnsLogger.ErrorContext(ctx, "transport not found: ", detour) r.dnsLogger.ErrorContext(ctx, "transport not found: ", detour)
continue continue
} }
if _, isFakeIP := transport.(adapter.FakeIPTransport); isFakeIP && metadata.FakeIP { if _, isFakeIP := transport.(adapter.FakeIPTransport); isFakeIP && !metadata.IsFromDnsOutbound {
continue continue
} }
r.dnsLogger.DebugContext(ctx, "match[", i, "] ", rule.String(), " => ", detour) r.dnsLogger.DebugContext(ctx, "match[", i, "] ", rule.String(), " => ", detour)