mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-05 19:28:45 +00:00
Socks5 inbound: Fix issues in new UDP ASSOCIATE (#6325)
https://github.com/XTLS/Xray-core/pull/6325#issuecomment-4724008713 Fixes https://github.com/XTLS/Xray-core/issues/6323 --------- Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
@@ -209,11 +209,12 @@ func (s *ServerSession) handshake5(nMethod byte, reader io.Reader, writer net.Co
|
|||||||
}
|
}
|
||||||
responsePort = net.Port(udpHub.LocalAddr().(*net.UDPAddr).Port)
|
responsePort = net.Port(udpHub.LocalAddr().(*net.UDPAddr).Port)
|
||||||
expectedRemote := &gonet.UDPAddr{}
|
expectedRemote := &gonet.UDPAddr{}
|
||||||
if request.Address.IP().IsUnspecified() {
|
// UDP Associate should not specify a domain as source IP
|
||||||
|
if request.Address.Family().IsDomain() || request.Address.IP().IsUnspecified() {
|
||||||
expectedRemote.IP = writer.RemoteAddr().(*net.TCPAddr).IP // unix?
|
expectedRemote.IP = writer.RemoteAddr().(*net.TCPAddr).IP // unix?
|
||||||
} else {
|
} else {
|
||||||
expectedRemote.IP = request.Address.IP() // panic?
|
expectedRemote.IP = request.Address.IP()
|
||||||
expectedRemote.Port = int(request.Port) // 0 is allowed
|
expectedRemote.Port = int(request.Port) // 0 is allowed
|
||||||
}
|
}
|
||||||
tempUDPConn = NewTempUDPConn(udpHub, writer, expectedRemote)
|
tempUDPConn = NewTempUDPConn(udpHub, writer, expectedRemote)
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-3
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
goerrors "errors"
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
@@ -216,18 +217,27 @@ func (s *Server) handleUDPPayload(ctx context.Context, conn stat.Connection, dis
|
|||||||
defer udpServer.RemoveRay()
|
defer udpServer.RemoveRay()
|
||||||
|
|
||||||
inbound := session.InboundFromContext(ctx)
|
inbound := session.InboundFromContext(ctx)
|
||||||
if inbound != nil && inbound.Source.IsValid() {
|
|
||||||
errors.LogInfo(ctx, "client UDP connection from ", inbound.Source)
|
|
||||||
}
|
|
||||||
|
|
||||||
var dest *net.Destination
|
var dest *net.Destination
|
||||||
|
|
||||||
reader := buf.NewPacketReader(conn)
|
reader := buf.NewPacketReader(conn)
|
||||||
|
var changeRemote sync.Once
|
||||||
for {
|
for {
|
||||||
mpayload, err := reader.ReadMultiBuffer()
|
mpayload, err := reader.ReadMultiBuffer()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
changeRemote.Do(func() {
|
||||||
|
if inbound != nil {
|
||||||
|
newInbound := *inbound
|
||||||
|
// change source to real remote UDP address
|
||||||
|
newInbound.Source = net.DestinationFromAddr(conn.RemoteAddr())
|
||||||
|
newInbound.Local = net.DestinationFromAddr(conn.LocalAddr())
|
||||||
|
inbound = &newInbound
|
||||||
|
ctx = session.ContextWithInbound(ctx, inbound)
|
||||||
|
errors.LogInfo(ctx, "client UDP connection from ", inbound.Source)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
for _, payload := range mpayload {
|
for _, payload := range mpayload {
|
||||||
request, err := DecodeUDPPacket(payload)
|
request, err := DecodeUDPPacket(payload)
|
||||||
|
|||||||
Reference in New Issue
Block a user