2 /* $KAME: altq_cbq.c,v 1.19 2003/09/17 14:23:25 kjc Exp $ */
5 * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the SMCC Technology
21 * Development Group at Sun Microsystems, Inc.
23 * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
24 * promote products derived from this software without specific prior
27 * SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
28 * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is
29 * provided "as is" without express or implied warranty of any kind.
31 * These notices must be retained in any copies of any part of this software.
34 #if defined(__FreeBSD__) || defined(__NetBSD__)
38 #include "opt_inet6.h"
40 #endif /* __FreeBSD__ || __NetBSD__ */
41 #ifdef ALTQ_CBQ /* cbq is enabled by ALTQ_CBQ option in opt_altq.h */
43 #include <sys/param.h>
44 #include <sys/malloc.h>
46 #include <sys/socket.h>
47 #include <sys/systm.h>
49 #include <sys/errno.h>
53 #include <sys/kernel.h>
57 #include <netinet/in.h>
59 #include <net/pfvar.h>
60 #include <altq/altq.h>
61 #include <altq/altq_cbq.h>
63 #include <altq/altq_conf.h>
68 * Local Data structures.
70 static cbq_state_t *cbq_list = NULL;
74 * Forward Declarations.
76 static int cbq_class_destroy(cbq_state_t *, struct rm_class *);
77 static struct rm_class *clh_to_clp(cbq_state_t *, u_int32_t);
78 static int cbq_clear_interface(cbq_state_t *);
79 static int cbq_request(struct ifaltq *, int, void *);
80 static int cbq_enqueue(struct ifaltq *, struct mbuf *,
81 struct altq_pktattr *);
82 static struct mbuf *cbq_dequeue(struct ifaltq *, int);
83 static void cbqrestart(struct ifaltq *);
84 static void get_class_stats(class_stats_t *, struct rm_class *);
85 static void cbq_purge(cbq_state_t *);
87 static int cbq_add_class(struct cbq_add_class *);
88 static int cbq_delete_class(struct cbq_delete_class *);
89 static int cbq_modify_class(struct cbq_modify_class *);
90 static int cbq_class_create(cbq_state_t *, struct cbq_add_class *,
91 struct rm_class *, struct rm_class *);
92 static int cbq_clear_hierarchy(struct cbq_interface *);
93 static int cbq_set_enable(struct cbq_interface *, int);
94 static int cbq_ifattach(struct cbq_interface *);
95 static int cbq_ifdetach(struct cbq_interface *);
96 static int cbq_getstats(struct cbq_getstats *);
98 static int cbq_add_filter(struct cbq_add_filter *);
99 static int cbq_delete_filter(struct cbq_delete_filter *);
100 #endif /* ALTQ3_COMPAT */
104 * cbq_class_destroy(cbq_mod_state_t *, struct rm_class *) - This
105 * function destroys a given traffic class. Before destroying
106 * the class, all traffic for that class is released.
109 cbq_class_destroy(cbq_state_t *cbqp, struct rm_class *cl)
113 /* delete the class */
114 rmc_delete_class(&cbqp->ifnp, cl);
117 * free the class handle
119 for (i = 0; i < CBQ_MAX_CLASSES; i++)
120 if (cbqp->cbq_class_tbl[i] == cl)
121 cbqp->cbq_class_tbl[i] = NULL;
123 if (cl == cbqp->ifnp.root_)
124 cbqp->ifnp.root_ = NULL;
125 if (cl == cbqp->ifnp.default_)
126 cbqp->ifnp.default_ = NULL;
128 if (cl == cbqp->ifnp.ctl_)
129 cbqp->ifnp.ctl_ = NULL;
134 /* convert class handle to class pointer */
135 static struct rm_class *
136 clh_to_clp(cbq_state_t *cbqp, u_int32_t chandle)
144 * first, try optimistically the slot matching the lower bits of
145 * the handle. if it fails, do the linear table search.
147 i = chandle % CBQ_MAX_CLASSES;
148 if ((cl = cbqp->cbq_class_tbl[i]) != NULL &&
149 cl->stats_.handle == chandle)
151 for (i = 0; i < CBQ_MAX_CLASSES; i++)
152 if ((cl = cbqp->cbq_class_tbl[i]) != NULL &&
153 cl->stats_.handle == chandle)
159 cbq_clear_interface(cbq_state_t *cbqp)
164 #ifdef ALTQ3_CLFIER_COMPAT
165 /* free the filters for this interface */
166 acc_discard_filters(&cbqp->cbq_classifier, NULL, 1);
169 /* clear out the classes now */
172 for (i = 0; i < CBQ_MAX_CLASSES; i++) {
173 if ((cl = cbqp->cbq_class_tbl[i]) != NULL) {
174 if (is_a_parent_class(cl))
177 cbq_class_destroy(cbqp, cl);
178 cbqp->cbq_class_tbl[i] = NULL;
179 if (cl == cbqp->ifnp.root_)
180 cbqp->ifnp.root_ = NULL;
181 if (cl == cbqp->ifnp.default_)
182 cbqp->ifnp.default_ = NULL;
184 if (cl == cbqp->ifnp.ctl_)
185 cbqp->ifnp.ctl_ = NULL;
196 cbq_request(struct ifaltq *ifq, int req, void *arg)
198 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
200 IFQ_LOCK_ASSERT(ifq);
210 /* copy the stats info in rm_class to class_states_t */
212 get_class_stats(class_stats_t *statsp, struct rm_class *cl)
214 statsp->xmit_cnt = cl->stats_.xmit_cnt;
215 statsp->drop_cnt = cl->stats_.drop_cnt;
216 statsp->over = cl->stats_.over;
217 statsp->borrows = cl->stats_.borrows;
218 statsp->overactions = cl->stats_.overactions;
219 statsp->delays = cl->stats_.delays;
221 statsp->depth = cl->depth_;
222 statsp->priority = cl->pri_;
223 statsp->maxidle = cl->maxidle_;
224 statsp->minidle = cl->minidle_;
225 statsp->offtime = cl->offtime_;
226 statsp->qmax = qlimit(cl->q_);
227 statsp->ns_per_byte = cl->ns_per_byte_;
228 statsp->wrr_allot = cl->w_allotment_;
229 statsp->qcnt = qlen(cl->q_);
230 statsp->avgidle = cl->avgidle_;
232 statsp->qtype = qtype(cl->q_);
234 if (q_is_red(cl->q_))
235 red_getstats(cl->red_, &statsp->red[0]);
238 if (q_is_rio(cl->q_))
239 rio_getstats((rio_t *)cl->red_, &statsp->red[0]);
244 cbq_pfattach(struct pf_altq *a)
249 if ((ifp = ifunit(a->ifname)) == NULL || a->altq_disc == NULL)
256 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, a->altq_disc,
257 cbq_enqueue, cbq_dequeue, cbq_request, NULL, NULL);
263 cbq_add_altq(struct pf_altq *a)
268 if ((ifp = ifunit(a->ifname)) == NULL)
270 if (!ALTQ_IS_READY(&ifp->if_snd))
273 /* allocate and initialize cbq_state_t */
274 cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_NOWAIT | M_ZERO);
277 CALLOUT_INIT(&cbqp->cbq_callout);
279 cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
281 /* keep the state in pf_altq */
288 cbq_remove_altq(struct pf_altq *a)
292 if ((cbqp = a->altq_disc) == NULL)
296 cbq_clear_interface(cbqp);
298 if (cbqp->ifnp.default_)
299 cbq_class_destroy(cbqp, cbqp->ifnp.default_);
300 if (cbqp->ifnp.root_)
301 cbq_class_destroy(cbqp, cbqp->ifnp.root_);
303 /* deallocate cbq_state_t */
304 free(cbqp, M_DEVBUF);
310 cbq_add_queue(struct pf_altq *a)
312 struct rm_class *borrow, *parent;
315 struct cbq_opts *opts;
318 if ((cbqp = a->altq_disc) == NULL)
324 * find a free slot in the class table. if the slot matching
325 * the lower bits of qid is free, use this slot. otherwise,
326 * use the first free slot.
328 i = a->qid % CBQ_MAX_CLASSES;
329 if (cbqp->cbq_class_tbl[i] != NULL) {
330 for (i = 0; i < CBQ_MAX_CLASSES; i++)
331 if (cbqp->cbq_class_tbl[i] == NULL)
333 if (i == CBQ_MAX_CLASSES)
337 opts = &a->pq_u.cbq_opts;
338 /* check parameters */
339 if (a->priority >= CBQ_MAXPRI)
342 /* Get pointers to parent and borrow classes. */
343 parent = clh_to_clp(cbqp, a->parent_qid);
344 if (opts->flags & CBQCLF_BORROW)
350 * A class must borrow from it's parent or it can not
351 * borrow at all. Hence, borrow can be null.
353 if (parent == NULL && (opts->flags & CBQCLF_ROOTCLASS) == 0) {
354 printf("cbq_add_queue: no parent class!\n");
358 if ((borrow != parent) && (borrow != NULL)) {
359 printf("cbq_add_class: borrow class != parent\n");
366 switch (opts->flags & CBQCLF_CLASSMASK) {
367 case CBQCLF_ROOTCLASS:
370 if (cbqp->ifnp.root_)
373 case CBQCLF_DEFCLASS:
374 if (cbqp->ifnp.default_)
382 /* more than two flags bits set */
387 * create a class. if this is a root class, initialize the
390 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
391 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, opts->ns_per_byte,
392 cbqrestart, a->qlimit, RM_MAXQUEUED,
393 opts->maxidle, opts->minidle, opts->offtime,
395 cl = cbqp->ifnp.root_;
397 cl = rmc_newclass(a->priority,
398 &cbqp->ifnp, opts->ns_per_byte,
399 rmc_delay_action, a->qlimit, parent, borrow,
400 opts->maxidle, opts->minidle, opts->offtime,
401 opts->pktsize, opts->flags);
406 /* return handle to user space. */
407 cl->stats_.handle = a->qid;
408 cl->stats_.depth = cl->depth_;
410 /* save the allocated class */
411 cbqp->cbq_class_tbl[i] = cl;
413 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
414 cbqp->ifnp.default_ = cl;
420 cbq_remove_queue(struct pf_altq *a)
426 if ((cbqp = a->altq_disc) == NULL)
429 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
432 /* if we are a parent class, then return an error. */
433 if (is_a_parent_class(cl))
436 /* delete the class */
437 rmc_delete_class(&cbqp->ifnp, cl);
440 * free the class handle
442 for (i = 0; i < CBQ_MAX_CLASSES; i++)
443 if (cbqp->cbq_class_tbl[i] == cl) {
444 cbqp->cbq_class_tbl[i] = NULL;
445 if (cl == cbqp->ifnp.root_)
446 cbqp->ifnp.root_ = NULL;
447 if (cl == cbqp->ifnp.default_)
448 cbqp->ifnp.default_ = NULL;
456 cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes)
463 if ((cbqp = altq_lookup(a->ifname, ALTQT_CBQ)) == NULL)
466 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
469 if (*nbytes < sizeof(stats))
472 get_class_stats(&stats, cl);
474 if ((error = copyout((caddr_t)&stats, ubuf, sizeof(stats))) != 0)
476 *nbytes = sizeof(stats);
482 * cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pattr)
483 * - Queue data packets.
485 * cbq_enqueue is set to ifp->if_altqenqueue and called by an upper
486 * layer (e.g. ether_output). cbq_enqueue queues the given packet
487 * to the cbq, then invokes the driver's start routine.
489 * Assumptions: called in splimp
490 * Returns: 0 if the queueing is successful.
491 * ENOBUFS if a packet dropping occurred as a result of
496 cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pktattr)
498 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
503 IFQ_LOCK_ASSERT(ifq);
505 /* grab class set by classifier */
506 if ((m->m_flags & M_PKTHDR) == 0) {
507 /* should not happen */
508 printf("altq: packet for %s does not have pkthdr\n",
509 ifq->altq_ifp->if_xname);
514 if ((t = pf_find_mtag(m)) != NULL)
515 cl = clh_to_clp(cbqp, t->qid);
517 else if ((ifq->altq_flags & ALTQF_CLASSIFY) && pktattr != NULL)
518 cl = pktattr->pattr_class;
521 cl = cbqp->ifnp.default_;
529 cl->pktattr_ = pktattr; /* save proto hdr used by ECN */
534 if (rmc_queue_packet(cl, m) != 0) {
535 /* drop occurred. some mbuf was freed in rmc_queue_packet. */
536 PKTCNTR_ADD(&cl->stats_.drop_cnt, len);
540 /* successfully queued. */
547 cbq_dequeue(struct ifaltq *ifq, int op)
549 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
552 IFQ_LOCK_ASSERT(ifq);
554 m = rmc_dequeue_next(&cbqp->ifnp, op);
556 if (m && op == ALTDQ_REMOVE) {
557 --cbqp->cbq_qlen; /* decrement # of packets in cbq */
560 /* Update the class. */
561 rmc_update_class_util(&cbqp->ifnp);
568 * cbqrestart(queue_t *) - Restart sending of data.
569 * called from rmc_restart in splimp via timeout after waking up
575 cbqrestart(struct ifaltq *ifq)
580 IFQ_LOCK_ASSERT(ifq);
582 if (!ALTQ_IS_ENABLED(ifq))
583 /* cbq must have been detached */
586 if ((cbqp = (cbq_state_t *)ifq->altq_disc) == NULL)
587 /* should not happen */
592 cbqp->cbq_qlen > 0 && (ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
594 (*ifp->if_start)(ifp);
599 static void cbq_purge(cbq_state_t *cbqp)
604 for (i = 0; i < CBQ_MAX_CLASSES; i++)
605 if ((cl = cbqp->cbq_class_tbl[i]) != NULL)
607 if (ALTQ_IS_ENABLED(cbqp->ifnp.ifq_))
608 cbqp->ifnp.ifq_->ifq_len = 0;
614 struct cbq_add_class *acp;
617 struct rm_class *borrow, *parent;
620 ifacename = acp->cbq_iface.cbq_ifacename;
621 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
624 /* check parameters */
625 if (acp->cbq_class.priority >= CBQ_MAXPRI ||
626 acp->cbq_class.maxq > CBQ_MAXQSIZE)
629 /* Get pointers to parent and borrow classes. */
630 parent = clh_to_clp(cbqp, acp->cbq_class.parent_class_handle);
631 borrow = clh_to_clp(cbqp, acp->cbq_class.borrow_class_handle);
634 * A class must borrow from it's parent or it can not
635 * borrow at all. Hence, borrow can be null.
637 if (parent == NULL && (acp->cbq_class.flags & CBQCLF_ROOTCLASS) == 0) {
638 printf("cbq_add_class: no parent class!\n");
642 if ((borrow != parent) && (borrow != NULL)) {
643 printf("cbq_add_class: borrow class != parent\n");
647 return cbq_class_create(cbqp, acp, parent, borrow);
651 cbq_delete_class(dcp)
652 struct cbq_delete_class *dcp;
658 ifacename = dcp->cbq_iface.cbq_ifacename;
659 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
662 if ((cl = clh_to_clp(cbqp, dcp->cbq_class_handle)) == NULL)
665 /* if we are a parent class, then return an error. */
666 if (is_a_parent_class(cl))
669 /* if a filter has a reference to this class delete the filter */
670 acc_discard_filters(&cbqp->cbq_classifier, cl, 0);
672 return cbq_class_destroy(cbqp, cl);
676 cbq_modify_class(acp)
677 struct cbq_modify_class *acp;
683 ifacename = acp->cbq_iface.cbq_ifacename;
684 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
687 /* Get pointer to this class */
688 if ((cl = clh_to_clp(cbqp, acp->cbq_class_handle)) == NULL)
691 if (rmc_modclass(cl, acp->cbq_class.nano_sec_per_byte,
692 acp->cbq_class.maxq, acp->cbq_class.maxidle,
693 acp->cbq_class.minidle, acp->cbq_class.offtime,
694 acp->cbq_class.pktsize) < 0)
701 * cbq_class_create(cbq_mod_state_t *cbqp, struct cbq_add_class *acp,
702 * struct rm_class *parent, struct rm_class *borrow)
704 * This function create a new traffic class in the CBQ class hierarchy of
705 * given paramters. The class that created is either the root, default,
706 * or a new dynamic class. If CBQ is not initilaized, the the root class
710 cbq_class_create(cbqp, acp, parent, borrow)
712 struct cbq_add_class *acp;
713 struct rm_class *parent, *borrow;
716 cbq_class_spec_t *spec = &acp->cbq_class;
721 * allocate class handle
723 for (i = 1; i < CBQ_MAX_CLASSES; i++)
724 if (cbqp->cbq_class_tbl[i] == NULL)
726 if (i == CBQ_MAX_CLASSES)
728 chandle = i; /* use the slot number as class handle */
731 * create a class. if this is a root class, initialize the
734 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
735 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, spec->nano_sec_per_byte,
736 cbqrestart, spec->maxq, RM_MAXQUEUED,
737 spec->maxidle, spec->minidle, spec->offtime,
739 cl = cbqp->ifnp.root_;
741 cl = rmc_newclass(spec->priority,
742 &cbqp->ifnp, spec->nano_sec_per_byte,
743 rmc_delay_action, spec->maxq, parent, borrow,
744 spec->maxidle, spec->minidle, spec->offtime,
745 spec->pktsize, spec->flags);
750 /* return handle to user space. */
751 acp->cbq_class_handle = chandle;
753 cl->stats_.handle = chandle;
754 cl->stats_.depth = cl->depth_;
756 /* save the allocated class */
757 cbqp->cbq_class_tbl[i] = cl;
759 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
760 cbqp->ifnp.default_ = cl;
761 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_CTLCLASS)
762 cbqp->ifnp.ctl_ = cl;
769 struct cbq_add_filter *afp;
775 ifacename = afp->cbq_iface.cbq_ifacename;
776 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
779 /* Get the pointer to class. */
780 if ((cl = clh_to_clp(cbqp, afp->cbq_class_handle)) == NULL)
783 return acc_add_filter(&cbqp->cbq_classifier, &afp->cbq_filter,
784 cl, &afp->cbq_filter_handle);
788 cbq_delete_filter(dfp)
789 struct cbq_delete_filter *dfp;
794 ifacename = dfp->cbq_iface.cbq_ifacename;
795 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
798 return acc_delete_filter(&cbqp->cbq_classifier,
799 dfp->cbq_filter_handle);
803 * cbq_clear_hierarchy deletes all classes and their filters on the
807 cbq_clear_hierarchy(ifacep)
808 struct cbq_interface *ifacep;
813 ifacename = ifacep->cbq_ifacename;
814 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
817 return cbq_clear_interface(cbqp);
822 * cbq_set_enable(struct cbq_enable *ep) - this function processed the
823 * ioctl request to enable class based queueing. It searches the list
824 * of interfaces for the specified interface and then enables CBQ on
827 * Returns: 0, for no error.
828 * EBADF, for specified inteface not found.
832 cbq_set_enable(ep, enable)
833 struct cbq_interface *ep;
840 ifacename = ep->cbq_ifacename;
841 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
846 if (cbqp->ifnp.root_ == NULL || cbqp->ifnp.default_ == NULL ||
847 cbqp->ifnp.ctl_ == NULL) {
848 if (cbqp->ifnp.root_ == NULL)
849 printf("No Root Class for %s\n", ifacename);
850 if (cbqp->ifnp.default_ == NULL)
851 printf("No Default Class for %s\n", ifacename);
852 if (cbqp->ifnp.ctl_ == NULL)
853 printf("No Control Class for %s\n", ifacename);
855 } else if ((error = altq_enable(cbqp->ifnp.ifq_)) == 0) {
861 error = altq_disable(cbqp->ifnp.ifq_);
869 struct cbq_getstats *gsp;
875 class_stats_t stats, *usp;
878 ifacename = gsp->iface.cbq_ifacename;
879 nclasses = gsp->nclasses;
882 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
887 for (n = 0, i = 0; n < nclasses && i < CBQ_MAX_CLASSES; n++, i++) {
888 while ((cl = cbqp->cbq_class_tbl[i]) == NULL)
889 if (++i >= CBQ_MAX_CLASSES)
892 get_class_stats(&stats, cl);
893 stats.handle = cl->stats_.handle;
895 if ((error = copyout((caddr_t)&stats, (caddr_t)usp++,
896 sizeof(stats))) != 0)
907 struct cbq_interface *ifacep;
911 cbq_state_t *new_cbqp;
914 ifacename = ifacep->cbq_ifacename;
915 if ((ifp = ifunit(ifacename)) == NULL)
917 if (!ALTQ_IS_READY(&ifp->if_snd))
920 /* allocate and initialize cbq_state_t */
921 new_cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
922 if (new_cbqp == NULL)
924 bzero(new_cbqp, sizeof(cbq_state_t));
925 CALLOUT_INIT(&new_cbqp->cbq_callout);
927 new_cbqp->cbq_qlen = 0;
928 new_cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
931 * set CBQ to this ifnet structure.
933 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, new_cbqp,
934 cbq_enqueue, cbq_dequeue, cbq_request,
935 &new_cbqp->cbq_classifier, acc_classify);
937 free(new_cbqp, M_DEVBUF);
941 /* prepend to the list of cbq_state_t's. */
942 new_cbqp->cbq_next = cbq_list;
950 struct cbq_interface *ifacep;
955 ifacename = ifacep->cbq_ifacename;
956 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
959 (void)cbq_set_enable(ifacep, DISABLE);
961 cbq_clear_interface(cbqp);
963 /* remove CBQ from the ifnet structure. */
964 (void)altq_detach(cbqp->ifnp.ifq_);
966 /* remove from the list of cbq_state_t's. */
967 if (cbq_list == cbqp)
968 cbq_list = cbqp->cbq_next;
972 for (cp = cbq_list; cp != NULL; cp = cp->cbq_next)
973 if (cp->cbq_next == cbqp) {
974 cp->cbq_next = cbqp->cbq_next;
980 /* deallocate cbq_state_t */
981 free(cbqp, M_DEVBUF);
987 * cbq device interface
993 cbqopen(dev, flag, fmt, p)
996 #if (__FreeBSD_version > 500000)
1006 cbqclose(dev, flag, fmt, p)
1009 #if (__FreeBSD_version > 500000)
1016 struct cbq_interface iface;
1020 ifp = cbq_list->ifnp.ifq_->altq_ifp;
1021 sprintf(iface.cbq_ifacename, "%s", ifp->if_xname);
1022 err = cbq_ifdetach(&iface);
1023 if (err != 0 && error == 0)
1031 cbqioctl(dev, cmd, addr, flag, p)
1036 #if (__FreeBSD_version > 500000)
1044 /* check cmd for superuser only */
1047 /* currently only command that an ordinary user can call */
1050 #if (__FreeBSD_version > 700000)
1051 error = priv_check(p, PRIV_ALTQ_MANAGE);
1052 #elsif (__FreeBSD_version > 400000)
1055 error = suser(p->p_ucred, &p->p_acflag);
1065 error = cbq_set_enable((struct cbq_interface *)addr, ENABLE);
1069 error = cbq_set_enable((struct cbq_interface *)addr, DISABLE);
1072 case CBQ_ADD_FILTER:
1073 error = cbq_add_filter((struct cbq_add_filter *)addr);
1076 case CBQ_DEL_FILTER:
1077 error = cbq_delete_filter((struct cbq_delete_filter *)addr);
1081 error = cbq_add_class((struct cbq_add_class *)addr);
1085 error = cbq_delete_class((struct cbq_delete_class *)addr);
1088 case CBQ_MODIFY_CLASS:
1089 error = cbq_modify_class((struct cbq_modify_class *)addr);
1092 case CBQ_CLEAR_HIERARCHY:
1093 error = cbq_clear_hierarchy((struct cbq_interface *)addr);
1097 error = cbq_ifattach((struct cbq_interface *)addr);
1101 error = cbq_ifdetach((struct cbq_interface *)addr);
1105 error = cbq_getstats((struct cbq_getstats *)addr);
1118 static void cbq_class_dump(int);
1120 static void cbq_class_dump(i)
1123 struct rm_class *cl;
1124 rm_class_stats_t *s;
1125 struct _class_queue_ *q;
1127 if (cbq_list == NULL) {
1128 printf("cbq_class_dump: no cbq_state found\n");
1131 cl = cbq_list->cbq_class_tbl[i];
1133 printf("class %d cl=%p\n", i, cl);
1138 printf("pri=%d, depth=%d, maxrate=%d, allotment=%d\n",
1139 cl->pri_, cl->depth_, cl->maxrate_, cl->allotment_);
1140 printf("w_allotment=%d, bytes_alloc=%d, avgidle=%d, maxidle=%d\n",
1141 cl->w_allotment_, cl->bytes_alloc_, cl->avgidle_,
1143 printf("minidle=%d, offtime=%d, sleeping=%d, leaf=%d\n",
1144 cl->minidle_, cl->offtime_, cl->sleeping_, cl->leaf_);
1145 printf("handle=%d, depth=%d, packets=%d, bytes=%d\n",
1146 s->handle, s->depth,
1147 (int)s->xmit_cnt.packets, (int)s->xmit_cnt.bytes);
1148 printf("over=%d\n, borrows=%d, drops=%d, overactions=%d, delays=%d\n",
1149 s->over, s->borrows, (int)s->drop_cnt.packets,
1150 s->overactions, s->delays);
1151 printf("tail=%p, head=%p, qlen=%d, qlim=%d, qthresh=%d,qtype=%d\n",
1152 q->tail_, q->head_, q->qlen_, q->qlim_,
1153 q->qthresh_, q->qtype_);
1160 static struct altqsw cbq_sw =
1161 {"cbq", cbqopen, cbqclose, cbqioctl};
1163 ALTQ_MODULE(altq_cbq, ALTQT_CBQ, &cbq_sw);
1164 MODULE_DEPEND(altq_cbq, altq_red, 1, 1, 1);
1165 MODULE_DEPEND(altq_cbq, altq_rio, 1, 1, 1);
1167 #endif /* KLD_MODULE */
1168 #endif /* ALTQ3_COMPAT */
1170 #endif /* ALTQ_CBQ */