From madmax@solo.peterlink.ru  Tue Apr 22 03:52:49 2003
Return-Path: <madmax@solo.peterlink.ru>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 78C6037B401
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 22 Apr 2003 03:52:49 -0700 (PDT)
Received: from solo.peterlink.ru (solo.peterlink.ru [195.242.2.178])
	by mx1.FreeBSD.org (Postfix) with ESMTP id CDDB943FD7
	for <FreeBSD-gnats-submit@freebsd.org>; Tue, 22 Apr 2003 03:52:48 -0700 (PDT)
	(envelope-from madmax@solo.peterlink.ru)
Received: from madmax by solo.peterlink.ru with local (Exim 4.12)
	id 197vOJ-000B6M-00
	for FreeBSD-gnats-submit@freebsd.org; Tue, 22 Apr 2003 14:52:47 +0400
Message-Id: <E197vOJ-000B6M-00@solo.peterlink.ru>
Date: Tue, 22 Apr 2003 14:52:47 +0400
From: Kozin Maxim V. <maxes@peterlink.ru>
Sender: "Kozin Maxim V.,a,b,b,d" <madmax@solo.peterlink.ru>
Reply-To: Kozin Maxim V. <maxes@peterlink.ru>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ipfw2 create dynamic rules with parent number 65535
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         51274
>Category:       kern
>Synopsis:       [ipfw] [patch] ipfw2 create dynamic rules with parent number 65535
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    freebsd-ipfw
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Apr 22 04:00:30 PDT 2003
>Closed-Date:    Wed Jun 01 11:45:54 UTC 2011
>Last-Modified:  Wed Jun 01 11:45:54 UTC 2011
>Originator:     Kozin Maxim
>Release:        FreeBSD 4.7-RELEASE-p7 i386
>Organization:
maxes@peterlink.ru
>Environment:
System: FreeBSD 4.7-RELEASE-p7 i386

>Description:
IPFW2 limut src-addr rule incorrect denied some clinets.

>How-To-Repeat:
Use rule:
	ipfw add 01 allow tcp from any to me 80 setup limit src-addr 20	
On production serer with large number concurent connection to httpd, 
run command:
ipfw -d sh | grep PARENT | sort -nk6
After some time, You can see result like this:
00020          0          0 (2s) PARENT 3 tcp 1.2.3.4 0 <-> 0.0.0.0 0
00020          0          0 (0s) PARENT 4 tcp 1.2.3.5 0 <-> 0.0.0.0 0
00020          0          0 (0s) PARENT 4 tcp 1.2.3.6 0 <-> 0.0.0.0 0
00020          0          0 (0s) PARENT 5 tcp 1.2.3.7 0 <-> 0.0.0.0 0
00020          0          0 (0s) PARENT 65532 tcp 2.2.3.9 0 <-> 0.0.0.0 0
00020          0          0 (0s) PARENT 65534 tcp 2.2.3.10 0 <-> 0.0.0.0 0

Host 2.2.3.9 and 2.2.3.10 blocked by ipfw, but 
ipfw -d sh | grep LIMIT | grep "2.2.3." show nothing.
Host 2.2.3.9 and 2.2.3.10 was blocked incorrectly. 
After some time (10-60 sec.) records "PARENT 65532" and "PARENT 65534" go away.
On  httpd with 20-30 req/sec and with simultaneously 70-120 distinct IP, 
number of blocked client may be varied from 1 to 10. 

>Fix:
As workaround I use next patch:
/usr/src/sys/netinet/ip_fw2.c:
     $FreeBSD: src/sys/netinet/ip_fw2.c,v 1.6.2.3 2002/08/21 05:34:07 luigi Exp
$

--- /usr/src/sys/netinet/ip_fw2.c.old      Wed Aug 21 09:34:07 2002
+++ /usr/src/sys/netinet/ip_fw2.c          Wed Mar 19 16:20:54 2003
@@ -617,7 +617,7 @@
        ipfw_dyn_rule *old_q = q;                                       \
                                                                        \
        /* remove a refcount to the parent */                           \
-       if (q->dyn_type == O_LIMIT)                                     \
+       if ((q->dyn_type == O_LIMIT) && (q->parent->count !=0))         \
                q->parent->count--;                                     \
        DEB(printf("-- unlink entry 0x%08x %d -> 0x%08x %d, %d left\n", \
                (q->id.src_ip), (q->id.src_port),                       \

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->ipfw 
Responsible-Changed-By: johan 
Responsible-Changed-When: Tue May 6 12:50:16 PDT 2003 
Responsible-Changed-Why:  
Over to maintainer group. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51274 
State-Changed-From-To: open->closed 
State-Changed-By: ae 
State-Changed-When: Wed Jun 1 11:44:16 UTC 2011 
State-Changed-Why:  
This problem was fixed 7 years ago with rev 1.40. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=51274 
>Unformatted:
