Module Name:    src
Committed By:   thorpej
Date:           Sat Nov 11 13:16:31 UTC 2023

Modified Files:
        src/sys/altq [thorpej-altq-separation]: altq_blue.c altq_cbq.c
            altq_cdnr.c altq_conf.c altq_fifoq.c altq_hfsc.c altq_jobs.c
            altq_priq.c altq_red.c altq_rio.c altq_subr.c altq_wfq.c if_altq.h
        src/sys/net [thorpej-altq-separation]: if.c if.h if_bridge.c
            if_ethersubr.c if_vlan.c
        src/sys/net80211 [thorpej-altq-separation]: ieee80211_input.c

Log Message:
Mostly de-tangle ifnet::if_snd from ifaltq, in a way that's minimally-
invasive to the ALTQ code itself.

The point of this is to lay the groundwork for future changes to ifqueue,
which among other benefits, will also hide the ALTQ ABI from drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.26.6.1 src/sys/altq/altq_blue.c
cvs rdiff -u -r1.39 -r1.39.6.1 src/sys/altq/altq_cbq.c
cvs rdiff -u -r1.22 -r1.22.6.1 src/sys/altq/altq_cdnr.c \
    src/sys/altq/altq_conf.c
cvs rdiff -u -r1.18 -r1.18.6.1 src/sys/altq/altq_fifoq.c
cvs rdiff -u -r1.30 -r1.30.6.1 src/sys/altq/altq_hfsc.c
cvs rdiff -u -r1.12 -r1.12.6.1 src/sys/altq/altq_jobs.c
cvs rdiff -u -r1.28 -r1.28.6.1 src/sys/altq/altq_priq.c
cvs rdiff -u -r1.35 -r1.35.6.1 src/sys/altq/altq_red.c
cvs rdiff -u -r1.25 -r1.25.6.1 src/sys/altq/altq_rio.c
cvs rdiff -u -r1.33 -r1.33.46.1 src/sys/altq/altq_subr.c
cvs rdiff -u -r1.23 -r1.23.6.1 src/sys/altq/altq_wfq.c
cvs rdiff -u -r1.16 -r1.16.4.1 src/sys/altq/if_altq.h
cvs rdiff -u -r1.529 -r1.529.2.1 src/sys/net/if.c
cvs rdiff -u -r1.305 -r1.305.2.1 src/sys/net/if.h
cvs rdiff -u -r1.189 -r1.189.6.1 src/sys/net/if_bridge.c
cvs rdiff -u -r1.326 -r1.326.2.1 src/sys/net/if_ethersubr.c
cvs rdiff -u -r1.171 -r1.171.2.1 src/sys/net/if_vlan.c
cvs rdiff -u -r1.117 -r1.117.4.1 src/sys/net80211/ieee80211_input.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/altq/altq_blue.c
diff -u src/sys/altq/altq_blue.c:1.26 src/sys/altq/altq_blue.c:1.26.6.1
--- src/sys/altq/altq_blue.c:1.26	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_blue.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_blue.c,v 1.26 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_blue.c,v 1.26.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_blue.c,v 1.15 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_blue.c,v 1.26 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_blue.c,v 1.26.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -221,7 +221,7 @@ blueioctl(dev_t dev, ioctlcmd_t cmd, voi
 			break;
 		}
 
-		rqp->rq_ifq = &ifp->if_snd;
+		rqp->rq_ifq = ifp->if_snd.ifq_altq;
 		qtail(rqp->rq_q) = NULL;
 		qlen(rqp->rq_q) = 0;
 		qlimit(rqp->rq_q) = BLUE_LIMIT;
@@ -397,7 +397,7 @@ blue_enqueue(struct ifaltq *ifq, struct 
 	pktattr.pattr_hdr = m->m_pkthdr.pattr_hdr;
 
 	if (blue_addq(rqp->rq_blue, rqp->rq_q, m, &pktattr) == 0)
-		ifq->ifq_len++;
+		ALTQ_INC_LEN(ifq);
 	else
 		error = ENOBUFS;
 	return error;
@@ -618,7 +618,7 @@ blue_dequeue(struct ifaltq * ifq, int op
 
 	m = blue_getq(rqp->rq_blue, rqp->rq_q);
 	if (m != NULL)
-		ifq->ifq_len--;
+		ALTQ_DEC_LEN(ifq);
 	return m;
 }
 
@@ -652,7 +652,7 @@ blue_request(struct ifaltq *ifq, int req
 	case ALTRQ_PURGE:
 		_flushq(rqp->rq_q);
 		if (ALTQ_IS_ENABLED(ifq))
-			ifq->ifq_len = 0;
+			ALTQ_SET_LEN(ifq, 0);
 		break;
 	}
 	return (0);

Index: src/sys/altq/altq_cbq.c
diff -u src/sys/altq/altq_cbq.c:1.39 src/sys/altq/altq_cbq.c:1.39.6.1
--- src/sys/altq/altq_cbq.c:1.39	Fri Dec 31 20:22:48 2021
+++ src/sys/altq/altq_cbq.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cbq.c,v 1.39 2021/12/31 20:22:48 andvar Exp $	*/
+/*	$NetBSD: altq_cbq.c,v 1.39.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_cbq.c,v 1.21 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.39 2021/12/31 20:22:48 andvar Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cbq.c,v 1.39.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -542,7 +542,7 @@ cbq_enqueue(struct ifaltq *ifq, struct m
 
 	/* successfully queued. */
 	++cbqp->cbq_qlen;
-	IFQ_INC_LEN(ifq);
+	ALTQ_INC_LEN(ifq);
 	return (0);
 }
 
@@ -556,7 +556,7 @@ cbq_dequeue(struct ifaltq *ifq, int op)
 
 	if (m && op == ALTDQ_REMOVE) {
 		--cbqp->cbq_qlen;  /* decrement # of packets in cbq */
-		IFQ_DEC_LEN(ifq);
+		ALTQ_DEC_LEN(ifq);
 
 		/* Update the class. */
 		rmc_update_class_util(&cbqp->ifnp);
@@ -602,7 +602,7 @@ cbq_purge(cbq_state_t *cbqp)
 		if ((cl = cbqp->cbq_class_tbl[i]) != NULL)
 			rmc_dropall(cl);
 	if (ALTQ_IS_ENABLED(cbqp->ifnp.ifq_))
-		cbqp->ifnp.ifq_->ifq_len = 0;
+		ALTQ_SET_LEN(cbqp->ifnp.ifq_, 0);
 }
 #ifdef ALTQ3_COMPAT
 
