From nobody@FreeBSD.org  Tue Sep 14 23:08:14 2004
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125])
	by hub.freebsd.org (Postfix) with ESMTP id 551E616A4CE
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 14 Sep 2004 23:08:14 +0000 (GMT)
Received: from www.freebsd.org (www.freebsd.org [216.136.204.117])
	by mx1.FreeBSD.org (Postfix) with ESMTP id 47C8D43D2F
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 14 Sep 2004 23:08:14 +0000 (GMT)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.12.11/8.12.11) with ESMTP id i8EN8DYJ023863
	for <freebsd-gnats-submit@FreeBSD.org>; Tue, 14 Sep 2004 23:08:13 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.12.11/8.12.11/Submit) id i8EN8DQR023861;
	Tue, 14 Sep 2004 23:08:13 GMT
	(envelope-from nobody)
Message-Id: <200409142308.i8EN8DQR023861@www.freebsd.org>
Date: Tue, 14 Sep 2004 23:08:13 GMT
From: Aurlien Rougemont <beorn@ligarena.com>
To: freebsd-gnats-submit@FreeBSD.org
Subject: altq activation problem on 5.3 beta1->4
X-Send-Pr-Version: www-2.3

>Number:         71746
>Category:       kern
>Synopsis:       altq activation problem on 5.3 beta1->4
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    mlaier
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Tue Sep 14 23:10:26 GMT 2004
>Closed-Date:    Mon Sep 20 15:27:04 GMT 2004
>Last-Modified:  Mon Sep 20 15:27:04 GMT 2004
>Originator:     Aurlien Rougemont
>Release:        5.3beta4
>Organization:
Ligarena
>Environment:
FreeBSD beorn.dynoland.lan 5.3-BETA4 FreeBSD 5.3-BETA4 #2: Tue Sep 14 11:34:43 CEST 2004     root@beorn.dynoland.lan:/usr/obj/usr/src/sys/BEORN  i386
>Description:
I've been running FreeBSD 5.2-CURRENT then 5.3beta1,2,3 and now 4 and I am still experiencing the same problem.

When i'm switchting from a pf.conf file without altq, to a pf.conf file with altq, the altq module seems to remain off (no packets detected in pftop or in pfctl -v -s queue) and ignoring paquets that are macthing the rules with the queue statements.

>How-To-Repeat:
When I apply a pf.conf without any altq/queue statement: 
   pf -f /path/pfnoaltq.conf

then i wan to apply a pf.conf with some altq/queue statements:
   pf -f /path/pfwithaltq.conf
>Fix:

 I've had to make a little workaround script to bypass this (let's dare!) bug :
-----------------------
 #!/bin/sh
 $pfctl=/sbin/pfctl

 $pfctl -d
 $pfctl -ef $1
 -----------------------
 
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-i386->mlaier 
Responsible-Changed-By: mlaier 
Responsible-Changed-When: Wed Sep 15 02:39:33 GMT 2004 
Responsible-Changed-Why:  
I'll take this one. 

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

