mirror of
https://gitclone.com/github.com/MetaCubeX/Clash.Meta
synced 2025-02-24 05:02:14 +08:00
fix: udp nat handle
This commit is contained in:
parent
f16ebf9bfe
commit
9d8c3b0a3b
@ -342,29 +342,9 @@ func handleUDPConn(packet C.PacketAdapter) {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
if handle() {
|
|
||||||
packet.Drop()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
cond, loaded := natTable.GetOrCreateLock(key)
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer packet.Drop()
|
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)
|
proxy, rule, err := resolveMetadata(metadata)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnln("[UDP] Parse metadata failed: %s", err.Error())
|
log.Warnln("[UDP] Parse metadata failed: %s", err.Error())
|
||||||
@ -381,6 +361,25 @@ func handleUDPConn(packet C.PacketAdapter) {
|
|||||||
metadata.DstIP = ip
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), C.DefaultUDPTimeout)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
rawPc, err := retry(ctx, func(ctx context.Context) (C.PacketConn, error) {
|
rawPc, err := retry(ctx, func(ctx context.Context) (C.PacketConn, error) {
|
||||||
|
Loading…
Reference in New Issue
Block a user