fix: udp nat handle

This commit is contained in:
PuerNya 2023-12-18 23:44:19 +08:00 committed by 汐殇
parent f16ebf9bfe
commit 9d8c3b0a3b

View File

@ -342,29 +342,9 @@ func handleUDPConn(packet C.PacketAdapter) {
return false
}
if handle() {
packet.Drop()
return
}
cond, loaded := natTable.GetOrCreateLock(key)
go func() {
defer packet.Drop()
if loaded {
cond.L.Lock()
cond.Wait()
handle()
cond.L.Unlock()
return
}
defer func() {
natTable.DeleteLock(key)
cond.Broadcast()
}()
proxy, rule, err := resolveMetadata(metadata)
if err != nil {
log.Warnln("[UDP] Parse metadata failed: %s", err.Error())
@ -381,6 +361,25 @@ func handleUDPConn(packet C.PacketAdapter) {
metadata.DstIP = ip
}
if handle() {
return
}
cond, loaded := natTable.GetOrCreateLock(key)
if loaded {
cond.L.Lock()
cond.Wait()
handle()
cond.L.Unlock()
return
}
defer func() {
natTable.DeleteLock(key)
cond.Broadcast()
}()
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultUDPTimeout)
defer cancel()
rawPc, err := retry(ctx, func(ctx context.Context) (C.PacketConn, error) {