conntrack and PREROUTING
Hi All,
Is the PREROUTING chain bypassed if a connection is ESTABLISHED? There are hints to this in the documents I've read but I haven't found anything definitive.
I'm using Dansguardian with TinyProxy with the following rule:
iptables -t nat -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3129
Everything is working, from a proxy perspective, as expected. However, if I play a high bit-rate (>4 Mbps) video stream over HTTP, the playback is very choppy. The choppiness is due to ACK latency through the proxy. (Video playback is fine if I remove the proxy.)
I know I could just create a nat PREROUTING rule to bypass the proxy for the site I'm attempting to stream video from but I'm looking for a more general solution. Thus, what I'm attempting to do is have ACKs bypass the proxy after the connection is ESTABLISHED. I tried using the raw table in PREROUTING but the my rule was never hit. (Thus, the reason for my first question.) The raw table rules I attempted were:
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i br0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -m state --state ESTABLISHED -j NOTRACK
-and-
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i br0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -m conntrack --ctstate ESTABLISHED -j NOTRACK
Is what I'm attempting to do possible with the existing implementation? Does this even make sense?
I'm attempting to do this on a home router that is running Linux 2.6.18 with iptables v1.3.7-20070509
Thanks,
...doug
Quoted 3 lines · Doug Kehn
Hi All,
Is the PREROUTING chain bypassed if a connection is ESTABLISHED?
Generally, no. For the nat table yes, which is only consulted on new connections.
Quoted 25 lines
There are hints to this in the documents I've read but I haven't found anything definitive.
I'm using Dansguardian with TinyProxy with the following rule:
iptables -t nat -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3129
Everything is working, from a proxy perspective, as expected. However, if I play a high bit-rate (>4 Mbps) video stream over HTTP, the playback is very choppy. The choppiness is due to ACK latency through the proxy. (Video playback is fine if I remove the proxy.)
I know I could just create a nat PREROUTING rule to bypass the proxy for the site I'm attempting to stream video from but I'm looking for a more general solution. Thus, what I'm attempting to do is have ACKs bypass the proxy after the connection is ESTABLISHED. I tried using the raw table in PREROUTING but the my rule was never hit. (Thus, the reason for my first question.) The raw table rules I attempted were:
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i br0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -m state --state ESTABLISHED -j NOTRACK
Quoted 7 lines
-and-
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i br0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -m conntrack --ctstate ESTABLISHED -j NOTRACK
Does this even make sense?
Yes, but:
Quoted 2 lines
Is what I'm attempting to do possible with the existing implementation?
The connection tracking and NAT subsystems might get confused if they do not see all ACKs despite the TCP window moving on. You will know when the connection hangs.
Quoted 9 lines · Jan Engelhardt
Quoted 5 lines · Doug Kehn
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i br0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -m conntrack --ctstate ESTABLISHED -j NOTRACK
Does this even make sense?
Yes, but:
No. The raw table doesn't have conntrack information.
Quoted 7 lines · Patrick McHardy
Quoted 6 lines · Jan Engelhardt
Quoted 4 lines · Doug Kehn
iptables -t raw -A PREROUTING -d ! 192.168.2.0/24 -i br0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -m conntrack --ctstate ESTABLISHED -j NOTRACK
Quoted 6 lines
Quoted 3 lines
Quoted 1 line
Does this even make sense?
Yes, but:
No. The raw table doesn't have conntrack information.
Oops ;-)
But you can assume that any ACK belongs to an established connection, hence omitting -m conntrack --ctstate ESTABLISHED would achieve the same.
Of course there are scenarios, like probe ACKs sent by nmap that do not belong to any, or a conntrack router B which got rebooted (and hence lost the connections that are still active between two hosts A and C), but that should be real corner cases.
Hi Jan,
Quoted 63 lines · Jan Engelhardt
Quoted 4 lines
Hi All,
Is the PREROUTING chain bypassed if a connection is
ESTABLISHED?
Generally, no. For the nat table yes, which is only consulted on
new connections.Quoted 1 line
There are hints to this in the documents I've read
but I haven't
Quoted 3 lines
found anything definitive.
I'm using Dansguardian with TinyProxy with the
following rule:
Quoted 2 lines
iptables -t nat -A PREROUTING -d !
192.168.2.0/255.255.255.0 -i eth0
Quoted 3 lines
-p tcp -m tcp --dport 80 -j REDIRECT --to-ports 3129
Everything is working, from a proxy perspective, as
expected.
Quoted 1 line
However, if I play a high bit-rate (>4 Mbps) video
stream over HTTP,
Quoted 1 line
the playback is very choppy. The choppiness is due to
ACK latency
Quoted 1 line
through the proxy. (Video playback is fine if I remove
the proxy.)
Quoted 2 lines
I know I could just create a nat PREROUTING rule to
bypass the proxy
Quoted 1 line
for the site I'm attempting to stream video from
but I'm looking for
Quoted 1 line
a more general solution. Thus, what I'm attempting
to do is have
Quoted 1 line
ACKs bypass the proxy after the connection is
ESTABLISHED. I tried
Quoted 1 line
using the raw table in PREROUTING but the my rule was
never hit.
Quoted 1 line
(Thus, the reason for my first question.) The raw table
rules I
Quoted 3 lines
attempted were:
iptables -t raw -A PREROUTING -d !
192.168.2.0/255.255.255.0 -i eth0
Quoted 1 line
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp
--dport 80 -m
Quoted 5 lines
state --state ESTABLISHED -j NOTRACK
-and-
iptables -t raw -A PREROUTING -d !
192.168.2.0/255.255.255.0 -i eth0
Quoted 1 line
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp
--dport 80 -m
Quoted 3 lines
conntrack --ctstate ESTABLISHED -j NOTRACK
Does this even make sense?
Yes, but:
Quoted 1 line
Is what I'm attempting to do possible with the
Quoted 8 lines
existing
Quoted 1 line
implementation?
The connection tracking and NAT subsystems might get confused if
they do not see all ACKs despite the TCP window moving on. You
will know when the connection hangs.
The connections do hang if I change the rule to:
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i eth0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -j NOTRACK
This makes sense, I believe, because the ACK to the SYN-ACK wouldn't be tracked and the connection state would never reach ESTABLISHED.
Regards,
...doug
Doug Kehn írta:
Quoted 6 lines
The connections do hang if I change the rule to:
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i eth0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -j NOTRACK
This makes sense, I believe, because the ACK to the SYN-ACK wouldn't be tracked and the connection state would never reach ESTABLISHED.
What about the UNTRACKED state???
Quoted 3 lines
Regards,
...doug
Swifty
Hi Patrick,
Quoted 6 lines · Patrick McHardy
Quoted 3 lines · Jan Engelhardt
Quoted 1 line · Doug Kehn
iptables -t raw -A PREROUTING -d !
192.168.2.0/255.255.255.0 -i br0
Quoted 1 line
Quoted 1 line
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m
Quoted 8 lines
tcp --dport 80 -m
Quoted 5 lines
Quoted 3 lines
conntrack --ctstate ESTABLISHED -j NOTRACK
Does this even make sense?
Yes, but:
No. The raw table doesn't have conntrack information.
I assume the same holds for -m state as well? If so, this would explain why the rules are never matched.
Is there a way to have ACKs bypass the proxy and not break connection tracking?
My theory is that when performing a streaming HTTP download (e.g. streaming video over HTTP) having the ACKs traverse the proxy introduces sufficient delay to degrade video playback. I'm hoping to find a general solution. Creating a NOTRACK rule for each site is possible but a little cumbersome.
Thanks,
...doug
Quoted 11 lines · Doug Kehn
Hi Patrick,
Quoted 6 lines · Patrick McHardy
Quoted 3 lines · Jan Engelhardt
Quoted 1 line · Doug Kehn
iptables -t raw -A PREROUTING -d !
192.168.2.0/255.255.255.0 -i br0
Quoted 1 line
Quoted 1 line
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m
Quoted 8 lines
Quoted 6 lines
tcp --dport 80 -m
Quoted 4 lines
Quoted 3 lines
conntrack --ctstate ESTABLISHED -j NOTRACK
Does this even make sense?
Yes, but:
No. The raw table doesn't have conntrack information.
I assume the same holds for -m state as well? If so, this would explain why the rules are never matched.
Correct.
Quoted 3 lines
Is there a way to have ACKs bypass the proxy and not break connection tracking?
My theory is that when performing a streaming HTTP download (e.g. streaming video over HTTP) having the ACKs traverse the proxy introduces sufficient delay to degrade video playback. I'm hoping to find a general solution. Creating a NOTRACK rule for each site is possible but a little cumbersome.
I don't see how that could work, the proxy has two seperate connections (client<->proxy and proxy<->server), so it needs to receive all packets.
Hi Gáspár,
Quoted 4 lines · Gáspár Lajos
Doug Kehn írta:
Quoted 3 lines
The connections do hang if I change the rule to:
iptables -t raw -A PREROUTING -d !
Quoted 8 lines
192.168.2.0/255.255.255.0 -i eth0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -j NOTRACK
Quoted 2 lines
This makes sense, I believe, because the ACK to the
SYN-ACK wouldn't be tracked and the connection state would never reach ESTABLISHED.
Quoted 1 line
What about the UNTRACKED state???
I get the same result with UNTRACKED. 8(
Thanks,
...doug
Hi Patrick,
Quoted 36 lines · Patrick McHardy
Quoted 11 lines · Doug Kehn
Hi Patrick,
Quoted 6 lines · Patrick McHardy
Quoted 3 lines · Jan Engelhardt
Quoted 1 line · Doug Kehn
iptables -t raw -A PREROUTING -d !
192.168.2.0/255.255.255.0 -i br0
Quoted 1 line
Quoted 1 line
-p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK
ACK -m
Quoted 6 lines
Quoted 6 lines
tcp --dport 80 -m
Quoted 4 lines
Quoted 3 lines
conntrack --ctstate ESTABLISHED -j NOTRACK
Does this even make sense?
Yes, but:
No. The raw table doesn't have conntrack
information.
Quoted 2 lines
I assume the same holds for -m state as well? If so,
this would explain why the rules are never matched.
Correct.
Quoted 1 line
Is there a way to have ACKs bypass the proxy and not
break connection tracking?
Quoted 2 lines
My theory is that when performing a streaming HTTP
download (e.g. streaming video over HTTP) having the ACKs traverse the proxy introduces sufficient delay to degrade video playback. I'm hoping to find a general solution.
Creating a NOTRACK rule for each site is possible but a
little cumbersome.
Quoted 5 lines
I don't see how that could work, the proxy has two seperate
connections (client<->proxy and proxy<->server), so it
needs to receive all packets.
Yep, that's my understanding. I guess I was hoping that my feeble little brain was missing something obvious/cleaver.
Thanks,
...doug
Quoted 9 lines · Doug Kehn
The connections do hang if I change the rule to:
iptables -t raw -A PREROUTING -d ! 192.168.2.0/255.255.255.0 -i eth0 -p tcp -m tcp --tcp-flags FIN,SYN,RST,ACK ACK -m tcp --dport 80 -j NOTRACK
This makes sense, I believe, because the ACK to the SYN-ACK wouldn't be tracked and the connection state would never reach ESTABLISHED.
The connection is established once conntrack sees the SYNACK.