@@ -909,12 +909,12 @@ cbq_ifattach(struct cbq_interface *iface
  	CALLOUT_INIT(&new_cbqp->cbq_callout);
 
 	new_cbqp->cbq_qlen = 0;
-	new_cbqp->ifnp.ifq_ = &ifp->if_snd;	    /* keep the ifq */
+	new_cbqp->ifnp.ifq_ = ifp->if_snd.ifq_altq;    /* keep the ifq */
 
 	/*
 	 * set CBQ to this ifnet structure.
 	 */
-	error = altq_attach(&ifp->if_snd, ALTQT_CBQ, new_cbqp,
+	error = altq_attach(ifp->if_snd.ifq_altq, ALTQT_CBQ, new_cbqp,
 			    cbq_enqueue, cbq_dequeue, cbq_request,
 			    &new_cbqp->cbq_classifier, acc_classify);
 	if (error) {

Index: src/sys/altq/altq_cdnr.c
diff -u src/sys/altq/altq_cdnr.c:1.22 src/sys/altq/altq_cdnr.c:1.22.6.1
--- src/sys/altq/altq_cdnr.c:1.22	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_cdnr.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_cdnr.c,v 1.22 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_cdnr.c,v 1.22.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_cdnr.c,v 1.15 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_cdnr.c,v 1.22 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_cdnr.c,v 1.22.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -144,7 +144,7 @@ altq_cdnr_input(struct mbuf *m, int af)
 		/* traffic conditioner is not enabled on this interface */
 		return (1);
 
-	top = ifp->if_snd.altq_cdnr;
+	top = ifp->if_snd.ifq_altq->altq_cdnr;
 
 	ip = mtod(m, struct ip *);
 #ifdef INET6
@@ -841,10 +841,10 @@ cdnrcmd_if_attach(char *ifname)
 	if ((ifp = ifunit(ifname)) == NULL)
 		return (EBADF);
 
-	if (ifp->if_snd.altq_cdnr != NULL)
+	if (ifp->if_snd.ifq_altq->altq_cdnr != NULL)
 		return (EBUSY);
 
-	if ((top = top_create(&ifp->if_snd)) == NULL)
+	if ((top = top_create(ifp->if_snd.ifq_altq)) == NULL)
 		return (ENOMEM);
 	return (0);
 }
Index: src/sys/altq/altq_conf.c
diff -u src/sys/altq/altq_conf.c:1.22 src/sys/altq/altq_conf.c:1.22.6.1
--- src/sys/altq/altq_conf.c:1.22	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_conf.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_conf.c,v 1.22 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_conf.c,v 1.22.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_conf.c,v 1.24 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_conf.c,v 1.22 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_conf.c,v 1.22.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -237,18 +237,18 @@ altqioctl(dev_t dev, ioctlcmd_t cmd, voi
 			typereq = (struct altqreq *)addr;
 			if ((ifp = ifunit(typereq->ifname)) == NULL)
 				return (EINVAL);
-			typereq->arg = (u_long)ifp->if_snd.altq_type;
+			typereq->arg = (u_long)ifp->if_snd.ifq_altq->altq_type;
 			return (0);
 		case ALTQTBRSET:
 			tbrreq = (struct tbrreq *)addr;
 			if ((ifp = ifunit(tbrreq->ifname)) == NULL)
 				return (EINVAL);
-			return tbr_set(&ifp->if_snd, &tbrreq->tb_prof);
+			return tbr_set(ifp->if_snd.ifq_altq, &tbrreq->tb_prof);
 		case ALTQTBRGET:
 			tbrreq = (struct tbrreq *)addr;
 			if ((ifp = ifunit(tbrreq->ifname)) == NULL)
 				return (EINVAL);
-			return tbr_get(&ifp->if_snd, &tbrreq->tb_prof);
+			return tbr_get(ifp->if_snd.ifq_altq, &tbrreq->tb_prof);
 		default:
 			return (EINVAL);
 		}

Index: src/sys/altq/altq_fifoq.c
diff -u src/sys/altq/altq_fifoq.c:1.18 src/sys/altq/altq_fifoq.c:1.18.6.1
--- src/sys/altq/altq_fifoq.c:1.18	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_fifoq.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_fifoq.c,v 1.18 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_fifoq.c,v 1.18.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_fifoq.c,v 1.12 2003/07/10 12:07:48 kjc Exp $	*/
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_fifoq.c,v 1.18 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_fifoq.c,v 1.18.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -173,7 +173,7 @@ fifoqioctl(dev_t dev, ioctlcmd_t cmd, vo
 			break;
 		}
 
-		q->q_ifq = &ifp->if_snd;
+		q->q_ifq = ifp->if_snd.ifq_altq;
 		q->q_head = q->q_tail = NULL;
 		q->q_len = 0;
 		q->q_limit = FIFOQ_LIMIT;
@@ -281,7 +281,7 @@ fifoq_enqueue(struct ifaltq *ifq, struct
 		q->q_tail->m_nextpkt = m;
 	q->q_tail = m;
 	q->q_len++;
-	ifq->ifq_len++;
+	ALTQ_INC_LEN(ifq);
 	return 0;
 }
 
@@ -316,7 +316,7 @@ fifoq_dequeue(struct ifaltq *ifq, int op
 		q->q_tail = NULL;
 	m->m_nextpkt = NULL;
 	q->q_len--;
-	ifq->ifq_len--;
+	ALTQ_DEC_LEN(ifq);
 #ifdef FIFOQ_STATS
 	PKTCNTR_ADD(&q->q_stats.xmit_cnt, m_pktlen(m));
 	if (q->q_len == 0)
@@ -385,7 +385,7 @@ fifoq_purge(fifoq_state_t *q)
 	q->q_tail = NULL;
 	q->q_len = 0;
 	if (ALTQ_IS_ENABLED(q->q_ifq))
-		q->q_ifq->ifq_len = 0;
+		ALTQ_SET_LEN(q->q_ifq, 0);
 }
 
 #ifdef KLD_MODULE

Index: src/sys/altq/altq_hfsc.c
diff -u src/sys/altq/altq_hfsc.c:1.30 src/sys/altq/altq_hfsc.c:1.30.6.1
--- src/sys/altq/altq_hfsc.c:1.30	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_hfsc.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_hfsc.c,v 1.30 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_hfsc.c,v 1.30.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_hfsc.c,v 1.26 2005/04/13 03:44:24 suz Exp $	*/
 
 /*
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.30 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.30.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -377,7 +377,7 @@ hfsc_purge(struct hfsc_if *hif)
 		if (!qempty(cl->cl_q))
 			hfsc_purgeq(cl);
 	if (ALTQ_IS_ENABLED(hif->hif_ifq))
-		hif->hif_ifq->ifq_len = 0;
+		ALTQ_SET_LEN(hif->hif_ifq, 0);
 }
 
 struct hfsc_class *
@@ -712,7 +712,7 @@ hfsc_enqueue(struct ifaltq *ifq, struct 
 		PKTCNTR_ADD(&cl->cl_stats.drop_cnt, len);
 		return (ENOBUFS);
 	}
-	IFQ_INC_LEN(ifq);
+	ALTQ_INC_LEN(ifq);
 	cl->cl_hif->hif_packets++;
 
 	/* successfully queued. */
@@ -806,7 +806,7 @@ hfsc_dequeue(struct ifaltq *ifq, int op)
 		panic("hfsc_dequeue:");
 	len = m_pktlen(m);
 	cl->cl_hif->hif_packets--;
-	IFQ_DEC_LEN(ifq);
+	ALTQ_DEC_LEN(ifq);
 	PKTCNTR_ADD(&cl->cl_stats.xmit_cnt, len);
 
 	update_vf(cl, len, cur_time);
@@ -889,7 +889,7 @@ hfsc_purgeq(struct hfsc_class *cl)
 		PKTCNTR_ADD(&cl->cl_stats.drop_cnt, m_pktlen(m));
 		m_freem(m);
 		cl->cl_hif->hif_packets--;
-		IFQ_DEC_LEN(cl->cl_hif->hif_ifq);
+		ALTQ_DEC_LEN(cl->cl_hif->hif_ifq);
 	}
 	ASSERT(qlen(cl->cl_q) == 0);
 
@@ -2007,13 +2007,13 @@ hfsccmd_if_attach(struct hfsc_attach *ap
 	if ((ifp = ifunit(ap->iface.hfsc_ifname)) == NULL)
 		return (ENXIO);
 
-	if ((hif = hfsc_attach(&ifp->if_snd, ap->bandwidth)) == NULL)
+	if ((hif = hfsc_attach(ifp->if_snd.ifq_altq, ap->bandwidth)) == NULL)
 		return (ENOMEM);
 
 	/*
 	 * set HFSC to this ifnet structure.
 	 */
-	if ((error = altq_attach(&ifp->if_snd, ALTQT_HFSC, hif,
+	if ((error = altq_attach(ifp->if_snd.ifq_altq, ALTQT_HFSC, hif,
 				 hfsc_enqueue, hfsc_dequeue, hfsc_request,
 				 &hif->hif_classifier, acc_classify)) != 0)
 		hfsc_detach(hif);

Index: src/sys/altq/altq_jobs.c
diff -u src/sys/altq/altq_jobs.c:1.12 src/sys/altq/altq_jobs.c:1.12.6.1
--- src/sys/altq/altq_jobs.c:1.12	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_jobs.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_jobs.c,v 1.12 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_jobs.c,v 1.12.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_jobs.c,v 1.11 2005/04/13 03:44:25 suz Exp $	*/
 /*
  * Copyright (c) 2001, the Rector and Board of Visitors of the
@@ -59,7 +59,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_jobs.c,v 1.12 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_jobs.c,v 1.12.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -251,7 +251,7 @@ jobs_purge(struct jobs_if *jif)
 			jobs_purgeq(cl);
 	}
 	if (ALTQ_IS_ENABLED(jif->jif_ifq))
-		jif->jif_ifq->ifq_len = 0;
+		ALTQ_SET_LEN(jif->jif_ifq, 0);
 }
 
 static struct jobs_class *
@@ -510,7 +510,7 @@ jobs_enqueue(struct ifaltq *ifq, struct 
 
 	/* proceed with packet enqueuing */
 
-	if (IFQ_IS_EMPTY(ifq)) {
+	if (ALTQ_IS_EMPTY(ifq)) {
 		for (pri=0; pri <= jif->jif_maxpri; pri++) {
 			scan = jif->jif_classes[pri];
 			if (scan != NULL) {
@@ -601,7 +601,7 @@ jobs_enqueue(struct ifaltq *ifq, struct 
 	if (jobs_addq(cl, m, jif) != 0)
 		return_flag = ENOBUFS; /* signals there's a buffer overflow */
 	else
-		IFQ_INC_LEN(ifq);
+		ALTQ_INC_LEN(ifq);
 
 	/* successfully queued. */
 
@@ -669,7 +669,7 @@ jobs_dequeue(struct ifaltq *ifq, int op)
 	now = read_machclk();
 	tstamp1 = now;
 
-	if (IFQ_IS_EMPTY(ifq)) {
+	if (ALTQ_IS_EMPTY(ifq)) {
 		/* no packet in the queue */
 		for (pri=0; pri <= jif->jif_maxpri; pri++) {
 		  cl = jif->jif_classes[pri];
@@ -738,7 +738,7 @@ jobs_dequeue(struct ifaltq *ifq, int op)
 		m = NULL;
 
 	if (m != NULL) {
-		IFQ_DEC_LEN(ifq);
+		ALTQ_DEC_LEN(ifq);
 		if (qempty(cl->cl_q))
 			cl->cl_period++;
 
@@ -799,7 +799,7 @@ jobs_addq(struct jobs_class *cl, struct 
 		return (-1);
 
 	} else if (!jif->jif_separate
-		   && jif->jif_ifq->ifq_len >= jif->jif_qlimit) {
+		   && ALTQ_GET_LEN(jif->jif_ifq) >= jif->jif_qlimit) {
 		/* shared buffer: supports guarantees on losses */
 		if (!cl->concerned_rlc) {
 			if (!cl->concerned_alc) {
@@ -1480,7 +1480,7 @@ assign_rate_drops_adc(struct jobs_if *ji
 								cl->current_loss += (len << SCALE_LOSS)/cl->cl_arrival.bytes;
 								m_freem(pkt); /* the packet is trashed here */
 								tslist_drop(cl);
-								IFQ_DEC_LEN(cl->cl_jif->jif_ifq);
+								ALTQ_DEC_LEN(cl->cl_jif->jif_ifq);
 							}
 						} else
 							keep_going = 0; /* NOTREACHED */
@@ -2134,7 +2134,7 @@ get_class_stats(struct class_stats *sp, 
 	PKTCNTR_RESET(&cl->st_rin);
 	PKTCNTR_RESET(&cl->st_rout);
 
-	sp->totallength = cl->cl_jif->jif_ifq->ifq_len;
+	sp->totallength = ALTQ_GET_LEN(cl->cl_jif->jif_ifq);
 	sp->lastdel = ticks_to_secs(GRANULARITY*cl->cl_lastdel);
 	sp->avgdel = cl->cl_avgdel;
 

Index: src/sys/altq/altq_priq.c
diff -u src/sys/altq/altq_priq.c:1.28 src/sys/altq/altq_priq.c:1.28.6.1
--- src/sys/altq/altq_priq.c:1.28	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_priq.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_priq.c,v 1.28 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_priq.c,v 1.28.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_priq.c,v 1.13 2005/04/13 03:44:25 suz Exp $	*/
 /*
  * Copyright (C) 2000-2003
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_priq.c,v 1.28 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_priq.c,v 1.28.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -277,7 +277,7 @@ priq_purge(struct priq_if *pif)
 			priq_purgeq(cl);
 	}
 	if (ALTQ_IS_ENABLED(pif->pif_ifq))
-		pif->pif_ifq->ifq_len = 0;
+		ALTQ_SET_LEN(pif->pif_ifq, 0);
 }
 
 static struct priq_class *
@@ -471,7 +471,7 @@ priq_enqueue(struct ifaltq *ifq, struct 
 		PKTCNTR_ADD(&cl->cl_dropcnt, len);
 		return (ENOBUFS);
 	}
-	IFQ_INC_LEN(ifq);
+	ALTQ_INC_LEN(ifq);
 
 	/* successfully queued. */
 	return (0);
@@ -494,7 +494,7 @@ priq_dequeue(struct ifaltq *ifq, int op)
 	struct mbuf *m;
 	int pri;
 
-	if (IFQ_IS_EMPTY(ifq))
+	if (ALTQ_IS_EMPTY(ifq))
 		/* no packet in the queue */
 		return (NULL);
 
@@ -506,7 +506,7 @@ priq_dequeue(struct ifaltq *ifq, int op)
 
 			m = priq_getq(cl);
 			if (m != NULL) {
-				IFQ_DEC_LEN(ifq);
+				ALTQ_DEC_LEN(ifq);
 				if (qempty(cl->cl_q))
 					cl->cl_period++;
 				PKTCNTR_ADD(&cl->cl_xmitcnt, m_pktlen(m));
@@ -801,13 +801,13 @@ priqcmd_if_attach(struct priq_interface 
 	if ((ifp = ifunit(ap->ifname)) == NULL)
 		return (ENXIO);
 
-	if ((pif = priq_attach(&ifp->if_snd, ap->arg)) == NULL)
+	if ((pif = priq_attach(ifp->if_snd.ifq_altq, ap->arg)) == NULL)
 		return (ENOMEM);
 
 	/*
 	 * set PRIQ to this ifnet structure.
 	 */
-	if ((error = altq_attach(&ifp->if_snd, ALTQT_PRIQ, pif,
+	if ((error = altq_attach(ifp->if_snd.ifq_altq, ALTQT_PRIQ, pif,
 				 priq_enqueue, priq_dequeue, priq_request,
 				 &pif->pif_classifier, acc_classify)) != 0)
 		priq_detach(pif);

Index: src/sys/altq/altq_red.c
diff -u src/sys/altq/altq_red.c:1.35 src/sys/altq/altq_red.c:1.35.6.1
--- src/sys/altq/altq_red.c:1.35	Sun Dec  5 04:43:57 2021
+++ src/sys/altq/altq_red.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_red.c,v 1.35 2021/12/05 04:43:57 msaitoh Exp $	*/
+/*	$NetBSD: altq_red.c,v 1.35.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_red.c,v 1.20 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_red.c,v 1.35 2021/12/05 04:43:57 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_red.c,v 1.35.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -823,7 +823,7 @@ redioctl(dev_t dev, ioctlcmd_t cmd, void
 			break;
 		}
 
-		rqp->rq_ifq = &ifp->if_snd;
+		rqp->rq_ifq = ifp->if_snd.ifq_altq;
 		qtail(rqp->rq_q) = NULL;
 		qlen(rqp->rq_q) = 0;
 		qlimit(rqp->rq_q) = RED_LIMIT;
@@ -1017,7 +1017,7 @@ red_enqueue(struct ifaltq *ifq, struct m
 
 	if (red_addq(rqp->rq_red, rqp->rq_q, m, &pktattr) < 0)
 		return ENOBUFS;
-	ifq->ifq_len++;
+	ALTQ_INC_LEN(ifq);
 	return 0;
 }
 
@@ -1041,7 +1041,7 @@ red_dequeue(struct ifaltq *ifq, int op)
 	/* op == ALTDQ_REMOVE */
 	m =  red_getq(rqp->rq_red, rqp->rq_q);
 	if (m != NULL)
-		ifq->ifq_len--;
+		ALTQ_DEC_LEN(ifq);
 	return (m);
 }
 
@@ -1063,7 +1063,7 @@ red_purgeq(red_queue_t *rqp)
 {
 	_flushq(rqp->rq_q);
 	if (ALTQ_IS_ENABLED(rqp->rq_ifq))
-		rqp->rq_ifq->ifq_len = 0;
+		ALTQ_SET_LEN(rqp->rq_ifq, 0);
 }
 
 #ifdef ALTQ_FLOWVALVE

Index: src/sys/altq/altq_rio.c
diff -u src/sys/altq/altq_rio.c:1.25 src/sys/altq/altq_rio.c:1.25.6.1
--- src/sys/altq/altq_rio.c:1.25	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_rio.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_rio.c,v 1.25 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_rio.c,v 1.25.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_rio.c,v 1.19 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -60,7 +60,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_rio.c,v 1.25 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_rio.c,v 1.25.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -557,7 +557,7 @@ rioioctl(dev_t dev, ioctlcmd_t cmd, void
 			break;
 		}
 
-		rqp->rq_ifq = &ifp->if_snd;
+		rqp->rq_ifq = ifp->if_snd.ifq_altq;
 		qtail(rqp->rq_q) = NULL;
 		qlen(rqp->rq_q) = 0;
 		qlimit(rqp->rq_q) = RIO_LIMIT;
@@ -732,7 +732,7 @@ rio_request(struct ifaltq *ifq, int req,
 	case ALTRQ_PURGE:
 		_flushq(rqp->rq_q);
 		if (ALTQ_IS_ENABLED(ifq))
-			ifq->ifq_len = 0;
+			ALTQ_SET_LEN(ifq, 0);
 		break;
 	}
 	return (0);
@@ -756,7 +756,7 @@ rio_enqueue(struct ifaltq *ifq, struct m
 	pktattr.pattr_hdr = m->m_pkthdr.pattr_hdr;
 
 	if (rio_addq(rqp->rq_rio, rqp->rq_q, m, &pktattr) == 0)
-		ifq->ifq_len++;
+		ALTQ_INC_LEN(ifq);
 	else
 		error = ENOBUFS;
 	return error;
@@ -781,7 +781,7 @@ rio_dequeue(struct ifaltq *ifq, int op)
 
 	m = rio_getq(rqp->rq_rio, rqp->rq_q);
 	if (m != NULL)
-		ifq->ifq_len--;
+		ALTQ_DEC_LEN(ifq);
 	return m;
 }
 

Index: src/sys/altq/altq_subr.c
diff -u src/sys/altq/altq_subr.c:1.33 src/sys/altq/altq_subr.c:1.33.46.1
--- src/sys/altq/altq_subr.c:1.33	Tue Mar 14 09:03:08 2017
+++ src/sys/altq/altq_subr.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_subr.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $	*/
+/*	$NetBSD: altq_subr.c,v 1.33.46.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_subr.c,v 1.24 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -28,7 +28,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_subr.c,v 1.33 2017/03/14 09:03:08 ozaki-r Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_subr.c,v 1.33.46.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: altq_subr.c,
 #include <sys/socket.h>
 #include <sys/socketvar.h>
 #include <sys/kernel.h>
+#include <sys/kmem.h>
 #include <sys/errno.h>
 #include <sys/syslog.h>
 #include <sys/sysctl.h>
@@ -109,6 +110,53 @@ static void 	ip4f_free(struct ip4_frag *
  * alternate queueing support routines
  */
 
+/*
+ * Allocate an ifaltq and associate it with the specified ifqueue and
+ * ifnet.
+ */
+void
+altq_alloc(struct ifqueue *ifq, struct ifnet *ifp)
+{
+	if (ifq->ifq_altq == NULL) {
+		ifq->ifq_altq = kmem_zalloc(sizeof(*ifq->ifq_altq), KM_SLEEP);
+		ifq->ifq_altq->altq_ifq = ifq;
+
+		/*
+		 * This allows the ALTQ_*() mcaros to work with either
+		 * an ifqueue or an ifaltq argument.  Yes, it's a hack,
+		 * but it results in less code churn.
+		 */
+		ifq->ifq_altq->ifq_altq = ifq->ifq_altq;
+	}
+	if (ifp != NULL) {
+		ifq->ifq_altq->altq_ifp = ifp;
+	}
+}
+
+/*
+ * Free the ifaltq structure associated with an ifqueue.
+ */
+void
+altq_free(struct ifqueue *ifq)
+{
+	if (ifq->ifq_altq != NULL) {
+		ifq->ifq_altq->altq_ifp = NULL;
+		kmem_free(ifq->ifq_altq, sizeof(*ifq->ifq_altq));
+		ifq->ifq_altq = NULL;
+	}
+}
+
+/*
+ * Mark's a device's send queue as being ready for (as in
+ * "knowledgeable about") ALTQ processing.
+ */
+void
+altq_set_ready(struct ifqueue *ifq)
+{
+	altq_alloc(ifq, NULL);
+	ifq->ifq_altq->altq_flags = ALTQF_READY;
+}
+
 /* look up the queue state by the interface name and the queueing type. */
 void *
 altq_lookup(char *name, int type)
@@ -116,8 +164,9 @@ altq_lookup(char *name, int type)
 	struct ifnet *ifp;
 
 	if ((ifp = ifunit(name)) != NULL) {
-		if (type != ALTQT_NONE && ifp->if_snd.altq_type == type)
-			return (ifp->if_snd.altq_disc);
+		struct ifaltq *altq = ifp->if_snd.ifq_altq;
+		if (type != ALTQT_NONE && altq->altq_type == type)
+			return (altq->altq_disc);
 	}
 
 	return NULL;
@@ -198,8 +247,8 @@ altq_enable(struct ifaltq *ifq)
 		return 0;
 
 	s = splnet();
-	IFQ_PURGE(ifq);
-	ASSERT(ifq->ifq_len == 0);
+	IFQ_PURGE(ifq->altq_ifq);
+	ASSERT(ALTQ_GET_LEN(ifq) == 0);
 	ifq->altq_flags |= ALTQF_ENABLED;
 	if (ifq->altq_clfier != NULL)
 		ifq->altq_flags |= ALTQF_CLASSIFY;
@@ -217,8 +266,8 @@ altq_disable(struct ifaltq *ifq)
 		return 0;
 
 	s = splnet();
-	IFQ_PURGE(ifq);
-	ASSERT(ifq->ifq_len == 0);
+	IFQ_PURGE(ifq->altq_ifq);
+	ASSERT(ALTQ_GET_LEN(ifq) == 0);
 	ifq->altq_flags &= ~(ALTQF_ENABLED|ALTQF_CLASSIFY);
 	splx(s);
 	return 0;
@@ -280,9 +329,9 @@ tbr_dequeue(struct ifaltq *ifq, int op)
 		m = (*ifq->altq_dequeue)(ifq, op);
 	else {
 		if (op == ALTDQ_POLL)
-			IF_POLL(ifq, m);
+			IF_POLL(ifq->altq_ifq, m);
 		else
-			IF_DEQUEUE(ifq, m);
+			IF_DEQUEUE(ifq->altq_ifq, m);
 	}
 
 	if (m != NULL && op == ALTDQ_REMOVE)

Index: src/sys/altq/altq_wfq.c
diff -u src/sys/altq/altq_wfq.c:1.23 src/sys/altq/altq_wfq.c:1.23.6.1
--- src/sys/altq/altq_wfq.c:1.23	Tue Sep 21 14:30:15 2021
+++ src/sys/altq/altq_wfq.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: altq_wfq.c,v 1.23 2021/09/21 14:30:15 christos Exp $	*/
+/*	$NetBSD: altq_wfq.c,v 1.23.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: altq_wfq.c,v 1.14 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_wfq.c,v 1.23 2021/09/21 14:30:15 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_wfq.c,v 1.23.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -142,7 +142,7 @@ wfq_ifattach(struct wfq_interface *iface
 	}
 
 	/* keep the ifq */
-	new_wfqp->ifq = &ifp->if_snd;
+	new_wfqp->ifq = ifp->if_snd.ifq_altq;
 	new_wfqp->nums = DEFAULT_QSIZE;
 	new_wfqp->hwm = HWM;
 	new_wfqp->bytes = 0;
@@ -161,7 +161,7 @@ wfq_ifattach(struct wfq_interface *iface
 	/*
 	 * set WFQ to this ifnet structure.
 	 */
-	if ((error = altq_attach(&ifp->if_snd, ALTQT_WFQ, new_wfqp,
+	if ((error = altq_attach(ifp->if_snd.ifq_altq, ALTQT_WFQ, new_wfqp,
 				 wfq_ifenqueue, wfq_ifdequeue, wfq_request,
 				 new_wfqp, wfq_classify)) != 0) {
 		free(queue, M_DEVBUF);
@@ -233,7 +233,7 @@ wfq_flush(struct ifaltq *ifq)
 	while ((mp = wfq_ifdequeue(ifq, ALTDQ_REMOVE)) != NULL)
 		m_freem(mp);
 	if (ALTQ_IS_ENABLED(ifq))
-		ifq->ifq_len = 0;
+		ALTQ_SET_LEN(ifq, 0);
 	return 0;
 }
 
@@ -269,7 +269,7 @@ wfq_ifenqueue(struct ifaltq *ifq, struct
 	byte = mp->m_pkthdr.len;
 	queue->bytes += byte;
 	wfqp->bytes += byte;
-	ifq->ifq_len++;
+	ALTQ_INC_LEN(ifq);
 
 	if (queue->next == NULL) {
 		/* this queue gets active. add the queue to the active list */
@@ -303,7 +303,7 @@ wfq_ifenqueue(struct ifaltq *ifq, struct
 		PKTCNTR_ADD(&drop_queue->drop_cnt, byte);
 		wfqp->bytes -= byte;
 		m_freem(mp);
-		ifq->ifq_len--;
+		ALTQ_DEC_LEN(ifq);
 		if(drop_queue == queue)
 			/* the queue for this flow is selected to drop */
 			error = ENOBUFS;
@@ -482,7 +482,7 @@ wfq_ifdequeue(struct ifaltq *ifq, int op
 				PKTCNTR_ADD(&queue->xmit_cnt, byte);
 				wfqp->bytes -= byte;
 				if (ALTQ_IS_ENABLED(ifq))
-					ifq->ifq_len--;
+					ALTQ_DEC_LEN(ifq);
 			}
 			return mp;
 

Index: src/sys/altq/if_altq.h
diff -u src/sys/altq/if_altq.h:1.16 src/sys/altq/if_altq.h:1.16.4.1
--- src/sys/altq/if_altq.h:1.16	Mon Oct 24 08:11:24 2022
+++ src/sys/altq/if_altq.h	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_altq.h,v 1.16 2022/10/24 08:11:24 msaitoh Exp $	*/
+/*	$NetBSD: if_altq.h,v 1.16.4.1 2023/11/11 13:16:30 thorpej Exp $	*/
 /*	$KAME: if_altq.h,v 1.12 2005/04/13 03:44:25 suz Exp $	*/
 
 /*
@@ -36,18 +36,11 @@
 struct altq_pktattr; struct tb_regulator; struct top_cdnr;
 
 /*
- * Structure defining a queue for a network interface.
+ * Structure defining a complex queue for a network interface.
  */
-struct	ifaltq {
-	/* fields compatible with struct ifqueue */
-	struct	mbuf *ifq_head;
-	struct	mbuf *ifq_tail;
-	int	ifq_len;
-	int	ifq_maxlen;
-	uint64_t ifq_drops;
-	kmutex_t *ifq_lock;
-
-	/* alternate queueing related fields */
+struct ifaltq {
+	struct ifaltq *ifq_altq;	/* pointer back to self */
+	struct ifqueue *altq_ifq;	/* pointer back to base queue */
 	int	altq_type;		/* discipline type */
 	int	altq_flags;		/* flags (e.g. ready, in-use) */
 	void	*altq_disc;		/* for discipline-specific use */
@@ -136,25 +129,52 @@ struct tb_regulator {
 /* altq request types (currently only purge is defined) */
 #define	ALTRQ_PURGE		1	/* purge all packets */
 
-#define	ALTQ_IS_READY(ifq)		((ifq)->altq_flags & ALTQF_READY)
-#define	ALTQ_IS_ENABLED(ifq)		((ifq)->altq_flags & ALTQF_ENABLED)
-#define	ALTQ_NEEDS_CLASSIFY(ifq)	((ifq)->altq_flags & ALTQF_CLASSIFY)
-#define	ALTQ_IS_CNDTNING(ifq)		((ifq)->altq_flags & ALTQF_CNDTNING)
-
-#define	ALTQ_SET_CNDTNING(ifq)		((ifq)->altq_flags |= ALTQF_CNDTNING)
-#define	ALTQ_CLEAR_CNDTNING(ifq)	((ifq)->altq_flags &= ~ALTQF_CNDTNING)
-#define	ALTQ_IS_ATTACHED(ifq)		((ifq)->altq_disc != NULL)
+#define	ALTQ_INC_LEN(altq)	(altq)->altq_ifq->ifq_len++
+#define	ALTQ_DEC_LEN(altq)	(altq)->altq_ifq->ifq_len--
+#define	ALTQ_GET_LEN(altq)	(altq)->altq_ifq->ifq_len
+#define	ALTQ_SET_LEN(altq, v)	(altq)->altq_ifq->ifq_len = (v)
+#define	ALTQ_IS_EMPTY(altq)	((altq)->altq_ifq->ifq_len == 0)
+
+#define	_ALTQ_FLAGS(ifq)	((ifq)->ifq_altq != NULL ?		\
+				 (ifq)->ifq_altq->altq_flags : 0)
+
+#define	ALTQ_IS_READY(ifq)		(_ALTQ_FLAGS(ifq) & ALTQF_READY)
+#define	ALTQ_IS_ENABLED(ifq)		(_ALTQ_FLAGS(ifq) & ALTQF_ENABLED)
+#define	ALTQ_NEEDS_CLASSIFY(ifq)	(_ALTQ_FLAGS(ifq) & ALTQF_CLASSIFY)
+#define	ALTQ_IS_CNDTNING(ifq)		(_ALTQ_FLAGS(ifq) & ALTQF_CNDTNING)
+
+#define	ALTQ_SET_CNDTNING(ifq)						\
+do {									\
+	if ((ifq)->ifq_altq != NULL) {					\
+		(ifq)->ifq_altq->altq_flags |= ALTQF_CNDTNING;		\
+	}								\
+} while (/*CONSTCOND*/0)
+
+#define	ALTQ_CLEAR_CNDTNING(ifq)					\
+do {									\
+	if ((ifq)->ifq_altq != NULL) {					\
+		(ifq)->ifq_altq->altq_flags &= ~ALTQF_CNDTNING;		\
+	}								\
+} while (/*CONSTCOND*/0)
+
+#define	ALTQ_IS_ATTACHED(ifq)		((ifq)->ifq_altq != NULL &&	\
+					 (ifq)->ifq_altq->altq_disc != NULL)
 
 #define	ALTQ_ENQUEUE(ifq, m, err)					\
-	(err) = (*(ifq)->altq_enqueue)((ifq),(m))
+	(err) = (*(ifq)->ifq_altq->altq_enqueue)((ifq)->ifq_altq,(m))
 #define	ALTQ_DEQUEUE(ifq, m)						\
-	(m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_REMOVE)
+	(m) = (*(ifq)->ifq_altq->altq_dequeue)((ifq)->ifq_altq, ALTDQ_REMOVE)
 #define	ALTQ_POLL(ifq, m)						\
-	(m) = (*(ifq)->altq_dequeue)((ifq), ALTDQ_POLL)
+	(m) = (*(ifq)->ifq_altq->altq_dequeue)((ifq)->ifq_altq, ALTDQ_POLL)
 #define	ALTQ_PURGE(ifq)							\
-	(void)(*(ifq)->altq_request)((ifq), ALTRQ_PURGE, (void *)0)
-#define	ALTQ_IS_EMPTY(ifq)		((ifq)->ifq_len == 0)
-#define	TBR_IS_ENABLED(ifq)		((ifq)->altq_tbr != NULL)
+	(void)(*(ifq)->ifq_altq->altq_request)((ifq)->ifq_altq, ALTRQ_PURGE, (void *)0)
+
+#define	TBR_IS_ENABLED(ifq)		((ifq)->ifq_altq != NULL &&	\
+					 (ifq)->ifq_altq->altq_tbr != NULL)
+
+extern void altq_alloc(struct ifqueue *, struct ifnet *);
+extern void altq_free(struct ifqueue *);
+extern void altq_set_ready(struct ifqueue *);
 
 extern int altq_attach(struct ifaltq *, int, void *,
 		       int (*)(struct ifaltq *, struct mbuf *),

Index: src/sys/net/if.c
diff -u src/sys/net/if.c:1.529 src/sys/net/if.c:1.529.2.1
--- src/sys/net/if.c:1.529	Fri Feb 24 11:02:45 2023
+++ src/sys/net/if.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.c,v 1.529 2023/02/24 11:02:45 riastradh Exp $	*/
+/*	$NetBSD: if.c,v 1.529.2.1 2023/11/11 13:16:30 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001, 2008 The NetBSD Foundation, Inc.
@@ -90,7 +90,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.529 2023/02/24 11:02:45 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if.c,v 1.529.2.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #if defined(_KERNEL_OPT)
 #include "opt_inet.h"
@@ -220,7 +220,7 @@ static kauth_listener_t if_listener;
 
 static int doifioctl(struct socket *, u_long, void *, struct lwp *);
 static void sysctl_sndq_setup(struct sysctllog **, const char *,
-    struct ifaltq *);
+    struct ifqueue *);
 static void if_slowtimo_intr(void *);
 static void if_slowtimo_work(struct work *, void *);
 static int sysctl_if_watchdog(SYSCTLFN_PROTO);
@@ -742,11 +742,7 @@ if_initialize(ifnet_t *ifp)
 	ifp->if_csum_flags_rx = 0;
 
 #ifdef ALTQ
-	ifp->if_snd.altq_type = 0;
-	ifp->if_snd.altq_disc = NULL;
-	ifp->if_snd.altq_flags &= ALTQF_CANTCHANGE;
-	ifp->if_snd.altq_tbr  = NULL;
-	ifp->if_snd.altq_ifp  = ifp;
+	altq_alloc(&ifp->if_snd, ifp);
 #endif
 
 	IFQ_LOCK_INIT(&ifp->if_snd);
@@ -1389,9 +1385,10 @@ if_detach(struct ifnet *ifp)
 
 #ifdef ALTQ
 	if (ALTQ_IS_ENABLED(&ifp->if_snd))
-		altq_disable(&ifp->if_snd);
+		altq_disable(ifp->if_snd.ifq_altq);
 	if (ALTQ_IS_ATTACHED(&ifp->if_snd))
-		altq_detach(&ifp->if_snd);
+		altq_detach(ifp->if_snd.ifq_altq);
+	altq_free(&ifp->if_snd);
 #endif
 
 #if NCARP > 0
@@ -3991,7 +3988,7 @@ if_mcast_op(ifnet_t *ifp, const unsigned
 
 static void
 sysctl_sndq_setup(struct sysctllog **clog, const char *ifname,
-    struct ifaltq *ifq)
+    struct ifqueue *ifq)
 {
 	const struct sysctlnode *cnode, *rnode;
 

Index: src/sys/net/if.h
diff -u src/sys/net/if.h:1.305 src/sys/net/if.h:1.305.2.1
--- src/sys/net/if.h:1.305	Mon Oct  9 11:55:34 2023
+++ src/sys/net/if.h	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if.h,v 1.305 2023/10/09 11:55:34 riastradh Exp $	*/
+/*	$NetBSD: if.h,v 1.305.2.1 2023/11/11 13:16:30 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1999, 2000, 2001 The NetBSD Foundation, Inc.
@@ -237,12 +237,13 @@ struct if_status_description {
  * Structure defining a queue for a network interface.
  */
 struct ifqueue {
-	struct		mbuf *ifq_head;
-	struct		mbuf *ifq_tail;
+	kmutex_t	*ifq_lock;
+	struct mbuf	*ifq_head;
+	struct mbuf	*ifq_tail;
+	struct ifaltq	*ifq_altq;
 	int		ifq_len;
 	int		ifq_maxlen;
 	uint64_t	ifq_drops;
-	kmutex_t	*ifq_lock;
 };
 
 #ifdef _KERNEL
@@ -274,7 +275,7 @@ typedef unsigned short if_index_t;
  * Interface.  Field markings and the corresponding locks:
  *
  * i:	IFNET_LOCK (a.k.a., if_ioctl_lock)
- * q:	ifq_lock (struct ifaltq)
+ * q:	ifq_lock (struct ifqueue)
  * a:	if_afdata_lock
  * 6:	in6_multilock (global lock)
  * ::	unlocked, stable
@@ -342,7 +343,7 @@ typedef struct ifnet {
 			    (struct ifnet *);
 	void		(*if_bpf_mtap)	/* :: bpf routine */
 			    (struct bpf_if *, struct mbuf *, u_int);
-	struct ifaltq	if_snd;		/* q: output queue (includes altq) */
+	struct ifqueue	if_snd;		/* q: output queue */
 	struct ifaddr	*if_dl;		/* i: identity of this interface. */
 	const struct sockaddr_dl
 			*if_sadl;	/* i: pointer to sockaddr_dl of if_dl */
@@ -1001,7 +1002,7 @@ do {									\
 do {									\
 	mutex_enter((ifq)->ifq_lock);					\
 	if (TBR_IS_ENABLED(ifq))					\
-		(m) = tbr_dequeue((ifq), ALTDQ_REMOVE);			\
+		(m) = tbr_dequeue((ifq)->ifq_altq, ALTDQ_REMOVE);	\
 	else if (ALTQ_IS_ENABLED(ifq))					\
 		ALTQ_DEQUEUE((ifq), (m));				\
 	else								\
@@ -1013,7 +1014,7 @@ do {									\
 do {									\
 	mutex_enter((ifq)->ifq_lock);					\
 	if (TBR_IS_ENABLED(ifq))					\
-		(m) = tbr_dequeue((ifq), ALTDQ_POLL);			\
+		(m) = tbr_dequeue((ifq)->ifq_altq, ALTDQ_POLL);		\
 	else if (ALTQ_IS_ENABLED(ifq))					\
 		ALTQ_POLL((ifq), (m));					\
 	else								\
@@ -1031,10 +1032,7 @@ do {									\
 	mutex_exit((ifq)->ifq_lock);					\
 } while (/*CONSTCOND*/ 0)
 
-#define	IFQ_SET_READY(ifq)						\
-do {									\
-	(ifq)->altq_flags |= ALTQF_READY;				\
-} while (/*CONSTCOND*/ 0)
+#define	IFQ_SET_READY(ifq)	altq_set_ready(ifq)
 
 #define	IFQ_CLASSIFY(ifq, m, af)					\
 do {									\
@@ -1042,8 +1040,9 @@ do {									\
 	mutex_enter((ifq)->ifq_lock);					\
 	if (ALTQ_IS_ENABLED(ifq)) {					\
 		if (ALTQ_NEEDS_CLASSIFY(ifq))				\
-			(m)->m_pkthdr.pattr_class = (*(ifq)->altq_classify) \
-				((ifq)->altq_clfier, (m), (af));	\
+			(m)->m_pkthdr.pattr_class =			\
+			    (*(ifq)->ifq_altq->altq_classify)		\
+			    ((ifq)->ifq_altq->altq_clfier, (m), (af));	\
 		(m)->m_pkthdr.pattr_af = (af);				\
 		(m)->m_pkthdr.pattr_hdr = mtod((m), void *);		\
 	}								\

Index: src/sys/net/if_bridge.c
diff -u src/sys/net/if_bridge.c:1.189 src/sys/net/if_bridge.c:1.189.6.1
--- src/sys/net/if_bridge.c:1.189	Fri Jul 29 07:58:18 2022
+++ src/sys/net/if_bridge.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_bridge.c,v 1.189 2022/07/29 07:58:18 skrll Exp $	*/
+/*	$NetBSD: if_bridge.c,v 1.189.6.1 2023/11/11 13:16:30 thorpej Exp $	*/
 
 /*
  * Copyright 2001 Wasabi Systems, Inc.
@@ -80,7 +80,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.189 2022/07/29 07:58:18 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_bridge.c,v 1.189.6.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1497,7 +1497,7 @@ bridge_enqueue(struct bridge_softc *sc, 
 	 */
 	if (ALTQ_IS_ENABLED(&dst_ifp->if_snd)) {
 		/* XXX IFT_ETHER */
-		altq_etherclassify(&dst_ifp->if_snd, m);
+		altq_etherclassify(dst_ifp->if_snd.ifq_altq, m);
 	}
 	KERNEL_UNLOCK_ONE(NULL);
 #endif /* ALTQ */

Index: src/sys/net/if_ethersubr.c
diff -u src/sys/net/if_ethersubr.c:1.326 src/sys/net/if_ethersubr.c:1.326.2.1
--- src/sys/net/if_ethersubr.c:1.326	Thu Nov  2 09:40:47 2023
+++ src/sys/net/if_ethersubr.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_ethersubr.c,v 1.326 2023/11/02 09:40:47 yamaguchi Exp $	*/
+/*	$NetBSD: if_ethersubr.c,v 1.326.2.1 2023/11/11 13:16:30 thorpej Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996, 1997, and 1998 WIDE Project.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.326 2023/11/02 09:40:47 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_ethersubr.c,v 1.326.2.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -455,7 +455,7 @@ ether_output(struct ifnet * const ifp0, 
 	 * address family/header pointer in the pktattr.
 	 */
 	if (ALTQ_IS_ENABLED(&ifp->if_snd))
-		altq_etherclassify(&ifp->if_snd, m);
+		altq_etherclassify(ifp->if_snd.ifq_altq, m);
 	KERNEL_UNLOCK_ONE(NULL);
 #endif
 	return ifq_enqueue(ifp, m);

Index: src/sys/net/if_vlan.c
diff -u src/sys/net/if_vlan.c:1.171 src/sys/net/if_vlan.c:1.171.2.1
--- src/sys/net/if_vlan.c:1.171	Thu Nov  2 09:48:29 2023
+++ src/sys/net/if_vlan.c	Sat Nov 11 13:16:30 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: if_vlan.c,v 1.171 2023/11/02 09:48:29 yamaguchi Exp $	*/
+/*	$NetBSD: if_vlan.c,v 1.171.2.1 2023/11/11 13:16:30 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2000, 2001 The NetBSD Foundation, Inc.
@@ -78,7 +78,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.171 2023/11/02 09:48:29 yamaguchi Exp $");
+__KERNEL_RCSID(0, "$NetBSD: if_vlan.c,v 1.171.2.1 2023/11/11 13:16:30 thorpej Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_inet.h"
@@ -1289,7 +1289,7 @@ vlan_start(struct ifnet *ifp)
 			KASSERT(
 			    p->if_type == IFT_ETHER ||
 			    p->if_type == IFT_L2TP);
-			altq_etherclassify(&p->if_snd, m);
+			altq_etherclassify(p->if_snd.ifq_altq, m);
 		}
 		KERNEL_UNLOCK_ONE(NULL);
 #endif /* ALTQ */

Index: src/sys/net80211/ieee80211_input.c
diff -u src/sys/net80211/ieee80211_input.c:1.117 src/sys/net80211/ieee80211_input.c:1.117.4.1
--- src/sys/net80211/ieee80211_input.c:1.117	Sat Nov 19 07:57:51 2022
+++ src/sys/net80211/ieee80211_input.c	Sat Nov 11 13:16:31 2023
@@ -1,4 +1,4 @@
-/*	$NetBSD: ieee80211_input.c,v 1.117 2022/11/19 07:57:51 yamt Exp $	*/
+/*	$NetBSD: ieee80211_input.c,v 1.117.4.1 2023/11/11 13:16:31 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2001 Atsushi Onoe
@@ -37,7 +37,7 @@
 __FBSDID("$FreeBSD: src/sys/net80211/ieee80211_input.c,v 1.81 2005/08/10 16:22:29 sam Exp $");
 #endif
 #ifdef __NetBSD__
-__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.117 2022/11/19 07:57:51 yamt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ieee80211_input.c,v 1.117.4.1 2023/11/11 13:16:31 thorpej Exp $");
 #endif
 
 #ifdef _KERNEL_OPT
@@ -901,7 +901,7 @@ ieee80211_deliver_data(struct ieee80211c
 			int len;
 #ifdef ALTQ
 			if (ALTQ_IS_ENABLED(&ifp->if_snd)) {
-				altq_etherclassify(&ifp->if_snd, m1);
+				altq_etherclassify(ifp->if_snd.ifq_altq, m1);
 			}
 #endif
 			len = m1->m_pkthdr.len;

Reply via email to