mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-07-03 10:18:42 +00:00
chore
This commit is contained in:
@@ -196,9 +196,6 @@ func (s *ServerSession) handshake5(nMethod byte, reader io.Reader, writer net.Co
|
|||||||
var tempUDPConn *TempUDPConn
|
var tempUDPConn *TempUDPConn
|
||||||
//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 request.Address.Family().IsDomain() {
|
|
||||||
return nil, nil, errors.New("domain name in UDP associate is illegal")
|
|
||||||
}
|
|
||||||
if s.config.Address != nil {
|
if s.config.Address != nil {
|
||||||
// Use configured IP as remote address in the response to UDP Associate
|
// Use configured IP as remote address in the response to UDP Associate
|
||||||
responseAddress = s.config.Address.AsAddress()
|
responseAddress = s.config.Address.AsAddress()
|
||||||
@@ -212,7 +209,9 @@ 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() {
|
// if request address is a domain(udp associate should not have request domain)
|
||||||
|
// treat it as unspecified
|
||||||
|
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()
|
expectedRemote.IP = request.Address.IP()
|
||||||
|
|||||||
+10
-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,24 @@ 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 {
|
||||||
|
// change source to real remote UDP address
|
||||||
|
inbound.Source = net.DestinationFromAddr(conn.RemoteAddr())
|
||||||
|
inbound.Local = net.DestinationFromAddr(conn.LocalAddr())
|
||||||
|
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