Skip to contentSkip to conversation

SNAT seems to "miss" some packets

DISCUSSION Fabio Muzzi 3 participants 5 messages Jan 29, 2007

lore
Share & tools
lore
#0 lore raw

Hi, this is my first post to this list. I have tried goggling, but I have failed, and i think now it's time to ask for help.

I am running a firewall with Debian Linux (kernel 2.6.15) and am I am expriencing a strange behavior in a simple SNAT rule.

I was running a dual gateway equal cost multipath configuration, but I have reverted to a single gateway configuration to be sure that the issue was not with the dual gateway config.

eth2 is my WAN interface, with address 217.221.234.74. My lan is 10.0.0.0/16, and I have a SNAT rule that says:

iptables -t nat -A POSTROUTING -o eth2 -j SNAT -s 10.0.0.0/16 --to-source 217.221.234.74

Running a simple "ethereal -i eth2 'not host 217.221.234.74'" I can see that sometimes some packets go through WAN interface without being SNATed by netfilter.

Tipically I can see a lot of correctly SNATed traffic, and once every minute or so, some packets that seem to belong to an existent connection, that go through with the original "from" address (in the 10.0.0.0/16 network)

this is an example taken from tethereal:

5062.581579    10.0.0.51 -> 207.68.178.134 TCP 1069 > www [FIN, ACK] Seq=0 Ack=0 Win=64526 Len=0
5062.581602    10.0.0.51 -> 207.68.178.134 TCP 1070 > www [FIN, ACK] Seq=0 Ack=0 Win=65535 Len=0
5063.687959    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1070 > www [FIN, ACK] Seq=0 Ack=0 Win=65535 Len=0
5064.016036    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1069 > www [FIN, ACK] Seq=0 Ack=0 Win=64526 Len=0
5066.094266    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1070 > www [FIN, ACK] Seq=0 Ack=0 Win=65535 Len=0
5067.078602    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1069 > www [FIN, ACK] Seq=0 Ack=0 Win=64526 Len=0
5070.906759    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1070 > www [FIN, ACK] Seq=0 Ack=0 Win=65535 Len=0
5071.806521    10.0.0.51 -> 195.113.232.83 TCP 1065 > www [RST, ACK] Seq=0 Ack=0 Win=0 Len=0
5071.806642    10.0.0.51 -> 195.113.232.83 TCP 1067 > www [RST, ACK] Seq=0 Ack=0 Win=0 Len=0
5071.806657    10.0.0.51 -> 195.113.232.83 TCP 1066 > www [RST, ACK] Seq=0 Ack=0 Win=0 Len=0
5071.806765    10.0.0.51 -> 195.113.232.83 TCP 1068 > www [RST, ACK] Seq=0 Ack=0 Win=0 Len=0
5073.094312    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1069 > www [FIN, ACK] Seq=0 Ack=0 Win=64526 Len=0
5077.923046    10.0.0.12 -> 207.68.178.239 TCP [TCP Retransmission] remoteping > www [FIN, ACK] Seq=0 Ack=0 Win=64294 Le  n=0
5080.531986    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1070 > www [FIN, ACK] Seq=0 Ack=0 Win=65535 Len=0
5085.125717    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1069 > www [FIN, ACK] Seq=0 Ack=0 Win=64526 Len=0
5099.782192    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1070 > www [FIN, ACK] Seq=0 Ack=0 Win=65535 Len=0
5109.188539    10.0.0.51 -> 207.68.178.134 TCP [TCP Retransmission] 1069 > www [FIN, ACK] Seq=0 Ack=0 Win=64526 Len=0
5116.244053    10.0.0.12 -> 207.68.178.239 TCP [TCP Retransmission] remoteping > www [FIN, ACK] Seq=0 Ack=0 Win=64294 Le  n=0

Is this a known bug of my kernel/netfilter version? Is there something I can do to fix it?

Thanks.

Signature · 1 line
  Fabio "Kurgan" Muzzi
#1 lore raw
Quoted 2 lines

iptables -t nat -A POSTROUTING -o eth2 -j SNAT -s 10.0.0.0/16 --to-source 217.221.234.74

Make sure there are no other terminating rules in POSTROUTING that could stop a packet from reaching this SNAT rule.

	-`J'
#3 lore raw
In reply to Fabio Muzzi

Hello,

Quoted 3 lines · Fabio Muzzi

I am running a firewall with Debian Linux (kernel 2.6.15) and am I am expriencing a strange behavior in a simple SNAT rule.

[...]

Quoted 3 lines

Running a simple "ethereal -i eth2 'not host 217.221.234.74'" I can see that sometimes some packets go through WAN interface without being SNATed by netfilter.

Maybe these packets are considered in the INVALID state by the Netfilter connection tracking. Packets in the INVALID state bypass the stateful NAT processing. You may add a rule to log INVALID packets and compare them with the tcpdump output :

iptables -I FORWARD -o eth2 -m state --state INVALID \
-j LOG --log-prefix "FWD_INV "

Anyway there is no chance that another NAT rule may cause this, as packets belonging or related to an established connection don't go through the nat chains.

Note :
This may be related to the thread "Dropped fin acks (iptables + lvs)" above, as in both cases most affected packets seem to be FIN/ACK and RST/ACK.

#2 lore raw
In reply to Jan Engelhardt

Hello Jan,

Quoted 1 line · you
Quoted 1 line

iptables -t nat -A POSTROUTING -o eth2 -j SNAT -s 10.0.0.0/16 --to-source 217.221.234.74

JE> Make sure there are no other terminating rules in POSTROUTING that could stop a JE> packet from reaching this SNAT rule.

No, the snat rule is the FIRST in the postrouting chain. Also I have noticed that maybe i was wrong... I mean, the issue is not with the SNAT rule, but with a redirect in PREROUTING.

I have noticed now that all of the packets that are not SNATed are FIN, ACK or RST,ACK packets that go to port 80 on the remote host.

I have just remembered that I have a PREROUTING rule (the first in the chain) that does a REDIRECT to a local proxy, like this:

iptables -t nat -A PREROUTING -i eth0 -m state --state new -p tcp --dport 80 -j REDIRECT --to-port 8080

Now, this means that (I forgot it even if I have configured it) there should be NO web traffic to be SNATed, because all of the connections to port 80 go through the proxy.

So, it seems that somehow is the PREROUTING that fails to catch the packets, does not REDIRECT them to the local proxy, and these packets go out of the WAN interface, where no connection tracking status is registered for these packets that do not belong to a SNATed connection... and this is why they do not get SNATed.

So the new question is: why does the REDIRECT rule in prerouting miss some packets? And why always FIN packets?

Thanks again.

Signature · 1 line
  Fabio "Kurgan" Muzzi
#4 lore raw
In reply to Pascal Hambourg

Hello Pascal,

Monday, January 29, 2007, 3:07:54 PM, you wrote:

PH> This may be related to the thread "Dropped fin acks (iptables + lvs)" PH> above, as in both cases most affected packets seem to be FIN/ACK and PH> RST/ACK.

I have not read the archives, I'll download and read them soon.

Anyway, it seems that you are right, it misses only FIN packets... but it probably misses them in PREROUTING, as I have stated in another post in this thread.

Signature · 1 line
  Fabio "Kurgan" Muzzi