浏览代码

Fix https://github.com/XTLS/Xray-core/pull/5114#issuecomment-3273017153 (#5118)

风扇滑翔翼 3 月之前
父节点
当前提交
30e10be95d
共有 1 个文件被更改,包括 17 次插入17 次删除
  1. 17 17
      app/proxyman/inbound/worker.go

+ 17 - 17
app/proxyman/inbound/worker.go

@@ -77,25 +77,25 @@ func (w *tcpWorker) callback(conn stat.Connection) {
 		case internet.SocketConfig_TProxy:
 			dest = net.DestinationFromAddr(conn.LocalAddr())
 		}
-		// Check if try to connect to this inbound itself (can cause loopback)
-		var isLoopBack bool
-		if w.address == net.AnyIP || w.address == net.AnyIPv6 {
-			if dest.Port.Value() == w.port.Value() && IsLocal(dest.Address.IP()) {
-				isLoopBack = true
-			}
-		} else {
-			if w.hub.Addr().String() == dest.NetAddr() {
-				isLoopBack = true
-			}
-		}
-		if isLoopBack {
-			cancel()
-			conn.Close()
-			errors.LogError(ctx, errors.New("loopback connection detected"))
-			return
-		}
 
 		if dest.IsValid() {
+			// Check if try to connect to this inbound itself (can cause loopback)
+			var isLoopBack bool
+			if w.address == net.AnyIP || w.address == net.AnyIPv6 {
+				if dest.Port.Value() == w.port.Value() && IsLocal(dest.Address.IP()) {
+					isLoopBack = true
+				}
+			} else {
+				if w.hub.Addr().String() == dest.NetAddr() {
+					isLoopBack = true
+				}
+			}
+			if isLoopBack {
+				cancel()
+				conn.Close()
+				errors.LogError(ctx, errors.New("loopback connection detected"))
+				return
+			}
 			outbounds[0].Target = dest
 		}
 	}