From nobody@FreeBSD.org  Wed Apr 25 22:15:49 2007
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52])
	by hub.freebsd.org (Postfix) with ESMTP id 7665D16A402
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Apr 2007 22:15:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [69.147.83.33])
	by mx1.freebsd.org (Postfix) with ESMTP id 59C6113C484
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Apr 2007 22:15:49 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.13.1/8.13.1) with ESMTP id l3PMFnsT096002
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Apr 2007 22:15:49 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l3PMAlF6095213;
	Wed, 25 Apr 2007 22:10:47 GMT
	(envelope-from nobody)
Message-Id: <200704252210.l3PMAlF6095213@www.freebsd.org>
Date: Wed, 25 Apr 2007 22:10:47 GMT
From: Joo Rocha Braga Filho<goffredo@uol.com.br>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Sometimes useless code is executed in ip_dummynet, function find_queue
X-Send-Pr-Version: www-3.0

>Number:         112148
>Category:       kern
>Synopsis:       Sometimes useless code is executed in ip_dummynet, function find_queue
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 25 22:20:18 GMT 2007
>Closed-Date:    Wed Apr 25 22:23:05 GMT 2007
>Last-Modified:  Wed Apr 25 22:23:05 GMT 2007
>Originator:     Joo Rocha Braga Filho
>Release:        
>Organization:
Paratyinfo
>Environment:
FreeBSD staff.paratyinfo.com.br 6.2-STABLE FreeBSD 6.2-STABLE #2: Sat Apr 14 10:16:36 BRT 2007     root@goffredo.paratyinfo.com.br:/usr/obj/usr/src/sys/GOFFREDO  amd64
>Description:
In function find_queue there is some code to IPv6, but anyone can compile FreeBSD without IPv6, but this code will be there, even compiled without IPv6 support in kernel. The package will be tested if it is IPv6, even if the compiled kernel don't suport IPv6.

I know, the time lost is few, but I make this PR, and send a code to fix.

Thanks,
    Joo Rocha.


>How-To-Repeat:

>Fix:

/* If kernel supports IPv6 */

#ifdef INET6

/* Here is the function with IPv6 support. */

#else

/* New function version, without IPv6 suport. */

static struct dn_flow_queue *
find_queue(struct dn_flow_set *fs, struct ipfw_flow_id *id)
{
    int i = 0 ; /* we need i and q for new allocations */
    struct dn_flow_queue *q, *prev;

    if ( !(fs->flags_fs & DN_HAVE_FLOW_MASK) )
        q = fs->rq[0] ;
    else {
        /* first, do the masking, then hash */
        id->dst_port &= fs->flow_mask.dst_port ;
        id->src_port &= fs->flow_mask.src_port ;
        id->proto &= fs->flow_mask.proto ;
        id->flags = 0 ; /* we don't care about this one */
        id->dst_ip &= fs->flow_mask.dst_ip ;
        id->src_ip &= fs->flow_mask.src_ip ;

        i = (   ( (id->dst_ip) & 0xffff ) ^
                ( (id->dst_ip >> 15) & 0xffff ) ^
                ( (id->src_ip << 1) & 0xffff ) ^
                ( (id->src_ip >> 16 ) & 0xffff ) ^
                (id->dst_port << 1) ^ (id->src_port) ^
                (id->proto )
             ) % fs->rq_size ;

        /* finally, scan the current list for a match */
        searches++ ;
        for (prev=NULL, q = fs->rq[i] ; q ; ) {
            search_steps++;
            if (    id->dst_ip == q->id.dst_ip &&
                    id->src_ip == q->id.src_ip &&
                    id->dst_port == q->id.dst_port &&
                    id->src_port == q->id.src_port &&
                    id->proto == q->id.proto &&
                    id->flags == q->id.flags)
                break ; /* found */

            /* No match. Check if we can expire the entry */
            if (pipe_expire && q->head == NULL && q->S == q->F+1 ) {
                /* entry is idle and not in any heap, expire it */
                struct dn_flow_queue *old_q = q ;

                if (prev != NULL)
                    prev->next = q = q->next ;
                else
                    fs->rq[i] = q = q->next ;
                fs->rq_elements-- ;
                free(old_q, M_DUMMYNET);
                continue ;
            }
            prev = q ;
            q = q->next ;
        }
        if (q && prev != NULL) { /* found and not in front */
            prev->next = q->next ;
            q->next = fs->rq[i] ;
            fs->rq[i] = q ;
        }
    }
    if (q == NULL) { /* no match, need to allocate a new entry */
        q = create_queue(fs, i);
        if (q != NULL)
        q->id = *id ;
    }
    return q ;
}

#endif

>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed 
State-Changed-By: linimon 
State-Changed-When: Wed Apr 25 22:22:33 UTC 2007 
State-Changed-Why:  
Duplicate of kern/112146. 

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