From nobody@FreeBSD.org  Fri Feb 22 17:38:10 2008
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id A0EC916A400
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Feb 2008 17:38:10 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id 992E213C46A
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Feb 2008 17:38:10 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.2/8.14.2) with ESMTP id m1MHZX6W074238
	for <freebsd-gnats-submit@FreeBSD.org>; Fri, 22 Feb 2008 17:35:33 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.2/8.14.1/Submit) id m1MHZXm7074237;
	Fri, 22 Feb 2008 17:35:33 GMT
	(envelope-from nobody)
Message-Id: <200802221735.m1MHZXm7074237@www.freebsd.org>
Date: Fri, 22 Feb 2008 17:35:33 GMT
From: Mykola Dzham <i@levsha.org.ua>
To: freebsd-gnats-submit@FreeBSD.org
Subject: [patch] bsnmpd snmp_pf module work incorrect when DIOCGETALTQ return queue list not in qid order
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         120974
>Category:       bin
>Synopsis:       [patch] bsnmpd(1) snmp_pf module work incorrect when DIOCGETALTQ return queue list not in qid order
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    philip
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Fri Feb 22 17:40:01 UTC 2008
>Closed-Date:    Sun Jun 01 14:10:13 UTC 2008
>Last-Modified:  Wed Jun  4 09:10:01 UTC 2008
>Originator:     Mykola Dzham
>Release:        7.0-RC1
>Organization:
>Environment:
FreeBSD ruslan 7.0-RC1 FreeBSD 7.0-RC1 #0: Tue Jan 15 21:48:25 EET 2008     levsha@notebook.levsha.org.ua:/usr/obj/nanobsd.full/usr/src/sys/NANOBSD  i386
>Description:
bsnmpd pf_snmp module use code:
for (i = 0; i < numqs; i++) {
 ...
 pa.nr = i;
 ioctl(dev, DIOCGETALTQ, &pa)
 ...
}
to request queue list from kernel, then use pa.altq.qid as queue id.
Kernel can return queue list not in pa.altq.qid order. If this occur,
then snmpwalk return only part of queue list.
>How-To-Repeat:
Use small program to test queue order, returned from kernel:
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/fcntl.h>
#include <net/if.h>
#include <netinet/in.h>
#include <net/pfvar.h>
#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#include <errno.h>

int main(int argc, char *argv[])
{
        int dev;
        struct pfioc_altq pa;
        int i, numqs, ticket;

        dev = open("/dev/pf", O_RDWR);
        if (dev == -1)
                err(1, "open(\"/dev/pf\") failed");

        bzero(&pa, sizeof(pa));
        if (ioctl(dev, DIOCGETALTQS, &pa)) {
                err(1, "ioctl(DIOCGETALTQS): %s", strerror(errno));
        }
        numqs = pa.nr;
        ticket = pa.ticket;
        for (i = 0; i < numqs; i++) {
                pa.ticket = ticket;
                pa.nr = i;
                if (ioctl(dev, DIOCGETALTQ, &pa)) {
                        err(1,"ioctl(DIOCGETALTQ): %s", strerror(errno));
                }
                if (pa.altq.qid > 0) {
                        printf("%d: %s\n", pa.altq.qid, pa.altq.qname);
                }
        }
        return 0;
}
If program return all queue list, but not in pa.altq.qid order, then
you can reproduce problem: snmpwalk ... .1.3.6.1.4.1.12325.1.200.1.10
return only part of tree
>Fix:
Use INSERT_OBJECT_INT_LINK_INDEX macro instead of TAILQ_INSERT_TAIL
(patch attached)

Patch attached with submission follows:

--- pf_snmp.c.orig	2008-02-22 19:01:50.000000000 +0200
+++ pf_snmp.c	2008-02-22 19:10:27.000000000 +0200
@@ -1025,7 +1025,7 @@
 			memcpy(&e->altq, &pa.altq, sizeof(struct pf_altq));
 			e->index = pa.altq.qid;
 			pfq_table_count = i;
-			TAILQ_INSERT_TAIL(&pfq_table, e, link);
+			INSERT_OBJECT_INT_LINK_INDEX(e, &pfq_table, link, index);
 		}
 	}
 	


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-pf 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sat Feb 23 01:16:52 UTC 2008 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120974 
Responsible-Changed-From-To: freebsd-pf->philip 
Responsible-Changed-By: philip 
Responsible-Changed-When: Tue Mar 4 06:50:06 UTC 2008 
Responsible-Changed-Why:  
I'll take this one.  I have some more snmp_pf work in the pipeline. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120974 
State-Changed-From-To: open->closed 
State-Changed-By: philip 
State-Changed-When: Sun Jun 1 14:10:12 UTC 2008 
State-Changed-Why:  
Committed. Thanks! 

http://www.freebsd.org/cgi/query-pr.cgi?pr=120974 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120974: commit references a PR
Date: Sun,  1 Jun 2008 14:10:10 +0000 (UTC)

 philip      2008-06-01 14:10:01 UTC
 
   FreeBSD src repository
 
   Modified files:
     usr.sbin/bsnmpd/modules/snmp_pf pf_snmp.c 
   Log:
   SVN rev 179476 on 2008-06-01 14:09:54Z by philip
   
   Use INSERT_OBJECT_INT_LINK_INDEX macro instead of TAILQ_INSERT_TAIL when
   filling the table of ALTQ queues retrieved from the kernel.
   
   It is possible for the kernel to return the queues not by pa.altq.qid order.
   When this happens, pf_snmp would only partially fill its table.
   
   PR:             bin/120974
   Submitted by:   Mykola Dzham <i -at- levsha.org.ua>
   MFC after:      3 days
   
   Revision  Changes    Path
   1.9       +1 -1      src/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: bin/120974: commit references a PR
Date: Wed,  4 Jun 2008 09:04:34 +0000 (UTC)

 philip      2008-06-04 08:55:59 UTC
 
   FreeBSD src repository
 
   Modified files:        (Branch: RELENG_7)
     usr.sbin/bsnmpd/modules/snmp_pf pf_snmp.c 
   Log:
   SVN rev 179540 on 2008-06-04 08:55:49Z by philip
   
   MFC r179476:
   
     Use INSERT_OBJECT_INT_LINK_INDEX macro instead of TAILQ_INSERT_TAIL when
     filling the table of ALTQ queues retrieved from the kernel.
   
     It is possible for the kernel to return the queues not by pa.altq.qid order.
     When this happens, pf_snmp would only partially fill its table.
   
   PR:             bin/120974
   Submitted by:   Mykola Dzham <i -at- levsha.org.ua>
   
   Revision  Changes    Path
   1.8.2.1   +1 -1      src/usr.sbin/bsnmpd/modules/snmp_pf/pf_snmp.c
 _______________________________________________
 cvs-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/cvs-all
 To unsubscribe, send any mail to "cvs-all-unsubscribe@freebsd.org"
 
>Unformatted:
