mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 03:51:31 +00:00
Fix DNS outbound
This commit is contained in:
parent
3741394269
commit
bd54608473
|
@ -119,30 +119,47 @@ func (d *DNS) NewPacketConnection(ctx context.Context, conn N.PacketConn, metada
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx = adapter.WithContext(ctx, &metadata)
|
ctx = adapter.WithContext(ctx, &metadata)
|
||||||
fastClose, cancel := common.ContextWithCancelCause(ctx)
|
fastClose, cancel := common.ContextWithCancelCause(ctx)
|
||||||
timeout := canceler.New(fastClose, cancel, C.DNSTimeout)
|
timeout := canceler.New(fastClose, cancel, C.DNSTimeout)
|
||||||
var group task.Group
|
var group task.Group
|
||||||
group.Append0(func(ctx context.Context) error {
|
group.Append0(func(ctx context.Context) error {
|
||||||
_buffer := buf.StackNewSize(dns.FixedPacketSize)
|
|
||||||
defer common.KeepAlive(_buffer)
|
|
||||||
buffer := common.Dup(_buffer)
|
|
||||||
defer buffer.Release()
|
|
||||||
for {
|
for {
|
||||||
buffer.FullReset()
|
|
||||||
destination, err := conn.ReadPacket(buffer)
|
|
||||||
if err != nil {
|
|
||||||
cancel(err)
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var message mDNS.Msg
|
var message mDNS.Msg
|
||||||
err = message.Unpack(buffer.Bytes())
|
var destination M.Socksaddr
|
||||||
if err != nil {
|
var err error
|
||||||
cancel(err)
|
if len(cachedPackets) > 0 {
|
||||||
return err
|
packet := cachedPackets[0]
|
||||||
|
cachedPackets = cachedPackets[1:]
|
||||||
|
for _, counter := range counters {
|
||||||
|
counter(int64(packet.Buffer.Len()))
|
||||||
|
}
|
||||||
|
err = message.Unpack(packet.Buffer.Bytes())
|
||||||
|
packet.Buffer.Release()
|
||||||
|
if err != nil {
|
||||||
|
cancel(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
destination = packet.Destination
|
||||||
|
} else {
|
||||||
|
buffer := buf.NewPacket()
|
||||||
|
destination, err = conn.ReadPacket(buffer)
|
||||||
|
if err != nil {
|
||||||
|
buffer.Release()
|
||||||
|
cancel(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
for _, counter := range counters {
|
||||||
|
counter(int64(buffer.Len()))
|
||||||
|
}
|
||||||
|
err = message.Unpack(buffer.Bytes())
|
||||||
|
buffer.Release()
|
||||||
|
if err != nil {
|
||||||
|
cancel(err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
timeout.Update()
|
||||||
}
|
}
|
||||||
timeout.Update()
|
|
||||||
metadataInQuery := metadata
|
metadataInQuery := metadata
|
||||||
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)
|
||||||
|
|
Loading…
Reference in a new issue