Skip to contentSkip to conversation

Netfilter Inconsistency?

DISCUSSION Brian Deep 2 participants 3 messages May 15, 2003 – May 27, 2003 netfilter

lore
Share & tools
lore

Brian Deep

author
#0 lore raw

I am running into some netfilter inconsistency in developing an application that uses libiptc to add and remove SNAT rules.

I can add and delete rules fine and open up
connections correctly using the SNAT rules, but if I change the source IP address on the SNAT rule I run into problems. The SNAT rule is added correctly and verified using iptables userspace, but when the connection actually gets NAT'd, it gets the source IP address of the SNAT rule I had in previous. I have tried manually inserting and appending SNAT rules, but the connection is still NAT'd with the previous rule source IP. At some point, this rule "time's out" and I am able to correctly add my SNAT rule in.

So,
iptables -t nat -A POSTROUTING -p tcp --sport 1040 --dport 80 -j SNAT --to-source 1.1.1.1
is added using libiptc. Connections work fine. iptables -t nat -D POSTROUTING -p tcp --sport 1040 --dport 80 -j SNAT --to-source 1.1.1.1
is executed to remove the rule using libiptc and verfied with iptables.
Next,
iptables -t nat -A POSTROUTING -p tcp --sport 1040 --dport 80 -j SNAT --to-source 1.1.1.2
is added via libiptc and verified using iptables. However, any connections going out are SNAT'd to 1.1.1.1

If the connection goes out on a different source port, everything works fine. Using iptables v1.2.7a. Kernel v 2.4.18

Anyone have any thoughts? And why the he** would it timeout after several minutes?

Thanks,
-- Brian

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com

#1 lore raw
Quoted 11 lines · Brian Deep

I can add and delete rules fine and open up
connections correctly using the SNAT rules, but if I change the source IP address on the SNAT rule I run into problems. The SNAT rule is added correctly and verified using iptables userspace, but when the connection actually gets NAT'd, it gets the source IP address of the SNAT rule I had in previous. I have tried manually inserting and appending SNAT rules, but the connection is still NAT'd with the previous rule source IP. At some point, this rule "time's out" and I am able to correctly add my SNAT rule in.

the NAT tables are only traversed for every first packet of a connection. if you alter the ruleset, it will only work for new connections. All further packets within this connection will be transformed according to what was determined by the first packet.

Quoted 2 lines

Anyone have any thoughts? And why the he** would it timeout after several minutes?

because then the entry times out from the conntrack table (you can confirm this by watching /proc/net/ip_conntrack)

Quoted 2 lines

Thanks,
-- Brian

Signature · 5 lines
- Harald Welte <[email protected]>             http://www.netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie
author
#2 lore raw
Quoted 23 lines · --- Harald Welte
Quoted 2 lines · Brian Deep

I can add and delete rules fine and open up
connections correctly using the SNAT rules, but if

I

Quoted 1 line

change the source IP address on the SNAT rule I

run

Quoted 1 line

into problems. The SNAT rule is added correctly

and

Quoted 2 lines

verified using iptables userspace, but when the connection actually gets NAT'd, it gets the source

IP

Quoted 1 line

address of the SNAT rule I had in previous. I

have

Quoted 1 line

tried manually inserting and appending SNAT

rules,

Quoted 1 line

but the connection is still NAT'd with the

previous

Quoted 1 line

rule source IP. At some point, this rule "time's

out"

Quoted 1 line

and I am able to correctly add my SNAT rule in.

Quoted 9 lines

the NAT tables are only traversed for every first packet of a
connection. if you alter the ruleset, it will only work for new
connections. All further packets within this connection will be
transformed according to what was determined by the first packet.

Oops, I meant to say that I open up a new connection based on the new NAT rule and it uses(is NAT'd according to) the previously removed NAT rule instead
of newly created one. Iptables shows only one rule
in place, the new one, but tcpdump shows the packets NAT'd according to the old rule. I have to wait for connection tracking to time-out the connection based on the old rule before the new connection is NAT'd correctly.
My filter rules specify a source port address, as my client binds to a port before connecting so that it hits the correct NAT rule. If I close the connection and open a new connection on the same source port (seconds later) I run into this NAT/connetion-tracking problem.

Thanks,
-- Brian

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.com