Skip to contentSkip to conversation

conntrack-tools 0.9.14 can not block the connection

DISCUSSION Richard Feng 6 participants 18 messages May 6, 2010 – May 10, 2010

lore
Share & tools
lore
#0 lore raw

Hi,

I am using Linux 2.6.29. I have the problem for using 'conntrack' (version:0.9.14) to block the traffic.
Using the following command as example:
conntrack -D -s 1.1.1.1 -d 2.2.2.2
After execution, it appears the connection info was deleted -
conntrack -L | grep 1.1.1.1 -- shows the entry was deleted.

However, the connection is still active - is this the correct behaviour?

From the documentation (from conntrack-tools.netfilter.org), somewhere it says that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero".There is simply no 'netfilter' folder under my
folder '/proc/sys/net/ipv4'. Is this the problem? How could I fix it?

Thanks,
Richard Feng

#1 lore raw
Quoted 8 lines · Richard Feng

Hi,

I am using Linux 2.6.29. I have the problem for using 'conntrack' (version:0.9.14) to block the traffic.
Using the following command as example:
conntrack -D -s 1.1.1.1 -d 2.2.2.2
After execution, it appears the connection info was deleted -
conntrack -L | grep 1.1.1.1 -- shows the entry was deleted.

If something does not exist, conntrack won't output it.

Quoted 1 line

However, the connection is still active - is this the correct behaviour?

Yes.

Quoted 4 lines
Quoted 1 line

From the documentation (from conntrack-tools.netfilter.org), somewhere it says

that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero".There is simply no 'netfilter' folder under my
folder '/proc/sys/net/ipv4'. Is this the problem? How could I fix it?

