From nobody@FreeBSD.org  Wed Apr 25 21:34:54 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 64DC716A401
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Apr 2007 21:34:54 +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 48DC413C448
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Apr 2007 21:34:54 +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 l3PLYrw4089405
	for <freebsd-gnats-submit@FreeBSD.org>; Wed, 25 Apr 2007 21:34:53 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.13.1/8.13.1/Submit) id l3PLTqNb088669;
	Wed, 25 Apr 2007 21:29:52 GMT
	(envelope-from nobody)
Message-Id: <200704252129.l3PLTqNb088669@www.freebsd.org>
Date: Wed, 25 Apr 2007 21:29:52 GMT
From: Joo Rocha Braga Filho<goffredo@uol.com.br>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Sometimes useless code in ip_dummynet, function find_queue
X-Send-Pr-Version: www-3.0

>Number:         112147
>Category:       kern
>Synopsis:       [netinet] some ivp6-conditional code is always included, despite INET6 setting
>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 21:40:12 GMT 2007
>Closed-Date:    Fri Jan 04 02:05:22 UTC 2008
>Last-Modified:  Fri Jan 04 02:05:22 UTC 2008
>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: bms 
State-Changed-When: Fri 4 Jan 2008 02:03:33 UTC 
State-Changed-Why:  
This is a total non issue. 

The code which the submitter changes does not use any INET6 functions-- 
it's all macros, the v6 check could be a predicted branch, but overall 
the maintenance cost of dyking out the v6 support is far greater than any 
possible performance gain. 


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