Quellcode durchsuchen

support tproxy in tcp connections

Darien Raymond vor 7 Jahren
Ursprung
Commit
9d646d6039
1 geänderte Dateien mit 18 neuen und 3 gelöschten Zeilen
  1. 18 3
      app/proxyman/inbound/worker.go

+ 18 - 3
app/proxyman/inbound/worker.go

@@ -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{