Skip to contentSkip to conversation

connlimit problem

DISCUSSION Jean-Philippe Menil 4 participants 8 messages Sep 9, 2011

lore
Share & tools
lore
#0 lore raw

Hi,

I try to limit the connection per ip with connlimit in addition to the socket match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket -m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules never match:

    0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     
0.0.0.0/0            tcp dpt:80flags: 0x17/0x02 socket #conn src/32 > 1
    9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24     
0.0.0.0/0            tcp dpt:80 socket
    5   216 TPROXY     tcp  --  *      *       192.168.100.0/24     
0.0.0.0/0            tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1
    0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     
0.0.0.0/0            tcp dpt:3128flags: 0x17/0x02 socket #conn src/32 > 1
    6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24     

0.0.0.0/0 tcp dpt:3128 socket
19 800 TPROXY tcp -- * * 192.168.100.0/24
0.0.0.0/0 tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Is this an expected behaviour, or a problem in my rules?

Regards

Signature · 4 lines
Jean-Philippe Menil - Pôle réseau Service IRTS
DSI Université de Nantes
[email protected]
Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09
#1 lore raw

2011/9/9 Jean-Philippe Menil <[email protected]>:

Quoted 22 lines

Hi,

I try to limit the connection per ip with connlimit in addition to the socket match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket -m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules  never match:

   0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:80flags: 0x17/0x02 socket #conn src/32 > 1
   9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:80 socket
   5   216 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1 0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:3128flags: 0x17/0x02 socket #conn src/32 > 1 6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:3128 socket
  19   800 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Quoted 2 lines

Is this an expected behaviour, or a problem in my rules?

I think it's because the PREROUTING table has no concept of connection (conntrack has not started yet), so the number of connection(s) stays at zero.

Of course, I might be wrong. Someone please CMIIW.

Rgds,

Signature · 6 lines
FdS Pandu E Poluan
~ IT Optimizer ~

 • LOPSA Member #15248
 • Blog : http://pepoluan.tumblr.com
 • Linked-In : http://id.linkedin.com/in/pepoluan
#2 lore raw
Quoted 23 lines · Pandu Poluan

2011/9/9 Jean-Philippe Menil <[email protected]>:

Quoted 22 lines

Hi,

I try to limit the connection per ip with connlimit in addition to the socket match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket -m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules  never match:

   0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:80flags: 0x17/0x02 socket #conn src/32 > 1
   9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:80 socket
   5   216 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1 0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:3128flags: 0x17/0x02 socket #conn src/32 > 1 6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:3128 socket
  19   800 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0 tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Quoted 8 lines
Quoted 2 lines

Is this an expected behaviour, or a problem in my rules?

I think it's because the PREROUTING table has no concept of connection (conntrack has not started yet), so the number of connection(s) stays at zero.

Of course, I might be wrong. Someone please CMIIW.

Indeed your assessment is false.

#3 lore raw
In reply to Jean-Philippe Menil
Quoted 16 lines · Jean-Philippe Menil

I try to limit the connection per ip with connlimit in addition to the socket match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket -m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules never match:

    0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:80flags: 0x17/0x02 socket #conn src/32 > 1
    9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:80 socket
    5   216 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1
    0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:3128flags: 0x17/0x02 socket #conn src/32 > 1
    6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
Quoted 5 lines

tcp dpt:3128 socket
19 800 TPROXY tcp -- * * 192.168.100.0/24 0.0.0.0/0
tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Is this an expected behaviour, or a problem in my rules?

You use the socket match from the PREROUTING chain, where it'll never
match: it's before routing, so the the system could not associate the packet to a socket yet.

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
#4 lore raw
Quoted 22 lines · Jozsef Kadlecsik
Quoted 20 lines · Jean-Philippe Menil

I try to limit the connection per ip with connlimit in addition to the socket match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket -m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules never match:

     0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:80flags: 0x17/0x02 socket #conn src/32>  1
     9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:80 socket
     5   216 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1
     0     0 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:3128flags: 0x17/0x02 socket #conn src/32>  1
     6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0
tcp dpt:3128 socket
    19   800 TPROXY     tcp  --  *      *       192.168.100.0/24     0.0.0.0/0

tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Quoted 7 lines
Quoted 1 line

Is this an expected behaviour, or a problem in my rules?

You use the socket match from the PREROUTING chain, where it'll never
match: it's before routing, so the the system could not associate the packet to a socket yet.

Best regards,
Jozsef

Ok, i see.
So, if my understand is correct, it will be better to do like this:

$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --dport http -m socket -j DIVERT
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --dport http -j TPROXY --tproxy-mark 0x1/0x1 --on-port 50080

