From pm@zin.lublin.pl  Wed Aug 11 16:35:40 2004
Return-Path: <pm@zin.lublin.pl>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id E53B916A4CE
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 11 Aug 2004 16:35:39 +0000 (GMT)
Received: from shellma.zin.lublin.pl (shellma.zin.lublin.pl [212.182.126.68])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 2B63243D1D
	for <FreeBSD-gnats-submit@freebsd.org>; Wed, 11 Aug 2004 16:35:37 +0000 (GMT)
	(envelope-from pm@zin.lublin.pl)
Received: by shellma.zin.lublin.pl (Postfix, from userid 1018)
	id E06283474C2; Wed, 11 Aug 2004 18:34:26 +0200 (CEST)
Message-Id: <20040811163426.E06283474C2@shellma.zin.lublin.pl>
Date: Wed, 11 Aug 2004 18:34:26 +0200 (CEST)
From: Pawel Malachowski <pawmal-posting@freebsd.lublin.pl>
Reply-To: Pawel Malachowski <pawmal-posting@freebsd.lublin.pl>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: ipfw(8) pipe/queue show N displays data not only for N
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         70311
>Category:       bin
>Synopsis:       ipfw(8) pipe/queue show N displays data not only for N
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    pjd
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Wed Aug 11 16:40:37 GMT 2004
>Closed-Date:    Mon Nov 08 18:47:54 GMT 2004
>Last-Modified:  Tue Nov  9 19:30:24 GMT 2004
>Originator:     Pawe Maachowski
>Release:        FreeBSD 4.10-STABLE i386
>Organization:
ZiN
>Environment:
FreeBSD 4.10-STABLE #7: Tue Jul 27 18:06:15 CEST 2004
with IPFW2 (same with IPFW1 I guess).
>Description:
`ipfw pipe  show N' displays data for  pipe N  and *all queues*.
`ipfw queue show N' displays data for *pipe N* and *all queues*.

*x* == x is incorrect.

>How-To-Repeat:

% ipfw pipe 998 config bw 2Mbit/s
% ipfw queue 999 config weight 1 pipe 998
// Define other pipes and queues if You want.

% ipfw pipe show 998
// Shows pipe 998 and all queues in system.

% ipfw pipe show 999
// Shows no pipes (there is no pipe 999) and all queues in system.

% ipfw queue show 999
// Shows no pipes and all queues in system.

% ipfw queue show 998
// Shows pipe 998 (there is no queue 998) and all queues in system.

>Fix:

Patch against 4.10-STABLE/IPFW2. Two versions (I prefer second one
because it is more useful in real environment).

1. After patching:
`ipfw pipe  show N' displays data for pipe N and no queues.
`ipfw queue show N' displays data for queue N and no pipes.


*** /usr/src/sbin/ipfw/ipfw2.c.orig     Wed Aug 11 18:08:27 2004
--- /usr/src/sbin/ipfw/ipfw2.c  Wed Aug 11 18:08:34 2004
***************
*** 1498,1504 ****
                next = (char *)p + l;
                nbytes -= l;