From: Max Laier <max@love2party.net>
To: freebsd-gnats-submit@freebsd.org, beorn@ligarena.com
Cc:  
Subject: Re: kern/71746: altq activation problem on 5.3 beta1->4
Date: Thu, 16 Sep 2004 22:54:50 +0200

 --Boundary-00=_b2fSBivi5s1lxS7
 Content-Type: text/plain;
   charset="us-ascii"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: inline
 
 Can you try the attached patch (also on: 
 http://people.freebsd.org/~mlaier/altq_onoff.diff)
 
 It should apply to both RELENG_5 and HEAD.
 
 This has not been tested, so be sure to put on your safety belts, but I am 
 reasonable sure that it will fix the problem (if it works :-\) ... Will test 
 it myself later (when I have console access to my crashbox). Looking forward 
 to your report! Thanks!
 
 -- 
 /"\  Best regards,                      | mlaier@freebsd.org
 \ /  Max Laier                          | ICQ #67774661
  X   http://pf4freebsd.love2party.net/  | mlaier@EFnet
 / \  ASCII Ribbon Campaign              | Against HTML Mail and News
 
 --Boundary-00=_b2fSBivi5s1lxS7
 Content-Type: text/x-diff;
   charset="us-ascii";
   name="altq_onoff.diff"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
 	filename="altq_onoff.diff"
 
 Index: pf_ioctl.c
 ===================================================================
 RCS file: /usr/store/mlaier/fcvs/src/sys/contrib/pf/net/pf_ioctl.c,v
 retrieving revision 1.14
 diff -u -r1.14 pf_ioctl.c
 --- pf_ioctl.c	14 Sep 2004 03:12:01 -0000	1.14
 +++ pf_ioctl.c	16 Sep 2004 20:31:01 -0000
 @@ -1,5 +1,5 @@
  /*	$FreeBSD: src/sys/contrib/pf/net/pf_ioctl.c,v 1.14 2004/09/14 03:12:01 mlaier Exp $	*/
 -/*	$OpenBSD: pf_ioctl.c,v 1.112.2.2 2004/07/24 18:28:12 brad Exp $ */
 +/*	$OpenBSD: pf_ioctl.c,v 1.118 2004/05/03 07:51:59 kjc Exp $ */
  
  /*
   * Copyright (c) 2001 Daniel Hartmeier
 @@ -132,6 +132,8 @@
  int			 pf_begin_altq(u_int32_t *);
  int			 pf_rollback_altq(u_int32_t);
  int			 pf_commit_altq(u_int32_t);
 +int			 pf_enable_altq(struct pf_altq *);
 +int			 pf_disable_altq(struct pf_altq *);
  #endif /* ALTQ */
  int			 pf_begin_rules(u_int32_t *, int, char *, char *);
  int			 pf_rollback_rules(u_int32_t, int, char *, char *);
 @@ -144,6 +146,9 @@
  #endif
  
  struct pf_rule		 pf_default_rule;
 +#ifdef ALTQ
 +static int		 pf_altq_running;
 +#endif
  
  #define	TAGID_MAX	 50000
  TAILQ_HEAD(pf_tags, pf_tagname)	pf_tags = TAILQ_HEAD_INITIALIZER(pf_tags),
 @@ -866,7 +871,9 @@
  		if (altq->qname[0] == 0) {
  			/* attach the discipline */
  			error = altq_pfattach(altq);
 -			if (error) {
 +			if (error == 0 && pf_altq_running)
 +				error = pf_enable_altq(altq);
 +			if (error != 0) {
  				splx(s);
  				return (error);
  			}
 @@ -878,6 +885,8 @@
  		TAILQ_REMOVE(pf_altqs_inactive, altq, entries);
  		if (altq->qname[0] == 0) {
  			/* detach and destroy the discipline */
 +			if (pf_altq_running)
 +				error = pf_disable_altq(altq);
  			err = altq_pfdetach(altq);
  			if (err != 0 && error == 0)
  				error = err;
 @@ -893,6 +902,73 @@
  	altqs_inactive_open = 0;
  	return (error);
  }
 +
 +int
 +pf_enable_altq(struct pf_altq *altq)
 +{
 +	struct ifnet		*ifp;
 +	struct tb_profile	 tb;
 +	int			 s, error = 0;
 +
 +	if ((ifp = ifunit(altq->ifname)) == NULL)
 +		return (EINVAL);
 +
 +	if (ifp->if_snd.altq_type != ALTQT_NONE)
 +		error = altq_enable(&ifp->if_snd);
 +
 +	/* set tokenbucket regulator */
 +	if (error == 0 && ifp != NULL && ALTQ_IS_ENABLED(&ifp->if_snd)) {
 +		tb.rate = altq->ifbandwidth;
 +		tb.depth = altq->tbrsize;
 +		s = splimp();
 +#ifdef __FreeBSD__
 +		PF_UNLOCK();
 +#endif
 +		error = tbr_set(&ifp->if_snd, &tb);
 +#ifdef __FreeBSD__
 +		PF_LOCK();
 +#endif		
 +		splx(s);
 +	}
 +
 +	return (error);
 +}
 +
 +int
 +pf_disable_altq(struct pf_altq *altq)
 +{
 +	struct ifnet		*ifp;
 +	struct tb_profile	 tb;
 +	int			 s, error;
 +
 +	if ((ifp = ifunit(altq->ifname)) == NULL)
 +		return (EINVAL);
 +
 +	/*
 +	 * when the discipline is no longer referenced, it was overridden
 +	 * by a new one.  if so, just return.
 +	 */
 +	if (altq->altq_disc != ifp->if_snd.altq_disc)
 +		return (0);
 +
 +	error = altq_disable(&ifp->if_snd);
 +
 +	if (error == 0) {
 +		/* clear tokenbucket regulator */
 +		tb.rate = 0;
 +		s = splimp();
 +#ifdef __FreeBSD__
 +		PF_UNLOCK();
 +#endif
 +		error = tbr_set(&ifp->if_snd, &tb);
 +#ifdef __FreeBSD__
 +		PF_LOCK();
 +#endif
 +		splx(s);
 +	}
 +
 +	return (error);
 +}
  #endif /* ALTQ */
  
  int
 @@ -1957,35 +2033,18 @@
  #ifdef ALTQ
  	case DIOCSTARTALTQ: {
  		struct pf_altq		*altq;
 -		struct ifnet		*ifp;
 -		struct tb_profile	 tb;
  
  		/* enable all altq interfaces on active list */
  		s = splsoftnet();
  		TAILQ_FOREACH(altq, pf_altqs_active, entries) {
  			if (altq->qname[0] == 0) {
 -				if ((ifp = ifunit(altq->ifname)) == NULL) {
 -					error = EINVAL;
 -					break;
 -				}
 -				if (ifp->if_snd.altq_type != ALTQT_NONE)
 -					error = altq_enable(&ifp->if_snd);
 -				if (error != 0)
 -					break;
 -				/* set tokenbucket regulator */
 -				tb.rate = altq->ifbandwidth;
 -				tb.depth = altq->tbrsize;
 -				PF_UNLOCK();
 -				error = tbr_set(&ifp->if_snd, &tb);
 -				PF_LOCK();
 +				error = pf_enable_altq(altq);
  				if (error != 0)
  					break;
  			}
  		}
 -#ifndef __FreeBSD__
  		if (error == 0)
 -			pfaltq_running = 1;
 -#endif
 +			pf_altq_running = 1;
  		splx(s);
  		DPFPRINTF(PF_DEBUG_MISC, ("altq: started\n"));
  		break;
 @@ -1993,36 +2052,18 @@
  
  	case DIOCSTOPALTQ: {
  		struct pf_altq		*altq;
 -		struct ifnet		*ifp;
 -		struct tb_profile	 tb;
 -		int			 err;
  
  		/* disable all altq interfaces on active list */
  		s = splsoftnet();
  		TAILQ_FOREACH(altq, pf_altqs_active, entries) {
  			if (altq->qname[0] == 0) {
 -				if ((ifp = ifunit(altq->ifname)) == NULL) {
 -					error = EINVAL;
 +				error = pf_disable_altq(altq);
 +				if (error != 0)
  					break;
 -				}
 -				if (ifp->if_snd.altq_type != ALTQT_NONE) {
 -					err = altq_disable(&ifp->if_snd);
 -					if (err != 0 && error == 0)
 -						error = err;
 -				}
 -				/* clear tokenbucket regulator */
 -				tb.rate = 0;
 -				PF_UNLOCK();
 -				err = tbr_set(&ifp->if_snd, &tb);
 -				PF_LOCK();
 -				if (err != 0 && error == 0)
 -					error = err;
  			}
  		}
 -#ifndef __FreeBSD__
  		if (error == 0)
 -			pfaltq_running = 0;
 -#endif
 +			pf_altq_running = 0;
  		splx(s);
  		DPFPRINTF(PF_DEBUG_MISC, ("altq: stopped\n"));
  		break;
 
 --Boundary-00=_b2fSBivi5s1lxS7--
State-Changed-From-To: open->patched 
State-Changed-By: mlaier 
State-Changed-When: Fri Sep 17 09:19:57 GMT 2004 
State-Changed-Why:  
Patch committed to current after success report from originator (please 
follow up to gnats next time). MT5 is scheduled in 3 days, re@ approval 
provided. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=71746 
State-Changed-From-To: patched->closed 
State-Changed-By: mlaier 
State-Changed-When: Mon Sep 20 15:26:31 GMT 2004 
State-Changed-Why:  
Committed to RELENG_5 as well. Thanks. 

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