[tproxy] TProxy implementation.

Lennert Buytenhek buytenh@gnu.org
Wed, 26 Nov 2003 09:23:32 -0500

>I configured my transparent proxy box(has 1 network interface card) with
>Layer-4 switch(for Cache-Redirect).
>Just started, Tproxy working fine.
>Few minutes later, Tproxy send packet with other's foreign address to
>destination host irregularly.
>But client received response exactly.
>When that appeared, my reverse proxy box has 4000 established TCP server
>connections and hash table size was same.

I've seen this as well in my setup.  What tends to happen is

- The local TCP stack thinks a connection is no longer there, but
  conntrack thinks it is still there.  Local <IP:port> tuples (local
  to the proxy) are reused by the TCP stack, but are still listed as
  TIME_WAIT in conntrack.  This causes the IP of _new_ connections to
  foul up.

- The local TCP stack thinks a connection is still there, but conntrack
  thinks it's no longer there.  This happens in case of tcp half-close,
  and also seems to happen in some circumstances I can't figure out

Workaround for the first problem is easy-ish: assign several local IP
addresses to your proxy box, and bind the first 20000 connections to
the first IP, then 20000 to the next IP, etc.  Be sure to have your
tcp local port range setup big enough (i.e. 1024-65000).  It's not a
nice solution but it works.

The second problem is harder to tackle.  I'm still looking into it.