From 12170b03956230975cd7f542b79f6eb3ccc8a809 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 2 May 2022 06:27:45 +0800 Subject: [PATCH] fix trojan and snell's normal udp --- adapter/outbound/snell.go | 8 +++++++- adapter/outbound/trojan.go | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/adapter/outbound/snell.go b/adapter/outbound/snell.go index 92343055..7b272d5d 100644 --- a/adapter/outbound/snell.go +++ b/adapter/outbound/snell.go @@ -99,7 +99,13 @@ func (s *Snell) ListenPacketContext(ctx context.Context, metadata *C.Metadata, o tcpKeepAlive(c) c = streamConn(c, streamOption{s.psk, s.version, s.addr, s.obfsOption}) - return s.ListenPacketOnStreamConn(c, metadata) + err = snell.WriteUDPHeader(c, s.version) + if err != nil { + return nil, err + } + + pc := snell.PacketConn(c) + return newPacketConn(pc, s), nil } // ListenPacketOnStreamConn implements C.ProxyAdapter diff --git a/adapter/outbound/trojan.go b/adapter/outbound/trojan.go index 46586673..31811c51 100644 --- a/adapter/outbound/trojan.go +++ b/adapter/outbound/trojan.go @@ -161,7 +161,13 @@ func (t *Trojan) ListenPacketContext(ctx context.Context, metadata *C.Metadata, } } - return t.ListenPacketOnStreamConn(c, metadata) + err = t.instance.WriteHeader(c, trojan.CommandUDP, serializesSocksAddr(metadata)) + if err != nil { + return nil, err + } + + pc := t.instance.PacketConn(c) + return newPacketConn(pc, t), err } // ListenPacketOnStreamConn implements C.ProxyAdapter