Upgrading to a newer kernel (you're probably running some stoneage thing).

#2 lore raw
Quoted 5 lines · Jan Engelhardt
Quoted 3 lines · Richard Feng

Hi,

I am using Linux 2.6.29. I have the problem for using 'conntrack'

[...]

Quoted 2 lines

Upgrading to a newer kernel (you're probably running some stoneage thing).

For my information: I know that 2.6.29 isn't recent, but is it already considered a 'stone age thing'?

--
Rob

#3 lore raw
Quoted 5 lines · Rob Sterenborg
Quoted 4 lines · Jan Engelhardt
Quoted 2 lines · Richard Feng

Hi,

Quoted 7 lines
Quoted 1 line
Quoted 1 line

I am using Linux 2.6.29. I have the problem for using 'conntrack'

[...]

Quoted 2 lines

Upgrading to a newer kernel (you're probably running some stoneage thing).

For my information: I know that 2.6.29 isn't recent, but is it already considered a 'stone age thing'?

Let's requote:

Quoted 1 line

that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to

That file "ip_conntrack_tcp_be_liberal" was last seen in ... anyway, it's nf_conntrack_tcp_be_liberal now.

#4 lore raw
In reply to Jan Engelhardt

Thanks Jan for your answer - I still got some questions in the following.

Quoted 8 lines · Jan Engelhardt
Quoted 4 lines · Richard Feng

Hi,

However, the connection is still active - is this the correct behaviour?

Yes.

So 'conntrack -D' can not really cut current connections? It can only delete entry from the state table? I just want to make sure - from the document "http://conntrack-tools.netfilter.org/manual.html#conntrack". It clearly said "Delete on entry, this can be used to block traffic (you have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero)".

Quoted 1 line
Quoted 1 line
Quoted 1 line

From the documentation (from conntrack-tools.netfilter.org), somewhere it

says

Quoted 1 line
Quoted 1 line

that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal

to

Quoted 5 lines
Quoted 2 lines

zero".There is simply no 'netfilter' folder under my folder '/proc/sys/net/ipv4'. Is this the problem? How could I fix it?

Upgrading to a newer kernel (you're probably running some stoneage thing).

Thank you for your pointer at a later reply - I found it now
at /proc/sys/net/netfilter/nf_conntrack_tcp_be_liberal. And it was set "0".

Regards,
Richard

#5 lore raw
Quoted 6 lines · Richard Feng
Quoted 5 lines
Quoted 5 lines

From the documentation (from conntrack-tools.netfilter.org), somewhere it says that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero".There is simply no 'netfilter' folder under my folder '/proc/sys/net/ipv4'. Is this the problem? How could I fix it?

Quoted 7 lines

So 'conntrack -D' can not really cut current connections? It can only delete entry from the state table? I just want to make sure - from the document "http://conntrack-tools.netfilter.org/manual.html#conntrack". It clearly said "Delete on entry, this can be used to block traffic (you have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero)".

The documentation seems to be off here. If you only delete a ct entry, the next packet (even if a TCP ACK or something) will make a new ct with NEW as a ctstate.

To really have a TCP/SCTP connection blocked after deletion of the ct entry, you have to only allow NEW ctstates with the initla TCP/SCTP packet (SYN/INIT).

#6 lore raw
Quoted 16 lines · Jan Engelhardt
Quoted 6 lines · Richard Feng
Quoted 5 lines
Quoted 5 lines

From the documentation (from conntrack-tools.netfilter.org), somewhere it says that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero".There is simply no 'netfilter' folder under my folder '/proc/sys/net/ipv4'. Is this the problem? How could I fix it?

Quoted 7 lines

So 'conntrack -D' can not really cut current connections? It can only delete entry from the state table? I just want to make sure - from the document "http://conntrack-tools.netfilter.org/manual.html#conntrack". It clearly said "Delete on entry, this can be used to block traffic (you have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero)".

Quoted 7 lines

The documentation seems to be off here. If you only delete a ct entry, the next packet (even if a TCP ACK or something) will make a new ct with NEW as a ctstate.

To really have a TCP/SCTP connection blocked after deletion of the ct entry, you have to only allow NEW ctstates with the initla TCP/SCTP packet (SYN/INIT).

Yes, you need a well-formed stateful rule-set "to cut" the connection (at least you have to add a rule to block traffic in INVALID stats). Probably this is not clear enough in the doc. I can write a patch for this or alternatively accept one.

Thank you for the comments.

#7 lore raw
Quoted 19 lines · Pablo Neira Ayuso
Quoted 18 lines · Jan Engelhardt
Quoted 5 lines · Richard Feng
Quoted 5 lines
Quoted 5 lines

From the documentation (from conntrack-tools.netfilter.org), somewhere it says that "have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero".There is simply no 'netfilter' folder under my folder '/proc/sys/net/ipv4'. Is this the problem? How could I fix it?

Quoted 7 lines

So 'conntrack -D' can not really cut current connections? It can only delete entry from the state table? I just want to make sure - from the document "http://conntrack-tools.netfilter.org/manual.html#conntrack". It clearly said "Delete on entry, this can be used to block traffic (you have to set /proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal to zero)".

The documentation seems to be off here. If you only delete a ct entry, the next packet (even if a TCP ACK or something) will make a new ct with NEW as a ctstate.

Quoted 6 lines
Quoted 3 lines

To really have a TCP/SCTP connection blocked after deletion of the ct entry, you have to only allow NEW ctstates with the initla TCP/SCTP packet (SYN/INIT).

Yes, you need a well-formed stateful rule-set "to cut" the connection (at least you have to add a rule to block traffic in INVALID stats).

With "stats" I meant "state", and liberal tracking must be disabled as said.

#8 lore raw
Quoted 4 lines · Pablo Neira Ayuso
Quoted 4 lines
Quoted 4 lines

The documentation seems to be off here. If you only delete a ct entry, the next packet (even if a TCP ACK or something) will make a new ct with NEW as a ctstate.

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

To really have a TCP/SCTP connection blocked after deletion of the ct entry, you have to only allow NEW ctstates with the initla TCP/SCTP packet (SYN/INIT).

Yes, you need a well-formed stateful rule-set "to cut" the connection (at least you have to add a rule to block traffic in INVALID stats).

With "stats" I meant "state", and liberal tracking must be disabled as said.

Which is the default anyway. :-)

I think what was really meant was tcp_loose, not tcp_be_liberal. Anyway, I don't want to give bad hints. It's better to use a restrictive ruleset than tweaking sysctls.

#9 lore raw
Quoted 8 lines · Jan Engelhardt
Quoted 7 lines · Pablo Neira Ayuso
Quoted 7 lines
Quoted 7 lines

The documentation seems to be off here. If you only delete a ct entry, the next packet (even if a TCP ACK or something) will make a new ct with NEW as a ctstate.

To really have a TCP/SCTP connection blocked after deletion of the ct entry, you have to only allow NEW ctstates with the initla TCP/SCTP packet (SYN/INIT).

Jan made an interesting point. TCP conntrack has a liberal/strict sysctl, but I do not see any for SCTP conntrack. If I'm not mistaken, is SCTP conntrack of the liberal or strict kind ?

Quoted 7 lines
Quoted 3 lines
Quoted 2 lines

Yes, you need a well-formed stateful rule-set "to cut" the connection (at least you have to add a rule to block traffic in INVALID stats).

With "stats" I meant "state", and liberal tracking must be disabled as said.

Which is the default anyway. :-)

I think what was really meant was tcp_loose, not tcp_be_liberal.

In my understanding, tcp_loose only allows conntrack to pick up connections from the middle, but packets are still INVALID until the required number of packets is seen and accepted. Am I wrong ?

#10 lore raw
Quoted 5 lines · Pascal Hambourg
Quoted 1 line

I think what was really meant was tcp_loose, not tcp_be_liberal.

In my understanding, tcp_loose only allows conntrack to pick up connections from the middle, but packets are still INVALID until the required number of packets is seen and accepted. Am I wrong ?

No, the packets are set to the usual states, there's no packet counting.

With tcp_loose enabled (default) conntrack accepts non-SYN packets as "NEW" ones, i.e. attempts to pick up connections from the middle.

With tcp_be_liberal enabled (default is disabled) out of window packets are not marked as INVALID.

Best regards,
Jozsef
-
E-mail : [email protected], [email protected] PGP key : http://www.kfki.hu/~kadlec/pgp_public_key.txt
Address : KFKI Research Institute for Particle and Nuclear Physics

          H-1525 Budapest 114, POB. 49, Hungary
#11 lore raw
Quoted 8 lines · Jozsef Kadlecsik
Quoted 5 lines · Pascal Hambourg
Quoted 1 line

I think what was really meant was tcp_loose, not tcp_be_liberal.

In my understanding, tcp_loose only allows conntrack to pick up connections from the middle, but packets are still INVALID until the required number of packets is seen and accepted. Am I wrong ?

Quoted 7 lines

No, the packets are set to the usual states, there's no packet counting.

With tcp_loose enabled (default) conntrack accepts non-SYN packets as "NEW" ones, i.e. attempts to pick up connections from the middle.

With tcp_be_liberal enabled (default is disabled) out of window packets are not marked as INVALID.

And for grand completeness on the reader's behalf: an out-of-window packet can not occur if there is no previous ct entry (for the same tcp connection) whose window values could be compared to to see if there is an out-of-window condition.

#12 lore raw
Quoted 5 lines · Jan Engelhardt
Quoted 4 lines · Jozsef Kadlecsik

With tcp_loose enabled (default) conntrack accepts non-SYN packets as "NEW" ones, i.e. attempts to pick up connections from the middle.

Quoted 7 lines
Quoted 2 lines

With tcp_be_liberal enabled (default is disabled) out of window packets are not marked as INVALID.

And for grand completeness on the reader's behalf: an out-of-window packet can not occur if there is no previous ct entry (for the same tcp connection) whose window values could be compared to to see if there is an out-of-window condition.

Thanks to both of you for clarifying.

#13 lore raw
In reply to Jozsef Kadlecsik
Quoted 7 lines · Jozsef Kadlecsik
Quoted 4 lines · Pascal Hambourg
Quoted 1 line

I think what was really meant was tcp_loose, not tcp_be_liberal.

In my understanding, tcp_loose only allows conntrack to pick up connections from the middle, but packets are still INVALID until the required number of packets is seen and accepted. Am I wrong ?

Quoted 7 lines

No, the packets are set to the usual states, there's no packet counting.

With tcp_loose enabled (default) conntrack accepts non-SYN packets as "NEW" ones, i.e. attempts to pick up connections from the middle.

With tcp_be_liberal enabled (default is disabled) out of window packets are not marked as INVALID.

I have applied the following patch to the documentation based on this discussion. I have also uploaded a new version of the webpage.

doc: description on how to block traffic with conntrack was incomplete

From: Pablo Neira Ayuso <[email protected]>

This patch completes the documentation with the following discussion that took place in the mailing list.

http://marc.info/?l=netfilter&m=127335152521674&w=2

---
 doc/manual/conntrack-tools.tmpl |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
doc/manual/conntrack-tools.tmpl +7 -2
index b897318..ab4e5fb 100644
@@ -19,7 +19,7 @@
   </authorgroup>
 
   <copyright>
-   <year>2008</year>
+   <year>2008-2010</year>
    <holder>Pablo Neira Ayuso</holder>
   </copyright>
 
@@ -198,7 +198,12 @@ conntrack v0.9.7 (conntrack-tools): 1 flow entries have been shown.
 conntrack v0.9.7 (conntrack-tools): 1 flow entries has been updated.
  </programlisting>
 
-<para>Delete one entry, this can be used to block traffic (you have to set <emphasis>/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_be_liberal</emphasis> to zero).</para>
+<para>Delete one entry, this can be used to block traffic if:</para>
+<itemizedlist>
+ <listitem><para>You have a stateful rule-set that blocks traffic in INVALID state.</para></listitem>
+ <listitem><para>You have to set <emphasis>/proc/sys/net/ipv4/netfilter/ip_conntrack_tcp_loose</emphasis> or <emphasis>/proc/sys/net/netfilter/nf_conntrack_tcp_loose</emphasis>, depending on your kernel version, to zero.</para></listitem>
+</itemizedlist>
+
 <programlisting>
  # conntrack -D -p tcp --dport 3486
  tcp      6 431982 ESTABLISHED src=192.168.2.100 dst=123.59.27.117 sport=34846 dport=993 packets=169 bytes=14322 src=123.59.27.117 dst=192.168.2.100 sport=993 dport=34846 packets=113 bytes=34787 [ASSURED] mark=1 secmark=0 use=1
#14 lore raw
In reply to Richard Feng

Hello,

Quoted 9 lines · Richard Feng

I am using Linux 2.6.29. I have the problem for using 'conntrack' (version:0.9.14) to block the traffic.
Using the following command as example:
conntrack -D -s 1.1.1.1 -d 2.2.2.2
After execution, it appears the connection info was deleted -
conntrack -L | grep 1.1.1.1 -- shows the entry was deleted.

However, the connection is still active

What do you mean exactly ?
The conntrack tool only deals with netfilter connection tracking, not with the actual connection (e.g. it won't send RST's in order to tear it down). How it may affect the actual connection depends on the iptables ruleset.

#15 lore raw
Quoted 11 lines · Pascal Hambourg

Hello,

Quoted 8 lines · Richard Feng

I am using Linux 2.6.29. I have the problem for using 'conntrack' (version:0.9.14) to block the traffic.
Using the following command as example:
conntrack -D -s 1.1.1.1 -d 2.2.2.2
After execution, it appears the connection info was deleted -
conntrack -L | grep 1.1.1.1 -- shows the entry was deleted.

Quoted 8 lines
Quoted 1 line

However, the connection is still active

What do you mean exactly ?
The conntrack tool only deals with netfilter connection tracking, not with the actual connection (e.g. it won't send RST's in order to tear it down). How it may affect the actual connection depends on the iptables ruleset.

It says it can block traffic in the
document "http://conntrack-tools.netfilter.org/manual.html#conntrack". Maybe the doc is outdated? What should I do if I want to break current connection? Using 'cutter'?

#16 lore raw
Quoted 9 lines · Richard Feng
Quoted 6 lines · Pascal Hambourg

The conntrack tool only deals with netfilter connection tracking, not with the actual connection (e.g. it won't send RST's in order to tear it down). How it may affect the actual connection depends on the iptables ruleset.

It says it can block traffic in the
document "http://conntrack-tools.netfilter.org/manual.html#conntrack".

Do you mean this : "this can be used to block traffic" ?
It can be used to block traffic, but does not block traffic by itself. Subsequent packets of a deleted TCP connection will just be in the INVALID state, it is up to the iptables ruleset to drop such packets if this is what you want.

Quoted 1 line

What should I do if I want to break current connection? Using 'cutter'?

What do you want to achieve exactly ? Drop/reject subsequent packets ? Then see above, you need iptables. Or actively close the connection ? Then you need a tool such as cutter.

#17 lore raw
Quoted 6 lines · Pascal Hambourg

Do you mean this : "this can be used to block traffic" ?
It can be used to block traffic, but does not block traffic by itself. Subsequent packets of a deleted TCP connection will just be in the INVALID state, it is up to the iptables ruleset to drop such packets if this is what you want.

Quoted 6 lines
Quoted 1 line

What should I do if I want to break current connection? Using 'cutter'?

What do you want to achieve exactly ? Drop/reject subsequent packets ? Then see above, you need iptables. Or actively close the connection ? Then you need a tool such as cutter.

Thank you very much - I think that is the answer I am looking for.