mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 03:51:31 +00:00
Fix DNS routing
This commit is contained in:
parent
9078bc2de5
commit
4801b6f057
|
@ -77,12 +77,9 @@ func (d *DNS) handleConnection(ctx context.Context, conn net.Conn, metadata adap
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(message.Questions) > 0 {
|
metadataInQuery := metadata
|
||||||
question := message.Questions[0]
|
|
||||||
metadata.Domain = string(question.Name.Data[:question.Name.Length-1])
|
|
||||||
}
|
|
||||||
go func() error {
|
go func() error {
|
||||||
response, err := d.router.Exchange(ctx, &message)
|
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -125,13 +122,10 @@ func (d *DNS) NewPacketConnection(ctx context.Context, conn N.PacketConn, metada
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if len(message.Questions) > 0 {
|
|
||||||
question := message.Questions[0]
|
|
||||||
metadata.Domain = string(question.Name.Data[:question.Name.Length-1])
|
|
||||||
}
|
|
||||||
timeout.Update()
|
timeout.Update()
|
||||||
|
metadataInQuery := metadata
|
||||||
go func() error {
|
go func() error {
|
||||||
response, err := d.router.Exchange(ctx, &message)
|
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,6 +52,7 @@ func (r *Router) Exchange(ctx context.Context, message *dnsmessage.Message) (*dn
|
||||||
case dnsmessage.TypeAAAA:
|
case dnsmessage.TypeAAAA:
|
||||||
metadata.IPVersion = 6
|
metadata.IPVersion = 6
|
||||||
}
|
}
|
||||||
|
metadata.Domain = string(message.Questions[0].Name.Data[:message.Questions[0].Name.Length-1])
|
||||||
}
|
}
|
||||||
ctx, transport, strategy := r.matchDNS(ctx)
|
ctx, transport, strategy := r.matchDNS(ctx)
|
||||||
ctx, cancel := context.WithTimeout(ctx, C.DNSTimeout)
|
ctx, cancel := context.WithTimeout(ctx, C.DNSTimeout)
|
||||||
|
@ -68,6 +69,8 @@ func (r *Router) Exchange(ctx context.Context, message *dnsmessage.Message) (*dn
|
||||||
|
|
||||||
func (r *Router) Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error) {
|
func (r *Router) Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error) {
|
||||||
r.dnsLogger.DebugContext(ctx, "lookup domain ", domain)
|
r.dnsLogger.DebugContext(ctx, "lookup domain ", domain)
|
||||||
|
ctx, metadata := adapter.AppendContext(ctx)
|
||||||
|
metadata.Domain = domain
|
||||||
ctx, transport, transportStrategy := r.matchDNS(ctx)
|
ctx, transport, transportStrategy := r.matchDNS(ctx)
|
||||||
if strategy == dns.DomainStrategyAsIS {
|
if strategy == dns.DomainStrategyAsIS {
|
||||||
strategy = transportStrategy
|
strategy = transportStrategy
|
||||||
|
|
Loading…
Reference in a new issue