!               if (rulenum != 0 && rulenum != p->pipe_nr)
                        continue;

                /*
--- 1498,1504 ----
                next = (char *)p + l;
                nbytes -= l;

!               if ( (rulenum != 0 && rulenum != p->pipe_nr) || (do_pipe==2) )
                        continue;

                /*
***************
*** 1532,1537 ****
--- 1532,1541 ----
                l = sizeof(*fs) + fs->rq_elements * sizeof(*q);
                next = (char *)fs + l;
                nbytes -= l;
+
+               if ( (rulenum != 0 && rulenum != fs->fs_nr) || (do_pipe==1) )
+                       continue;
+
                q = (struct dn_flow_queue *)(fs+1);
                sprintf(prefix, "q%05d: weight %d pipe %d ",
                    fs->fs_nr, fs->weight, fs->parent_nr);



2. After patching:
`ipfw pipe  show N' displays data for pipe N and queues with parentpipe=N.
`ipfw queue show N' displays data for queue N and no pipes.

*** /usr/src/sbin/ipfw/ipfw2.c.orig     Wed Aug 11 18:08:27 2004
--- /usr/src/sbin/ipfw/ipfw2.c  Wed Aug 11 18:27:21 2004
***************
*** 1498,1504 ****
                next = (char *)p + l;
                nbytes -= l;

!               if (rulenum != 0 && rulenum != p->pipe_nr)
                        continue;

                /*
--- 1498,1504 ----
                next = (char *)p + l;
                nbytes -= l;

!               if ( (rulenum != 0 && rulenum != p->pipe_nr) || (do_pipe==2) )
                        continue;

                /*
***************
*** 1532,1537 ****
--- 1532,1542 ----
                l = sizeof(*fs) + fs->rq_elements * sizeof(*q);
                next = (char *)fs + l;
                nbytes -= l;
+
+               if (rulenum != 0 && ((rulenum != fs->fs_nr && do_pipe==2)
+               || (rulenum != fs->parent_nr && do_pipe==1)))
+                       continue;
+
                q = (struct dn_flow_queue *)(fs+1);
                sprintf(prefix, "q%05d: weight %d pipe %d ",
                    fs->fs_nr, fs->weight, fs->parent_nr);

>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->pjd 
Responsible-Changed-By: pjd 
Responsible-Changed-When: Mon Aug 23 16:39:32 GMT 2004 
Responsible-Changed-Why:  
I'll take this one. 

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

From: Pawel Jakub Dawidek <pjd@FreeBSD.org>
To: Pawel Malachowski <pawmal-posting@freebsd.lublin.pl>
Cc: FreeBSD-gnats-submit@FreeBSD.org, freebsd-ipfw@freebsd.org
Subject: Re: bin/70311: ipfw(8) pipe/queue show N displays data not only for N
Date: Mon, 23 Aug 2004 18:57:18 +0200

 --7vS62bsm3BVGCDKV
 Content-Type: text/plain; charset=iso-8859-2
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Wed, Aug 11, 2004 at 06:34:26PM +0200, Pawel Malachowski wrote:
 +> 2. After patching:
 +> `ipfw pipe  show N' displays data for pipe N and queues with parentpipe=
 =3DN.
 +> `ipfw queue show N' displays data for queue N and no pipes.
 +>=20
 +> *** /usr/src/sbin/ipfw/ipfw2.c.orig     Wed Aug 11 18:08:27 2004
 +> --- /usr/src/sbin/ipfw/ipfw2.c  Wed Aug 11 18:27:21 2004
 +> ***************
 +> *** 1498,1504 ****
 +>                 next =3D (char *)p + l;
 +>                 nbytes -=3D l;
 +>=20
 +> !               if (rulenum !=3D 0 && rulenum !=3D p->pipe_nr)
 +>                         continue;
 +>=20
 +>                 /*
 +> --- 1498,1504 ----
 +>                 next =3D (char *)p + l;
 +>                 nbytes -=3D l;
 +>=20
 +> !               if ( (rulenum !=3D 0 && rulenum !=3D p->pipe_nr) || (do_=
 pipe=3D=3D2) )
 +>                         continue;
 +>=20
 +>                 /*
 +> ***************
 +> *** 1532,1537 ****
 +> --- 1532,1542 ----
 +>                 l =3D sizeof(*fs) + fs->rq_elements * sizeof(*q);
 +>                 next =3D (char *)fs + l;
 +>                 nbytes -=3D l;
 +> +
 +> +               if (rulenum !=3D 0 && ((rulenum !=3D fs->fs_nr && do_pip=
 e=3D=3D2)
 +> +               || (rulenum !=3D fs->parent_nr && do_pipe=3D=3D1)))
 +> +                       continue;
 +> +
 +>                 q =3D (struct dn_flow_queue *)(fs+1);
 +>                 sprintf(prefix, "q%05d: weight %d pipe %d ",
 +>                     fs->fs_nr, fs->weight, fs->parent_nr);
 
 This patch doesn't work for me as expected. It shows all pipes and queues
 with parentpipe=3DN.
 Could you check this patch (it is against -CURRENT, but it should be easy
 to apply it to 4.x):
 
 Index: ipfw2.c
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
 RCS file: /private/FreeBSD/src/sbin/ipfw/ipfw2.c,v
 retrieving revision 1.54
 diff -u -p -r1.54 ipfw2.c
 --- ipfw2.c	12 Aug 2004 22:06:55 -0000	1.54
 +++ ipfw2.c	23 Aug 2004 16:51:26 -0000
 @@ -1564,6 +1564,12 @@ list_pipes(void *data, uint nbytes, int=20
  		l =3D sizeof(*fs) + fs->rq_elements * sizeof(*q);
  		next =3D (char *)fs + l;
  		nbytes -=3D l;
 +
 +		if (rulenum !=3D 0 && ((rulenum !=3D fs->fs_nr && do_pipe =3D=3D 2) ||
 +		    (rulenum !=3D fs->parent_nr && do_pipe =3D=3D 1))) {
 +			continue;
 +		}
 +
  		q =3D (struct dn_flow_queue *)(fs+1);
  		sprintf(prefix, "q%05d: weight %d pipe %d ",
  		    fs->fs_nr, fs->weight, fs->parent_nr);
 
 Basically, it looks that first addition of 'do_pipe=3D=3D2' is bogus.
 
 PS. Could you use unified diff format for patches generation?
 
 --=20
 Pawel Jakub Dawidek                       http://www.FreeBSD.org
 pjd@FreeBSD.org                           http://garage.freebsd.pl
 FreeBSD committer                         Am I Evil? Yes, I Am!
 
 --7vS62bsm3BVGCDKV
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.4 (FreeBSD)
 
 iD8DBQFBKiHuForvXbEpPzQRAr79AKChjiIY5ShwiIU+KZO76i1LfXhOOACfTQAm
 +gD5Y8Oo0SVqDdg5d28LbGk=
 =mOse
 -----END PGP SIGNATURE-----
 
 --7vS62bsm3BVGCDKV--

From: Pawel Malachowski <pawmal-posting@freebsd.lublin.pl>
To: Pawel Jakub Dawidek <pjd@freebsd.org>
Cc: freebsd-ipfw@freebsd.org, FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/70311: ipfw(8) pipe/queue show N displays data not only for N
Date: Mon, 23 Aug 2004 20:40:51 +0200

 On Mon, Aug 23, 2004 at 06:57:18PM +0200, Pawel Jakub Dawidek wrote:
 
 > This patch doesn't work for me as expected. It shows all pipes and queues
 > with parentpipe=N.
 > Could you check this patch (it is against -CURRENT, but it should be easy
 > to apply it to 4.x):
 
 Weird.
 For me, Your patch gives on my working RELENG_4 shaper setup:
 
 % ipfw pipe show 1
 00001: unlimited    0 ms  12 KB 0 queues (1 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
 q00110: weight 1 pipe 1  8 KB 0 queues (512 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
 q00120: weight 99 pipe 1  8 KB 0 queues (512 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
 
 	// expected, show pipe 1 and every queue with parent=1
 
 % ipfw queue show 1
 00001: unlimited    0 ms  12 KB 0 queues (1 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
 
 	// not expected, there is no queue 1, but it shows pipe 1 here.
 	// if I want pipe 1, I would type ipfw pipe show 1
 
 % ipfw pipe show 110
 
 	// expected, there is no pipe 110
 
 % ipfw queue show 110
 q00110: weight 1 pipe 1  8 KB 0 queues (512 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
 
 	// expected, there is queue 110.
 
 > Index: ipfw2.c
 > ===================================================================
 > RCS file: /private/FreeBSD/src/sbin/ipfw/ipfw2.c,v
 > retrieving revision 1.54
 > diff -u -p -r1.54 ipfw2.c
 > --- ipfw2.c	12 Aug 2004 22:06:55 -0000	1.54
 > +++ ipfw2.c	23 Aug 2004 16:51:26 -0000
 > @@ -1564,6 +1564,12 @@ list_pipes(void *data, uint nbytes, int 
 >  		l = sizeof(*fs) + fs->rq_elements * sizeof(*q);
 >  		next = (char *)fs + l;
 >  		nbytes -= l;
 > +
 > +		if (rulenum != 0 && ((rulenum != fs->fs_nr && do_pipe == 2) ||
 > +		    (rulenum != fs->parent_nr && do_pipe == 1))) {
 > +			continue;
 > +		}
 > +
 >  		q = (struct dn_flow_queue *)(fs+1);
 >  		sprintf(prefix, "q%05d: weight %d pipe %d ",
 >  		    fs->fs_nr, fs->weight, fs->parent_nr);
 > 
 > Basically, it looks that first addition of 'do_pipe==2' is bogus.
 
 Well, with this first 'do_pipe==2' check it works here like this:
 
 % ipfw pipe show 1
 00001: unlimited    0 ms  12 KB 0 queues (1 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0x00000000/0x0000
 q00110: weight 1 pipe 1  8 KB 0 queues (512 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
 q00120: weight 99 pipe 1  8 KB 0 queues (512 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
 
 	// expected, shows pipe 1 and every queue with parent=1
 
 % ipfw queue show 1
 
 	// expected, there is no queue 1
 
 % ipfw pipe show 110
 
 	// expected, there is no pipe 110
 
 % ipfw queue show 110
 q00110: weight 1 pipe 1  8 KB 0 queues (512 buckets) droptail
     mask: 0x00 0x00000000/0x0000 -> 0xffffffff/0x0000
 
 	// expected, there is queue 110
 
 
 So, for me it is not bogus. :)
 
 
 cheers,
 -- 
 Pawe Maachowski
State-Changed-From-To: open->closed 
State-Changed-By: pjd 
State-Changed-When: Mon Aug 23 19:23:51 GMT 2004 
State-Changed-Why:  
Patch committed. Dziki!:) 

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

From: Pawel Jakub Dawidek <pjd@FreeBSD.org>
To: Pawel Malachowski <pawmal-posting@freebsd.lublin.pl>
Cc: freebsd-ipfw@freebsd.org, FreeBSD-gnats-submit@freebsd.org
Subject: Re: bin/70311: ipfw(8) pipe/queue show N displays data not only for N
Date: Mon, 23 Aug 2004 21:23:41 +0200

 --RBdmpsAEjcqDYAXp
 Content-Type: text/plain; charset=iso-8859-2
 Content-Disposition: inline
 Content-Transfer-Encoding: quoted-printable
 
 On Mon, Aug 23, 2004 at 08:40:51PM +0200, Pawel Malachowski wrote:
 +> On Mon, Aug 23, 2004 at 06:57:18PM +0200, Pawel Jakub Dawidek wrote:
 +>=20
 +> > This patch doesn't work for me as expected. It shows all pipes and que=
 ues
 +> > with parentpipe=3DN.
 +> > Could you check this patch (it is against -CURRENT, but it should be e=
 asy
 +> > to apply it to 4.x):
 +>=20
 +> Weird.
 +> For me, Your patch gives on my working RELENG_4 shaper setup:
 
 Ok, it looks that I fucked up somthing when I patches my ipfw2.c by hand
 at the first time. Everything works just fine. Sorry for the noice.
 
 Patch committed to -CURRENT (MFC after 3 days). Thanks!
 
 --=20
 Pawel Jakub Dawidek                       http://www.FreeBSD.org
 pjd@FreeBSD.org                           http://garage.freebsd.pl
 FreeBSD committer                         Am I Evil? Yes, I Am!
 
 --RBdmpsAEjcqDYAXp
 Content-Type: application/pgp-signature
 Content-Disposition: inline
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.2.4 (FreeBSD)
 
 iD8DBQFBKkQ8ForvXbEpPzQRAsWGAJ0Q1Jpn0AjVfUhszK6DCXH1bkq+kQCdHeif
 jW5AB10h+X5qgS1yD0tWOGI=
 =NQWW
 -----END PGP SIGNATURE-----
 
 --RBdmpsAEjcqDYAXp--
State-Changed-From-To: closed->patched 
State-Changed-By: pjd 
State-Changed-When: Mon Aug 23 21:20:19 GMT 2004 
State-Changed-Why:  
There was no MFC yet, so state should be "patched" for now. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=70311 
State-Changed-From-To: patched->closed 
State-Changed-By: pjd 
State-Changed-When: Mon Nov 8 18:47:33 GMT 2004 
State-Changed-Why:  
Fix committed to RELENG_4, thanks! 

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

From: "Jukka A. Ukkonen" <jau@mawit.com>
To: freebsd-gnats-submit@FreeBSD.org,
	pawmal-posting@freebsd.lublin.pl
Cc:  
Subject: Re: bin/70311: ipfw(8) pipe/queue show N displays data not only for
 N
Date: Tue, 09 Nov 2004 21:25:51 +0200

 The latest change also reverted a change done in revision 1.57
 fixing an uninitialized variable "last".
 
 Line 1968 needs this minimal change (again)...
 
 -       u_long rnum, last;
 +       u_long rnum, last = 0;
 
 Cheers,
 	// jau
>Unformatted:
