Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 25 Apr 2007 22:10:47 GMT
From:      Joćo Rocha Braga Filho<goffredo@uol.com.br>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   kern/112148: Sometimes useless code is executed in ip_dummynet, function find_queue
Message-ID:  <200704252210.l3PMAlF6095213@www.freebsd.org>
Resent-Message-ID: <200704252220.l3PMKIBO063966@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>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:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Wed Apr 25 22:20:18 GMT 2007
>Closed-Date:
>Last-Modified:
>Originator:     Joćo 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,
    Joćo 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:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704252210.l3PMAlF6095213>