All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Snyder <josh@imagestream.com>
To: netfilter@lists.netfilter.org
Subject: Problem with ipconntrack+snat and changing routes
Date: Thu, 03 Nov 2005 17:42:52 -0500	[thread overview]
Message-ID: <436A926C.8080803@imagestream.com> (raw)

I have ran into this more than once and I just wanted to know if anyone 
else has ever seen this; I know everything I am talking about it valid 
for 2.4 kernels.  I don't think this is different in 2.6 but it might be.

What seems to be going on is the following.  Say we have a machine with 
two connections to the Internet and we are doing Nat on both of the 
external interfaces.  Something like...

                                          Eth2
                    Eth0  *-----------*--------> Cable 12.23.32.15
Internal network --------| Linux box |
  192.168.0.0/24          *-----------*--------> Dsl 34.36.23.89
                                          Eth1

Then we setup some Source Nat like...

# Snat for Cable
iptables -t nat -A POSTROUTING -o eth2 -j SNAT --to 12.23.32.15
# Snat for Dsl
iptables -t nat -A POSTROUTING -o eth1 -j SNAT --to 34.36.23.89

This works just fine... now here is where things start breaking.  If you 
use routing tables to statically put traffic onto one or the other 
external links things work as you would expect.  But you try to do route 
load balancing or you change which link your transmitting packets on you 
can end-up with very odd results.

So, if we do this to load balance traffic...

ip route add default scope global \
	nexthop via 12.23.32.1 dev eth2 weight 1 \
	nexthop via 34.36.23.1 dev eth1 weight 1

Now we are doing route based load balancing.  And everything will work 
fine until the route cache for a tracked connection expires.  For 
instance if you ssh into a machine but you go idle for an hour or so... 
Then what happens is the following, the Linux box will do a new route 
lookup if the new route lookup matches what you had before everything 
will still work fine.  But if the machine picks the other interface as 
the new route, packets will get sent out on the wrong interface still 
snated with the ip address of the other interface.

For example what you see is this... In the example above if you had a 
connection that was originally using eth2 so it was getting nated to 
12.23.32.15.  But if later on the route changes so your now going out 
eth1 you will still be transmitting packets with the Ip address of 
12.23.32.15 on your DSL link which has an ip address of 34.36.23.89. 
Most of the time this traffic will be dropped by your Isp.

Now, I understand that you can't just start sending packets for this 
connection with a new ip address.  But it doesn't sound like we should 
be sending these packets down the wrong interface.  I am not sure what 
the best thing to do in this case is... The above example is just one of 
a few ways you can see this problem(manually changing routing and 
Ospf/Bgp for example).  The worst case is if you have a routing change 
but your conntrack doesn't expire and routing doesn't change again after 
the first time... the only way to get stuff to work again is to unload 
ip_conntrack from the kernel.  I have ran into these issues a few times 
now and I was just wondering if anyone else has seen this or how SNAT 
should handle these cases.

			Josh


             reply	other threads:[~2005-11-03 22:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-03 22:42 Joshua Snyder [this message]
2005-11-04  2:38 ` Problem with ipconntrack+snat and changing routes Alexander Samad

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=436A926C.8080803@imagestream.com \
    --to=josh@imagestream.com \
    --cc=netfilter@lists.netfilter.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.