1
0

Fix: should always drop packet when handle UDP packet (#2659)

This commit is contained in:
yaling888 2023-04-05 14:05:23 +08:00 committed by GitHub
parent 4cd4912749
commit 95bbfe3945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -12,8 +12,6 @@ import (
) )
func handleUDPToRemote(packet C.UDPPacket, pc C.PacketConn, metadata *C.Metadata) error { func handleUDPToRemote(packet C.UDPPacket, pc C.PacketConn, metadata *C.Metadata) error {
defer packet.Drop()
addr := metadata.UDPAddr() addr := metadata.UDPAddr()
if addr == nil { if addr == nil {
return errors.New("udp addr invalid") return errors.New("udp addr invalid")

View File

@ -176,6 +176,7 @@ func resolveMetadata(ctx C.PlainContext, metadata *C.Metadata) (proxy C.Proxy, r
func handleUDPConn(packet *inbound.PacketAdapter) { func handleUDPConn(packet *inbound.PacketAdapter) {
metadata := packet.Metadata() metadata := packet.Metadata()
if !metadata.Valid() { if !metadata.Valid() {
packet.Drop()
log.Warnln("[Metadata] not valid: %#v", metadata) log.Warnln("[Metadata] not valid: %#v", metadata)
return return
} }
@ -188,6 +189,7 @@ func handleUDPConn(packet *inbound.PacketAdapter) {
} }
if err := preHandleMetadata(metadata); err != nil { if err := preHandleMetadata(metadata); err != nil {
packet.Drop()
log.Debugln("[Metadata PreHandle] error: %s", err) log.Debugln("[Metadata PreHandle] error: %s", err)
return return
} }
@ -196,8 +198,10 @@ func handleUDPConn(packet *inbound.PacketAdapter) {
if !metadata.Resolved() { if !metadata.Resolved() {
ips, err := resolver.LookupIP(context.Background(), metadata.Host) ips, err := resolver.LookupIP(context.Background(), metadata.Host)
if err != nil { if err != nil {
packet.Drop()
return return
} else if len(ips) == 0 { } else if len(ips) == 0 {
packet.Drop()
return return
} }
metadata.DstIP = ips[0] metadata.DstIP = ips[0]
@ -215,6 +219,7 @@ func handleUDPConn(packet *inbound.PacketAdapter) {
} }
if handle() { if handle() {
packet.Drop()
return return
} }
@ -222,6 +227,8 @@ func handleUDPConn(packet *inbound.PacketAdapter) {
cond, loaded := natTable.GetOrCreateLock(lockKey) cond, loaded := natTable.GetOrCreateLock(lockKey)
go func() { go func() {
defer packet.Drop()
if loaded { if loaded {
cond.L.Lock() cond.L.Lock()
cond.Wait() cond.Wait()