TCP bouncer with failover

Translation of the original in Catalan. Read it in: CatalàCastellano

In the

GATv2

project a couple of days ago I've published a subproject I call

tcp-fwd

. It's a small and simple application programmed with Python and Twisted. The functionality is very simple it's a TCP bouncer that if it can't connect to the first destination to forward the TCP traffic to it tries the second one, if not the third and so on up to as many servers as have been defined. If the connection can't end up being established the TCP link to the bouncer is disconnected. That is, the behaviour is transparent to the original client. For those who aren't familiar with the functionality of a bouncer I'll try to explain it. It's a TCP socket that listens on a port and acts as a

reverse proxy

. That is, when it receives a connection right away another connection is opened towards the server and if this one can be established then it connects the first connection with the second one.

The biggest drawback I see in this idea is that the connection that arrives at the final server doesn't have the client's IP as origin, but the IP of the server acting as bouncer this makes the log file of the final server not have the IP information of the client that has really connected. Even so there are scenarios in which this tool is very useful, since the most important thing isn't always those logs but rather that the client ends up getting the service it wanted transparently and the failover system I use always follows the same trial and error sequence for every socket that opens, so, the failover system is instantaneous and doesn't lose a single call.

One of the applications I'm using it for is to do mail delivery to a postfix. It's a mail server that only filters mail and the mails that pass the filters are delivered to the company's real mail server, well then, to know which is the company's server I use the configuration file

/etc/postfix/transport

where the server to deliver the mail to is indicated depending on the domain. But I haven't been able to see how to tell it more than one mail server to deliver to. So, what I do is to put as transport IP and port a localhost IP and a random port, then postfix delivers the mail to the bouncer located at that localhost IP and it's the bouncer that tries to connect this socket with one of the internal mail servers. Therefore, the thing is completely transparent for postfix and the servers that receive the mail have the same origin IP as if they had received it directly from postfix.

I suppose the idea has been well defined, if not you already know you can ask me whatever questions you need. The project's code is at:

tcp-fwd

.