kern/112147: Sometimes useless code in ip_dummynet, function find_queue

João Rocha Braga Filho goffredo at uol.com.br
Wed Apr 25 21:40:13 UTC 2007


>Number:         112147
>Category:       kern
>Synopsis:       Sometimes useless code 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 21:40:12 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 at 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:


More information about the freebsd-bugs mailing list