mirror of
				https://github.com/v2fly/v2ray-core.git
				synced 2025-10-25 23:04:58 +00:00 
			
		
		
		
	support tproxy in tcp connections
This commit is contained in:
		
							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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Darien Raymond
						Darien Raymond