mirror of
https://github.com/XTLS/Xray-core.git
synced 2026-09-22 22:58:03 +03:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
447b4438ee | ||
|
|
1f925778ed | ||
|
|
06dee57f8a | ||
|
|
7f8928272b |
@@ -25,6 +25,7 @@ require (
|
|||||||
golang.org/x/net v0.48.0
|
golang.org/x/net v0.48.0
|
||||||
golang.org/x/sync v0.19.0
|
golang.org/x/sync v0.19.0
|
||||||
golang.org/x/sys v0.39.0
|
golang.org/x/sys v0.39.0
|
||||||
|
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2
|
||||||
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173
|
||||||
google.golang.org/grpc v1.78.0
|
google.golang.org/grpc v1.78.0
|
||||||
google.golang.org/protobuf v1.36.11
|
google.golang.org/protobuf v1.36.11
|
||||||
@@ -50,7 +51,6 @@ require (
|
|||||||
golang.org/x/text v0.32.0 // indirect
|
golang.org/x/text v0.32.0 // indirect
|
||||||
golang.org/x/time v0.12.0 // indirect
|
golang.org/x/time v0.12.0 // indirect
|
||||||
golang.org/x/tools v0.39.0 // indirect
|
golang.org/x/tools v0.39.0 // indirect
|
||||||
golang.zx2c4.com/wintun v0.0.0-20230126152724-0fa3db229ce2 // indirect
|
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20251029180050-ab9386a59fda // indirect
|
||||||
gopkg.in/yaml.v2 v2.4.0 // indirect
|
gopkg.in/yaml.v2 v2.4.0 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
goerrors "errors"
|
goerrors "errors"
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/xtls/xray-core/common"
|
"github.com/xtls/xray-core/common"
|
||||||
"github.com/xtls/xray-core/common/buf"
|
"github.com/xtls/xray-core/common/buf"
|
||||||
@@ -26,6 +27,7 @@ var nullDestination = net.TCPDestination(net.AnyIP, 0)
|
|||||||
type Server struct {
|
type Server struct {
|
||||||
bindServer *netBindServer
|
bindServer *netBindServer
|
||||||
|
|
||||||
|
infoMu sync.RWMutex
|
||||||
info routingInfo
|
info routingInfo
|
||||||
policyManager policy.Manager
|
policyManager policy.Manager
|
||||||
}
|
}
|
||||||
@@ -78,12 +80,14 @@ func (*Server) Network() []net.Network {
|
|||||||
|
|
||||||
// Process implements proxy.Inbound.
|
// Process implements proxy.Inbound.
|
||||||
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Connection, dispatcher routing.Dispatcher) error {
|
||||||
|
s.infoMu.Lock()
|
||||||
s.info = routingInfo{
|
s.info = routingInfo{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
dispatcher: dispatcher,
|
dispatcher: dispatcher,
|
||||||
inboundTag: session.InboundFromContext(ctx),
|
inboundTag: session.InboundFromContext(ctx),
|
||||||
contentTag: session.ContentFromContext(ctx),
|
contentTag: session.ContentFromContext(ctx),
|
||||||
}
|
}
|
||||||
|
s.infoMu.Unlock()
|
||||||
|
|
||||||
ep, err := s.bindServer.ParseEndpoint(conn.RemoteAddr().String())
|
ep, err := s.bindServer.ParseEndpoint(conn.RemoteAddr().String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -120,18 +124,23 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
||||||
if s.info.dispatcher == nil {
|
// Make a thread-safe copy of routing info
|
||||||
errors.LogError(s.info.ctx, "unexpected: dispatcher == nil")
|
s.infoMu.RLock()
|
||||||
|
info := s.info
|
||||||
|
s.infoMu.RUnlock()
|
||||||
|
|
||||||
|
if info.dispatcher == nil {
|
||||||
|
errors.LogError(info.ctx, "unexpected: dispatcher == nil")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer conn.Close()
|
defer conn.Close()
|
||||||
|
|
||||||
ctx, cancel := context.WithCancel(core.ToBackgroundDetachedContext(s.info.ctx))
|
ctx, cancel := context.WithCancel(core.ToBackgroundDetachedContext(info.ctx))
|
||||||
sid := session.NewID()
|
sid := session.NewID()
|
||||||
ctx = c.ContextWithID(ctx, sid)
|
ctx = c.ContextWithID(ctx, sid)
|
||||||
inbound := session.Inbound{} // since promiscuousModeHandler mixed-up context, we shallow copy inbound (tag) and content (configs)
|
inbound := session.Inbound{} // since promiscuousModeHandler mixed-up context, we shallow copy inbound (tag) and content (configs)
|
||||||
if s.info.inboundTag != nil {
|
if info.inboundTag != nil {
|
||||||
inbound = *s.info.inboundTag
|
inbound = *info.inboundTag
|
||||||
}
|
}
|
||||||
inbound.Name = "wireguard"
|
inbound.Name = "wireguard"
|
||||||
inbound.CanSpliceCopy = 3
|
inbound.CanSpliceCopy = 3
|
||||||
@@ -141,8 +150,8 @@ func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
|||||||
// Currently we have no way to link to the original source address
|
// Currently we have no way to link to the original source address
|
||||||
inbound.Source = net.DestinationFromAddr(conn.RemoteAddr())
|
inbound.Source = net.DestinationFromAddr(conn.RemoteAddr())
|
||||||
ctx = session.ContextWithInbound(ctx, &inbound)
|
ctx = session.ContextWithInbound(ctx, &inbound)
|
||||||
if s.info.contentTag != nil {
|
if info.contentTag != nil {
|
||||||
ctx = session.ContextWithContent(ctx, s.info.contentTag)
|
ctx = session.ContextWithContent(ctx, info.contentTag)
|
||||||
}
|
}
|
||||||
ctx = session.SubContextFromMuxInbound(ctx)
|
ctx = session.SubContextFromMuxInbound(ctx)
|
||||||
|
|
||||||
@@ -156,7 +165,16 @@ func (s *Server) forwardConnection(dest net.Destination, conn net.Conn) {
|
|||||||
Reason: "",
|
Reason: "",
|
||||||
})
|
})
|
||||||
|
|
||||||
link, err := s.info.dispatcher.Dispatch(ctx, dest)
|
// Set inbound and content tags from routing info for proper routing
|
||||||
|
// These were commented out in PR #4030 but are needed for domain-based routing
|
||||||
|
if info.inboundTag != nil {
|
||||||
|
ctx = session.ContextWithInbound(ctx, info.inboundTag)
|
||||||
|
}
|
||||||
|
if info.contentTag != nil {
|
||||||
|
ctx = session.ContextWithContent(ctx, info.contentTag)
|
||||||
|
}
|
||||||
|
|
||||||
|
link, err := info.dispatcher.Dispatch(ctx, dest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
errors.LogErrorInner(ctx, err, "dispatch connection")
|
errors.LogErrorInner(ctx, err, "dispatch connection")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user