mirror of https://github.com/v2ray/v2ray-core
support tproxy in tcp connections
parent
909cb9b27a
commit
9d646d6039
|
@ -44,15 +44,30 @@ type tcpWorker struct {
|
||||||
hub internet.Listener
|
hub internet.Listener
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTProxyType(s *internet.MemoryStreamConfig) internet.SocketConfig_TProxyMode {
|
||||||
|
if s == nil || s.SocketSettings == nil {
|
||||||
|
return internet.SocketConfig_Off
|
||||||
|
}
|
||||||
|
return s.SocketSettings.Tproxy
|
||||||
|
}
|
||||||
|
|
||||||
func (w *tcpWorker) callback(conn internet.Connection) {
|
func (w *tcpWorker) callback(conn internet.Connection) {
|
||||||
ctx, cancel := context.WithCancel(context.Background())
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
sid := session.NewID()
|
sid := session.NewID()
|
||||||
ctx = session.ContextWithID(ctx, sid)
|
ctx = session.ContextWithID(ctx, sid)
|
||||||
|
|
||||||
if w.recvOrigDest {
|
if w.recvOrigDest {
|
||||||
dest, err := tcp.GetOriginalDestination(conn)
|
var dest net.Destination
|
||||||
if err != nil {
|
switch getTProxyType(w.stream) {
|
||||||
newError("failed to get original destination").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
case internet.SocketConfig_Redirect:
|
||||||
|
d, err := tcp.GetOriginalDestination(conn)
|
||||||
|
if err != nil {
|
||||||
|
newError("failed to get original destination").Base(err).WriteToLog(session.ExportIDToError(ctx))
|
||||||
|
} else {
|
||||||
|
dest = d
|
||||||
|
}
|
||||||
|
case internet.SocketConfig_TProxy:
|
||||||
|
dest = net.DestinationFromAddr(conn.LocalAddr())
|
||||||
}
|
}
|
||||||
if dest.IsValid() {
|
if dest.IsValid() {
|
||||||
ctx = session.ContextWithOutbound(ctx, &session.Outbound{
|
ctx = session.ContextWithOutbound(ctx, &session.Outbound{
|
||||||
|
|
Loading…
Reference in New Issue