support tproxy in tcp connections

pull/1289/head
Darien Raymond 2018-09-23 20:14:07 +02:00
parent 909cb9b27a
commit 9d646d6039
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
1 changed files with 18 additions and 3 deletions

View File

@ -44,15 +44,30 @@ type tcpWorker struct {
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) {
ctx, cancel := context.WithCancel(context.Background())
sid := session.NewID()
ctx = session.ContextWithID(ctx, sid)
if w.recvOrigDest {
dest, err := tcp.GetOriginalDestination(conn)
if err != nil {
newError("failed to get original destination").Base(err).WriteToLog(session.ExportIDToError(ctx))
var dest net.Destination
switch getTProxyType(w.stream) {
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() {
ctx = session.ContextWithOutbound(ctx, &session.Outbound{