From b183183fbc45e9bc8a78c666903c36c94b2f0a63 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Thu, 8 Jun 2023 15:57:51 +0800 Subject: [PATCH] fix: Disable XUDP global ID if source address invalid --- adapter/outbound/vless.go | 6 +++++- adapter/outbound/vmess.go | 8 ++++++-- constant/metadata.go | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/adapter/outbound/vless.go b/adapter/outbound/vless.go index 558342d5..325ccccd 100644 --- a/adapter/outbound/vless.go +++ b/adapter/outbound/vless.go @@ -374,9 +374,13 @@ func (v *Vless) ListenPacketOnStreamConn(ctx context.Context, c net.Conn, metada } if v.option.XUDP { + var globalID [8]byte + if metadata.SourceValid() { + globalID = utils.GlobalID(metadata.SourceAddress()) + } return newPacketConn(N.NewThreadSafePacketConn( vmessSing.NewXUDPConn(c, - utils.GlobalID(metadata.SourceAddress()), + globalID, M.SocksaddrFromNet(metadata.UDPAddr())), ), v), nil } else if v.option.PacketAddr { diff --git a/adapter/outbound/vmess.go b/adapter/outbound/vmess.go index 0a75aa1a..e9409aa4 100644 --- a/adapter/outbound/vmess.go +++ b/adapter/outbound/vmess.go @@ -224,13 +224,17 @@ func (v *Vmess) StreamConnContext(ctx context.Context, c net.Conn, metadata *C.M func (v *Vmess) streamConn(c net.Conn, metadata *C.Metadata) (conn net.Conn, err error) { if metadata.NetWork == C.UDP { if v.option.XUDP { + var globalID [8]byte + if metadata.SourceValid() { + globalID = utils.GlobalID(metadata.SourceAddress()) + } if N.NeedHandshake(c) { conn = v.client.DialEarlyXUDPPacketConn(c, - utils.GlobalID(metadata.SourceAddress()), + globalID, M.SocksaddrFromNet(metadata.UDPAddr())) } else { conn, err = v.client.DialXUDPPacketConn(c, - utils.GlobalID(metadata.SourceAddress()), + globalID, M.SocksaddrFromNet(metadata.UDPAddr())) } } else if v.option.PacketAddr { diff --git a/constant/metadata.go b/constant/metadata.go index edc58aec..de26a05f 100644 --- a/constant/metadata.go +++ b/constant/metadata.go @@ -171,6 +171,10 @@ func (m *Metadata) SourceDetail() string { } } +func (m *Metadata) SourceValid() bool { + return m.SrcPort != "" && m.SrcIP.IsValid() +} + func (m *Metadata) AddrType() int { switch true { case m.Host != "" || !m.DstIP.IsValid():