mirror of
https://github.com/XTLS/Xray-core.git
synced 2024-11-26 17:03:02 +00:00
Improve the response to UDP Associate in Socks5
This commit is contained in:
parent
7427a55ef1
commit
700966508f
@ -42,7 +42,7 @@ type ServerSession struct {
|
|||||||
config *ServerConfig
|
config *ServerConfig
|
||||||
address net.Address
|
address net.Address
|
||||||
port net.Port
|
port net.Port
|
||||||
clientAddress net.Address
|
localAddress net.Address
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer) (*protocol.RequestHeader, error) {
|
func (s *ServerSession) handshake4(cmd byte, reader io.Reader, writer io.Writer) (*protocol.RequestHeader, error) {
|
||||||
@ -192,14 +192,11 @@ func (s *ServerSession) handshake5(nMethod byte, reader io.Reader, writer io.Wri
|
|||||||
//nolint:gocritic // Use if else chain for clarity
|
//nolint:gocritic // Use if else chain for clarity
|
||||||
if request.Command == protocol.RequestCommandUDP {
|
if request.Command == protocol.RequestCommandUDP {
|
||||||
if s.config.Address != nil {
|
if s.config.Address != nil {
|
||||||
// Use configured IP as remote address in the response to UdpAssociate
|
// Use configured IP as remote address in the response to UDP Associate
|
||||||
responseAddress = s.config.Address.AsAddress()
|
responseAddress = s.config.Address.AsAddress()
|
||||||
} else if s.clientAddress == net.LocalHostIP || s.clientAddress == net.LocalHostIPv6 {
|
|
||||||
// For localhost clients use loopback IP
|
|
||||||
responseAddress = s.clientAddress
|
|
||||||
} else {
|
} else {
|
||||||
// For non-localhost clients use inbound listening address
|
// Use conn.LocalAddr() IP as remote address in the response by default
|
||||||
responseAddress = s.address
|
responseAddress = s.localAddress
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := writeSocks5Response(writer, statusSuccess, responseAddress, responsePort); err != nil {
|
if err := writeSocks5Response(writer, statusSuccess, responseAddress, responsePort); err != nil {
|
||||||
|
@ -92,7 +92,7 @@ func (s *Server) processTCP(ctx context.Context, conn internet.Connection, dispa
|
|||||||
config: s.config,
|
config: s.config,
|
||||||
address: inbound.Gateway.Address,
|
address: inbound.Gateway.Address,
|
||||||
port: inbound.Gateway.Port,
|
port: inbound.Gateway.Port,
|
||||||
clientAddress: inbound.Source.Address,
|
localAddress: net.IPAddress(conn.LocalAddr().(*net.TCPAddr).IP),
|
||||||
}
|
}
|
||||||
|
|
||||||
reader := &buf.BufferedReader{Reader: buf.NewReader(conn)}
|
reader := &buf.BufferedReader{Reader: buf.NewReader(conn)}
|
||||||
|
Loading…
Reference in New Issue
Block a user