Bidirectional UDP tunnel with socat on Linux
Is it possible to create a bidirectional UDP tunnel with socat? The starting point is a client (C) that communicates with a server (S) and receives a reply, so C⟷S. Of course, C and S are on different networks with a relay (R) between them, hence the need for C⟷R⟷S. The relay is running Ubuntu Linux.
Using socat for example per this:
sudo nohup socat UDP-LISTEN:1194,fork,reuseaddr UDP:IP-ADDRESS-OF-HOME-ROUTER:1194 &
apparently results in all packets received by the relay (R) to be forwarded to IP-ADDRESS-OF-HOME-ROUTER
, including the reply packets from the server, or C⟶R⟷S.
So my question is, would it be possible to make socat wait for reply packets from the server, and forward them back to the client? Is there perhaps another way to accomplish this goal?
The second method (datagram with UDP-RECVFROM/UDP-SENDTO) works only in a query/answer mode; a second answer in sequence from the OpenVPN server will not be passed back to the client; and for each query packet a sub process will be forked.
The first method forks a subprocess per "connection" (determined by source port), and - after an initial packet from the client - forwards in both directions. Sub processes will hang "forever", so it is advisable to use the timeout option -T 3600 or so.