$IPTABLES -t mangle -N DIVERT
$IPTABLES -t mangle -A DIVERT -j MARK --set-mark 1
$IPTABLES -t mangle -A DIVERT -m connlimit --connlimit-above 2 -j LOG --log-prefix "CONNLIMIT " $IPTABLES -t mangle -A DIVERT -m connlimit ! --connlimit-above 2 -j ACCEPT

Regards.

Signature · 4 lines
Jean-Philippe Menil - Pôle réseau Service IRTS
DSI Université de Nantes
[email protected]
Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09
#5 lore raw
Quoted 36 lines · Jean-Philippe Menil
Quoted 35 lines · Jozsef Kadlecsik
Quoted 25 lines · Jean-Philippe Menil

I try to limit the connection per ip with connlimit in addition to the socket
match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket
-m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules never match:

     0     0 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80flags: 0x17/0x02 socket #conn src/32>  1
     9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80 socket
     5   216 TPROXY     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1
     0     0 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:3128flags: 0x17/0x02 socket #conn src/32>  1
     6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:3128 socket
    19   800 TPROXY     tcp  --  *      *       192.168.100.0/24
Quoted 4 lines

0.0.0.0/0
tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Is this an expected behaviour, or a problem in my rules?

You use the socket match from the PREROUTING chain, where it'll never
match: it's before routing, so the the system could not associate the packet to a socket yet.

Quoted 6 lines
Quoted 2 lines

Best regards,
Jozsef

Ok, i see.
So, if my understand is correct, it will be better to do like this:

$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --dport http -m socket -j

                         ^^^^^^^^^^                             ^^^^^^^^^

Here again....

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
#6 lore raw
Quoted 43 lines · Jozsef Kadlecsik
Quoted 41 lines · Jean-Philippe Menil
Quoted 30 lines · Jozsef Kadlecsik
Quoted 28 lines · Jean-Philippe Menil

I try to limit the connection per ip with connlimit in addition to the socket
match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket
-m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules never match:

      0     0 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80flags: 0x17/0x02 socket #conn src/32>   1
      9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80 socket
      5   216 TPROXY     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1
      0     0 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:3128flags: 0x17/0x02 socket #conn src/32>   1
      6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:3128 socket
     19   800 TPROXY     tcp  --  *      *       192.168.100.0/24

0.0.0.0/0
tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Quoted 7 lines
Quoted 1 line

Is this an expected behaviour, or a problem in my rules?

You use the socket match from the PREROUTING chain, where it'll never
match: it's before routing, so the the system could not associate the packet to a socket yet.

Best regards,
Jozsef

Ok, i see.
So, if my understand is correct, it will be better to do like this:

Quoted 7 lines
Quoted 1 line

$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --dport http -m socket -j

                          ^^^^^^^^^^                             ^^^^^^^^^

Here again....

Best regards,
Jozsef
-

No, it's working as expected.
I have just followed the documentation in:
Documentation/networking/tproxy.txt

Regards.

Signature · 4 lines
Jean-Philippe Menil - Pôle réseau Service IRTS
DSI Université de Nantes
[email protected]
Tel : 02.53.48.49.27 - Fax : 02.53.48.49.09
#7 lore raw
Quoted 42 lines · Jean-Philippe Menil
Quoted 41 lines · Jozsef Kadlecsik
Quoted 39 lines · Jean-Philippe Menil
Quoted 30 lines · Jozsef Kadlecsik
Quoted 28 lines · Jean-Philippe Menil

I try to limit the connection per ip with connlimit in addition to the socket
match, with the following rule:
$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --syn --dport http -m socket
-m connlimit --connlimit-above 0 -j DIVERT

But as you can see, theses rules never match:

      0     0 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80flags: 0x17/0x02 socket #conn src/32>   1
      9  3030 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80 socket
      5   216 TPROXY     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:80 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1
      0     0 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:3128flags: 0x17/0x02 socket #conn src/32>   1
      6  2491 DIVERT     tcp  --  *      *       192.168.100.0/24
0.0.0.0/0
tcp dpt:3128 socket
     19   800 TPROXY     tcp  --  *      *       192.168.100.0/24

0.0.0.0/0
tcp dpt:3128 TPROXY redirect 0.0.0.0:50080 mark 0x1/0x1

Quoted 5 lines
Quoted 1 line

Is this an expected behaviour, or a problem in my rules?

You use the socket match from the PREROUTING chain, where it'll never
match: it's before routing, so the the system could not associate the packet to a socket yet.

Ok, i see.
So, if my understand is correct, it will be better to do like this:

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

$IPTABLES -t mangle -A PREROUTING -s $LAN -p tcp --dport http -m socket -j

                          ^^^^^^^^^^                             ^^^^^^^^^

Here again....

No, it's working as expected.
I have just followed the documentation in:
Documentation/networking/tproxy.txt

OK, the socket match not only checks but lookups the matching sockets. So it does indeed work from the PREROUTING chain.

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