Skip to contentSkip to conversation

Fix connlimit bug when receive RST packet in ESTABLISHED state

PATCH Applied Dong Wei 3 participants 7 messages Jun 2, 2008

Subsystems (2)
lore
Share & tools
lore

Dong Wei

author
#0 lore raw

PATCH 1/1 Fix connlimit bug when receive RST packet in ESTABLISHED state

Hi, all
In xt_connlimit match module, the counter of an IP is decreased when
the TCP packet is go through the chain with ip_conntrack state TW. Well, it's very natural that the server and client close the socket with FIN packet. But when the client/server close the socket with RST packet(using so_linger), the counter for this connection still exsit. The following patch can fix it which is based on linux-2.6.25.4

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +2 -1
diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
@@ -75,7 +75,8 @@
        u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
        if (proto == IPPROTO_TCP)
-               return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+               return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+                       || conn->proto.tcp.state == TCP_CONNTRACK_CLOSE);
        else
                return 0;
 }
net/netfilter/xt_connlimit.c +2 -1
diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
@@ -75,7 +75,8 @@
 	u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
 	if (proto == IPPROTO_TCP)
-		return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+		return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+		        || conn->proto.tcp.state == TCP_CONNTRACK_CLOSE);
 	else
 		return 0;
 }
#1 lore raw
Quoted 12 lines · Dong Wei

Hi, all
In xt_connlimit match module, the counter of an IP is decreased when
the TCP packet is go through the chain with ip_conntrack state TW. Well, it's very natural that the server and client close the socket with FIN packet. But when the client/server close the socket with RST packet(using so_linger), the counter for this connection still exsit. The following patch can fix it which is based on linux-2.6.25.4

diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 line 79

Quoted 6 lines
net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +2 -1
@@ -75,7 +75,8 @@
        u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
        if (proto == IPPROTO_TCP)
-               return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+               return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+                       || conn->proto.tcp.state == TCP_CONNTRACK_CLOSE);

Looks fine to me. Jan?

#2 lore raw
Quoted 15 lines · Patrick McHardy
Quoted 14 lines · Dong Wei

Hi, all
In xt_connlimit match module, the counter of an IP is decreased when
the TCP packet is go through the chain with ip_conntrack state TW. Well, it's very natural that the server and client close the socket with FIN packet. But when the client/server close the socket with RST packet(using so_linger), the counter for this connection still exsit. The following patch can fix it which is based on linux-2.6.25.4

diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +0 -0
@@ -75,7 +75,8 @@
        u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
Quoted 6 lines

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 line 79

Quoted 4 lines
net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +2 -1
        if (proto == IPPROTO_TCP)
-               return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+               return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+                       || conn->proto.tcp.state == TCP_CONNTRACK_CLOSE);

Looks fine to me. Jan?

The check for TCP_CONNTRACK_TIME_WAIT was introduced since there is the 2*MSL delay before the TIME_WAIT->CLOSED transition, and not counting a connection beginning with TIME_WAIT is common sense/what people expect.

Though the cleanup delay between TCP_CONNTRACK_CLOSE and (deallocated state) is much less than 2*MSL, it makes sense to also add this case per common sense.

Patch is fine, yes, but you do not need the redundant ( ) that were introduced.

#3 lore raw
Quoted 14 lines · Jan Engelhardt
Quoted 7 lines · Patrick McHardy
Quoted 6 lines · Dong Wei

diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +0 -0
@@ -75,7 +75,8 @@
        u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
Quoted 5 lines

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 line 79

Quoted 4 lines
net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +2 -1
        if (proto == IPPROTO_TCP)
-               return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+               return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+                       || conn->proto.tcp.state == TCP_CONNTRACK_CLOSE);

Looks fine to me. Jan?

Quoted 4 lines

The check for TCP_CONNTRACK_TIME_WAIT was introduced since there is the 2*MSL delay before the TIME_WAIT->CLOSED transition, and not counting a connection beginning with TIME_WAIT is common sense/what people expect.

Yes, though the end-result might not be what people expect. The connection can be reopened, exceeding the configured limit, and lots of TIME_WAIT/CLOSE connections might linger around.

Quoted 6 lines

Though the cleanup delay between TCP_CONNTRACK_CLOSE and (deallocated state) is much less than 2*MSL, it makes sense to also add this case per common sense.

Patch is fine, yes, but you do not need the redundant ( ) that were introduced.

I'll remove them when applying the patch.

Dong, I need a Signed-off-by: line from you before I can apply this.

author
#4 lore raw

Hi, Jan

My Signed-off-by message is:

Thanks

Quoted 43 lines · Patrick McHardy
Quoted 21 lines · Jan Engelhardt
Quoted 11 lines · Patrick McHardy
Quoted 9 lines · Dong Wei

diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
--- a/net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000
+0800
+++ b/net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000
+0800

(quoted diff) +0 -0
@@ -75,7 +75,8 @@
       u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
Quoted 7 lines

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800

Quoted 5 lines
net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +2 -1
       if (proto == IPPROTO_TCP)
-               return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+               return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+                       || conn->proto.tcp.state ==
 TCP_CONNTRACK_CLOSE);

Looks fine to me. Jan?

Quoted 4 lines

The check for TCP_CONNTRACK_TIME_WAIT was introduced since there is the 2*MSL delay before the TIME_WAIT->CLOSED transition, and not counting a connection beginning with TIME_WAIT is common sense/what people expect.

Yes, though the end-result might not be what people expect. The connection can be reopened, exceeding the configured limit, and lots of TIME_WAIT/CLOSE connections might linger around.

Quoted 6 lines

Though the cleanup delay between TCP_CONNTRACK_CLOSE and (deallocated state) is much less than 2*MSL, it makes sense to also add this case per common sense.

Patch is fine, yes, but you do not need the redundant ( ) that were introduced.

I'll remove them when applying the patch.

Dong, I need a Signed-off-by: line from you before I can apply this.

#6 lore raw
In reply to Patrick McHardy
Quoted 11 lines · Patrick McHardy
Quoted 10 lines · Jan Engelhardt
Quoted 9 lines · Patrick McHardy
Quoted 8 lines · Dong Wei

diff -ruN a/net/netfilter/xt_connlimit.c b/net/netfilter/xt_connlimit.c
--- a/net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000
+0800
+++ b/net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000
+0800

(quoted diff) +0 -0
@@ -75,7 +75,8 @@
        u_int16_t proto = conn->tuplehash[0].tuple.dst.protonum;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 line 79

Quoted 4 lines
net/netfilter/xt_connlimit.c 2008-06-02 18:50:40.000000000 +0800 renamed from net/netfilter/xt_connlimit.c 2008-06-02 18:48:38.000000000 +0800 +2 -1
        if (proto == IPPROTO_TCP)
-               return conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT;
+               return (conn->proto.tcp.state == TCP_CONNTRACK_TIME_WAIT
+                       || conn->proto.tcp.state == TCP_CONNTRACK_CLOSE);

Looks fine to me. Jan?