From 8cf14bb67e51cf47da4fbc6ae14d35aa2f9532fa Mon Sep 17 00:00:00 2001 From: PuerNya Date: Mon, 18 Dec 2023 14:51:36 +0800 Subject: [PATCH] chore: reslove udp host after rule matching --- tunnel/tunnel.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 2454fd9a..64ae91bf 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -328,16 +328,6 @@ func handleUDPConn(packet C.PacketAdapter) { sniffer.Dispatcher.UDPSniff(packet) } - // local resolve UDP dns - if !metadata.Resolved() { - ip, err := resolver.ResolveIP(context.Background(), metadata.Host) - if err != nil { - packet.Drop() - return - } - metadata.DstIP = ip - } - key := packet.LocalAddr().String() handle := func() bool { @@ -381,6 +371,16 @@ func handleUDPConn(packet C.PacketAdapter) { return } + // local resolve UDP dns + if !metadata.Resolved() && proxy.Type() != C.Reject && proxy.Type() != C.RejectDrop { + ip, err := resolver.ResolveIP(context.Background(), metadata.Host) + if err != nil { + packet.Drop() + return + } + metadata.DstIP = ip + } + ctx, cancel := context.WithTimeout(context.Background(), C.DefaultUDPTimeout) defer cancel() rawPc, err := retry(ctx, func(ctx context.Context) (C.PacketConn, error) {