[tproxy] Bad Interaction between NAT and TPROXY
Tue, 28 Sep 2004 22:01:54 -0700 (PDT)
I was just wondering if any sort of resolution has
appeared for this interaction between TPROXY and the
various components of Netfilter? It wasn't clear from
the Netfilter summary how much discussion might have
--- KOVACS Krisztian <firstname.lastname@example.org> wrote:
> 2004-08-20, p keltezéssel 06:53-kor Tim Burress ezt
> > We're seeing a problem when we combine NAT and
> > 1.2.1 on a firewall system with application-layer
> > proxies in the 2.4.26 kernel. Say the firewall
> > has two interfaces, public (18.104.22.168) and
> > (10.0.0.1). There is an SMTP server (10.0.0.2) on
> > private network, and we have DNAT rules configured
> > map
> > 22.214.171.124 ---> 10.0.0.2
> > So then, in practice, the SMTP proxy on the
> > receives a redirected SMTP connection from a
> > (126.96.36.199) on the net. It then does its
> > stuff, and sets up a connection to the server by:
> > (1) Binding a socket to a local address
> > (2) Setting up a TPROXY assignment from the local
> > address to 188.8.131.52
> > (3) Connect out to the server using the
> > address recovered by getsockopt(ORIGINAL_DST) on
> > original incoming socket
> > This all works fine when there is no NAT (and the
> > private addresses are eliminated). In that case,
> > the server sees is an incoming connection from
> > 184.108.40.206. But with NAT in the picture, what the
> > sees is an incoming connection from 10.0.0.1.
> > Working through the kernel code, it appears that
> > CONFIG_IP_NF_NAT_LOCAL is enabled, there is a call
> > do_extra_mangle() in ip_nat_core.c that is forcing
> > source address of outgoing packets to be the
> > source from the routing tables in the LOCAL_OUT
> > so by the time the packet gets to POSTROUTING, the
> > outbound packet no longer matches the TPROXY rule
> > we set up, so the source address goes out as-is.
> > Looking for a general solution, all I can think of
> > the moment is to patch ip_nat_core.c so that the
> > to do_extra_mangle.c is skipped if connection has
> > assigned by TPROXY, on the theory that the code
> > setting up the TPROXY assignment knows what it
> > the final source or destination to be, and that
> > should take priority over the extra mangling done
> > NAT.
> > Perhaps testing for IPS_TPROXY before the call to
> > do_extra_mangle()?
> > If that would work (the code is still a jungle to
> > it seems like this would solve the problem and
> > be relatively harmless, but I'm not sure. Actually
> > not sure why the NAT code rewrites the source
> > of a DNAT packet anyway (or the destination
> address of
> > an SNAT packet), so it makes me nervous.
> > What we do now as a workaround in simple networks
> > manually force the proxy to bind the local socket
> > 10.0.0.1 before the TPROXY assignment. It's ugly,
> > it works, since it anticipates how the kernel will
> > mangle the packets. However it's obviously not a
> > general solution, and would fail in complex
> > where routing to the destination is dynamic.
> > What's the best way to deal with this?
> Thanks for the detailed problem report... This
> seems to be a quite
> tough problem, and a very curious interaction
> between different parts of
> Netfilter. At the moment I do not have any better
> ideas than checking
> IPS_TPROXY, but I hope that the problem can be
> investigated in more
> detail on the Netfilter workshop.
> Please try to use your proposed workaround until
> then, we'll try to
> come up with a solution acceptable to everyone.
> Krisztian KOVACS
Do you Yahoo!?
Declare Yourself - Register online to vote today!