Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect a TCP connection

I have something like a proxy server (written in java) running between my clients and the actual video server (made in c++). Everything the clients send goes through this proxy and is then redirected to the server.

It is working fine, but I have some issues and think it would be better if I could make this proxy server only to listen to the clients requests and then somehow tell the server that a request has been made from the client side, and that it is supposed to create a connection with the client directly.

Basically in the TCP level what I want to happen is something like this:

1- whenever a client sends a SYN to my proxy, the proxy just sends a message to the real server telling the ip and port of the client.

2- The server would then send the corresponding SYN-ACK to the specified client creating a direct connection between client and server.

The proxy would then be just relaying the initial requests (but not the later data transfer) to the actual server. I just don't know if that is possible.

Thank you very much

Nelson R. Perez

like image 299
Bilthon Avatar asked Jun 04 '10 18:06

Bilthon


People also ask

What is a TCP redirect?

TCP/IP Redirector allows you to transparently redirect TCP/IP connections from one IP address and port to another. It may be used for mapping local ports or for redirecting traffic from one web site to another. Note: for redirecting websites, you need to replace the Host parameter in the request header.

How use Redir Linux?

Redirects connections through an HTTP proxy which supports the CONNECT command. Specify the address and port of the proxy using --caddr and --cport. --connect requires the hostname and port which the HTTP proxy will be asked to connect to. Set the bufsize (defaut 4096) in bytes.


2 Answers

That's very much the way some games (and Fog Creek CoPilot) do it, but it requires support on both the server and the client. Basically the proxy has to say to the client and server "try communicating with the directly on this ip and this port" and if they can't get through (because one or both is behind a NAT or firewall), they fall back to going through the proxy.

I found this good description of "peer to peer tcp hole punching" at http://www.brynosaurus.com/pub/net/p2pnat/

like image 58
Paul Tomblin Avatar answered Sep 26 '22 13:09

Paul Tomblin


Does the proxy and server lives on the same machine? If so, you can pass the connection to the server using Socket Transfer or File Descriptor Passing. You can find examples in C here,

http://www.wsinnovations.com/softeng/articles/uds.html

If they are on the different machines, there is no way to pass connection to the server. However, it's possible to proxy the IP packets to server using VIP (Virtual IP). This is below socket so you have to use Link layer interface, like DLPI.

like image 39
ZZ Coder Avatar answered Sep 22 '22 13:09

ZZ Coder