2 * Copyright (c) Sun Microsystems, Inc. 1993-1998 All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the SMCC Technology
18 * Development Group at Sun Microsystems, Inc.
20 * 4. The name of the Sun Microsystems, Inc nor may not be used to endorse or
21 * promote products derived from this software without specific prior
24 * SUN MICROSYSTEMS DOES NOT CLAIM MERCHANTABILITY OF THIS SOFTWARE OR THE
25 * SUITABILITY OF THIS SOFTWARE FOR ANY PARTICULAR PURPOSE. The software is
26 * provided "as is" without express or implied warranty of any kind.
28 * These notices must be retained in any copies of any part of this software.
30 * $KAME: altq_cbq.c,v 1.19 2003/09/17 14:23:25 kjc Exp $
36 #include "opt_inet6.h"
37 #ifdef ALTQ_CBQ /* cbq is enabled by ALTQ_CBQ option in opt_altq.h */
39 #include <sys/param.h>
40 #include <sys/malloc.h>
42 #include <sys/socket.h>
43 #include <sys/systm.h>
45 #include <sys/errno.h>
49 #include <sys/kernel.h>
53 #include <net/if_var.h>
54 #include <netinet/in.h>
56 #include <netpfil/pf/pf.h>
57 #include <netpfil/pf/pf_altq.h>
58 #include <netpfil/pf/pf_mtag.h>
59 #include <net/altq/altq.h>
60 #include <net/altq/altq_cbq.h>
62 #include <net/altq/altq_conf.h>
67 * Local Data structures.
69 static cbq_state_t *cbq_list = NULL;
73 * Forward Declarations.
75 static int cbq_class_destroy(cbq_state_t *, struct rm_class *);
76 static struct rm_class *clh_to_clp(cbq_state_t *, u_int32_t);
77 static int cbq_clear_interface(cbq_state_t *);
78 static int cbq_request(struct ifaltq *, int, void *);
79 static int cbq_enqueue(struct ifaltq *, struct mbuf *,
80 struct altq_pktattr *);
81 static struct mbuf *cbq_dequeue(struct ifaltq *, int);
82 static void cbqrestart(struct ifaltq *);
83 static void get_class_stats(class_stats_t *, struct rm_class *);
84 static void cbq_purge(cbq_state_t *);
86 static int cbq_add_class(struct cbq_add_class *);
87 static int cbq_delete_class(struct cbq_delete_class *);
88 static int cbq_modify_class(struct cbq_modify_class *);
89 static int cbq_class_create(cbq_state_t *, struct cbq_add_class *,
90 struct rm_class *, struct rm_class *);
91 static int cbq_clear_hierarchy(struct cbq_interface *);
92 static int cbq_set_enable(struct cbq_interface *, int);
93 static int cbq_ifattach(struct cbq_interface *);
94 static int cbq_ifdetach(struct cbq_interface *);
95 static int cbq_getstats(struct cbq_getstats *);
97 static int cbq_add_filter(struct cbq_add_filter *);
98 static int cbq_delete_filter(struct cbq_delete_filter *);
99 #endif /* ALTQ3_COMPAT */
103 * cbq_class_destroy(cbq_mod_state_t *, struct rm_class *) - This
104 * function destroys a given traffic class. Before destroying
105 * the class, all traffic for that class is released.
108 cbq_class_destroy(cbq_state_t *cbqp, struct rm_class *cl)
112 /* delete the class */
113 rmc_delete_class(&cbqp->ifnp, cl);
116 * free the class handle
118 for (i = 0; i < CBQ_MAX_CLASSES; i++)
119 if (cbqp->cbq_class_tbl[i] == cl)
120 cbqp->cbq_class_tbl[i] = NULL;
122 if (cl == cbqp->ifnp.root_)
123 cbqp->ifnp.root_ = NULL;
124 if (cl == cbqp->ifnp.default_)
125 cbqp->ifnp.default_ = NULL;
127 if (cl == cbqp->ifnp.ctl_)
128 cbqp->ifnp.ctl_ = NULL;
133 /* convert class handle to class pointer */
134 static struct rm_class *
135 clh_to_clp(cbq_state_t *cbqp, u_int32_t chandle)
143 * first, try optimistically the slot matching the lower bits of
144 * the handle. if it fails, do the linear table search.
146 i = chandle % CBQ_MAX_CLASSES;
147 if ((cl = cbqp->cbq_class_tbl[i]) != NULL &&
148 cl->stats_.handle == chandle)
150 for (i = 0; i < CBQ_MAX_CLASSES; i++)
151 if ((cl = cbqp->cbq_class_tbl[i]) != NULL &&
152 cl->stats_.handle == chandle)
158 cbq_clear_interface(cbq_state_t *cbqp)
163 #ifdef ALTQ3_CLFIER_COMPAT
164 /* free the filters for this interface */
165 acc_discard_filters(&cbqp->cbq_classifier, NULL, 1);
168 /* clear out the classes now */
171 for (i = 0; i < CBQ_MAX_CLASSES; i++) {
172 if ((cl = cbqp->cbq_class_tbl[i]) != NULL) {
173 if (is_a_parent_class(cl))
176 cbq_class_destroy(cbqp, cl);
177 cbqp->cbq_class_tbl[i] = NULL;
178 if (cl == cbqp->ifnp.root_)
179 cbqp->ifnp.root_ = NULL;
180 if (cl == cbqp->ifnp.default_)
181 cbqp->ifnp.default_ = NULL;
183 if (cl == cbqp->ifnp.ctl_)
184 cbqp->ifnp.ctl_ = NULL;
195 cbq_request(struct ifaltq *ifq, int req, void *arg)
197 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
199 IFQ_LOCK_ASSERT(ifq);
209 /* copy the stats info in rm_class to class_states_t */
211 get_class_stats(class_stats_t *statsp, struct rm_class *cl)
213 statsp->xmit_cnt = cl->stats_.xmit_cnt;
214 statsp->drop_cnt = cl->stats_.drop_cnt;
215 statsp->over = cl->stats_.over;
216 statsp->borrows = cl->stats_.borrows;
217 statsp->overactions = cl->stats_.overactions;
218 statsp->delays = cl->stats_.delays;
220 statsp->depth = cl->depth_;
221 statsp->priority = cl->pri_;
222 statsp->maxidle = cl->maxidle_;
223 statsp->minidle = cl->minidle_;
224 statsp->offtime = cl->offtime_;
225 statsp->qmax = qlimit(cl->q_);
226 statsp->ns_per_byte = cl->ns_per_byte_;
227 statsp->wrr_allot = cl->w_allotment_;
228 statsp->qcnt = qlen(cl->q_);
229 statsp->avgidle = cl->avgidle_;
231 statsp->qtype = qtype(cl->q_);
233 if (q_is_red(cl->q_))
234 red_getstats(cl->red_, &statsp->red[0]);
237 if (q_is_rio(cl->q_))
238 rio_getstats((rio_t *)cl->red_, &statsp->red[0]);
241 if (q_is_codel(cl->q_))
242 codel_getstats(cl->codel_, &statsp->codel);
247 cbq_pfattach(struct pf_altq *a)
252 if ((ifp = ifunit(a->ifname)) == NULL || a->altq_disc == NULL)
255 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, a->altq_disc,
256 cbq_enqueue, cbq_dequeue, cbq_request, NULL, NULL);
262 cbq_add_altq(struct pf_altq *a)
267 if ((ifp = ifunit(a->ifname)) == NULL)
269 if (!ALTQ_IS_READY(&ifp->if_snd))
272 /* allocate and initialize cbq_state_t */
273 cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_NOWAIT | M_ZERO);
276 CALLOUT_INIT(&cbqp->cbq_callout);
278 cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
280 /* keep the state in pf_altq */
287 cbq_remove_altq(struct pf_altq *a)
291 if ((cbqp = a->altq_disc) == NULL)
295 cbq_clear_interface(cbqp);
297 if (cbqp->ifnp.default_)
298 cbq_class_destroy(cbqp, cbqp->ifnp.default_);
299 if (cbqp->ifnp.root_)
300 cbq_class_destroy(cbqp, cbqp->ifnp.root_);
302 /* deallocate cbq_state_t */
303 free(cbqp, M_DEVBUF);
309 cbq_add_queue(struct pf_altq *a)
311 struct rm_class *borrow, *parent;
314 struct cbq_opts *opts;
317 if ((cbqp = a->altq_disc) == NULL)
323 * find a free slot in the class table. if the slot matching
324 * the lower bits of qid is free, use this slot. otherwise,
325 * use the first free slot.
327 i = a->qid % CBQ_MAX_CLASSES;
328 if (cbqp->cbq_class_tbl[i] != NULL) {
329 for (i = 0; i < CBQ_MAX_CLASSES; i++)
330 if (cbqp->cbq_class_tbl[i] == NULL)
332 if (i == CBQ_MAX_CLASSES)
336 opts = &a->pq_u.cbq_opts;
337 /* check parameters */
338 if (a->priority >= CBQ_MAXPRI)
341 /* Get pointers to parent and borrow classes. */
342 parent = clh_to_clp(cbqp, a->parent_qid);
343 if (opts->flags & CBQCLF_BORROW)
349 * A class must borrow from it's parent or it can not
350 * borrow at all. Hence, borrow can be null.
352 if (parent == NULL && (opts->flags & CBQCLF_ROOTCLASS) == 0) {
353 printf("cbq_add_queue: no parent class!\n");
357 if ((borrow != parent) && (borrow != NULL)) {
358 printf("cbq_add_class: borrow class != parent\n");
365 switch (opts->flags & CBQCLF_CLASSMASK) {
366 case CBQCLF_ROOTCLASS:
369 if (cbqp->ifnp.root_)
372 case CBQCLF_DEFCLASS:
373 if (cbqp->ifnp.default_)
381 /* more than two flags bits set */
386 * create a class. if this is a root class, initialize the
389 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
390 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, opts->ns_per_byte,
391 cbqrestart, a->qlimit, RM_MAXQUEUED,
392 opts->maxidle, opts->minidle, opts->offtime,
394 cl = cbqp->ifnp.root_;
396 cl = rmc_newclass(a->priority,
397 &cbqp->ifnp, opts->ns_per_byte,
398 rmc_delay_action, a->qlimit, parent, borrow,
399 opts->maxidle, opts->minidle, opts->offtime,
400 opts->pktsize, opts->flags);
405 /* return handle to user space. */
406 cl->stats_.handle = a->qid;
407 cl->stats_.depth = cl->depth_;
409 /* save the allocated class */
410 cbqp->cbq_class_tbl[i] = cl;
412 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
413 cbqp->ifnp.default_ = cl;
419 cbq_remove_queue(struct pf_altq *a)
425 if ((cbqp = a->altq_disc) == NULL)
428 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
431 /* if we are a parent class, then return an error. */
432 if (is_a_parent_class(cl))
435 /* delete the class */
436 rmc_delete_class(&cbqp->ifnp, cl);
439 * free the class handle
441 for (i = 0; i < CBQ_MAX_CLASSES; i++)
442 if (cbqp->cbq_class_tbl[i] == cl) {
443 cbqp->cbq_class_tbl[i] = NULL;
444 if (cl == cbqp->ifnp.root_)
445 cbqp->ifnp.root_ = NULL;
446 if (cl == cbqp->ifnp.default_)
447 cbqp->ifnp.default_ = NULL;
455 cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes)
462 if ((cbqp = altq_lookup(a->ifname, ALTQT_CBQ)) == NULL)
465 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
468 if (*nbytes < sizeof(stats))
471 get_class_stats(&stats, cl);
473 if ((error = copyout((caddr_t)&stats, ubuf, sizeof(stats))) != 0)
475 *nbytes = sizeof(stats);
481 * cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pattr)
482 * - Queue data packets.
484 * cbq_enqueue is set to ifp->if_altqenqueue and called by an upper
485 * layer (e.g. ether_output). cbq_enqueue queues the given packet
486 * to the cbq, then invokes the driver's start routine.
488 * Assumptions: called in splimp
489 * Returns: 0 if the queueing is successful.
490 * ENOBUFS if a packet dropping occurred as a result of
495 cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pktattr)
497 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
502 IFQ_LOCK_ASSERT(ifq);
504 /* grab class set by classifier */
505 if ((m->m_flags & M_PKTHDR) == 0) {
506 /* should not happen */
507 printf("altq: packet for %s does not have pkthdr\n",
508 ifq->altq_ifp->if_xname);
513 if ((t = pf_find_mtag(m)) != NULL)
514 cl = clh_to_clp(cbqp, t->qid);
516 else if ((ifq->altq_flags & ALTQF_CLASSIFY) && pktattr != NULL)
517 cl = pktattr->pattr_class;
520 cl = cbqp->ifnp.default_;
528 cl->pktattr_ = pktattr; /* save proto hdr used by ECN */
533 if (rmc_queue_packet(cl, m) != 0) {
534 /* drop occurred. some mbuf was freed in rmc_queue_packet. */
535 PKTCNTR_ADD(&cl->stats_.drop_cnt, len);
539 /* successfully queued. */
546 cbq_dequeue(struct ifaltq *ifq, int op)
548 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
551 IFQ_LOCK_ASSERT(ifq);
553 m = rmc_dequeue_next(&cbqp->ifnp, op);
555 if (m && op == ALTDQ_REMOVE) {
556 --cbqp->cbq_qlen; /* decrement # of packets in cbq */
559 /* Update the class. */
560 rmc_update_class_util(&cbqp->ifnp);
567 * cbqrestart(queue_t *) - Restart sending of data.
568 * called from rmc_restart in splimp via timeout after waking up
574 cbqrestart(struct ifaltq *ifq)
579 IFQ_LOCK_ASSERT(ifq);
581 if (!ALTQ_IS_ENABLED(ifq))
582 /* cbq must have been detached */
585 if ((cbqp = (cbq_state_t *)ifq->altq_disc) == NULL)
586 /* should not happen */
591 cbqp->cbq_qlen > 0 && (ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
593 (*ifp->if_start)(ifp);
598 static void cbq_purge(cbq_state_t *cbqp)
603 for (i = 0; i < CBQ_MAX_CLASSES; i++)
604 if ((cl = cbqp->cbq_class_tbl[i]) != NULL)
606 if (ALTQ_IS_ENABLED(cbqp->ifnp.ifq_))
607 cbqp->ifnp.ifq_->ifq_len = 0;
613 struct cbq_add_class *acp;
616 struct rm_class *borrow, *parent;
619 ifacename = acp->cbq_iface.cbq_ifacename;
620 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
623 /* check parameters */
624 if (acp->cbq_class.priority >= CBQ_MAXPRI ||
625 acp->cbq_class.maxq > CBQ_MAXQSIZE)
628 /* Get pointers to parent and borrow classes. */
629 parent = clh_to_clp(cbqp, acp->cbq_class.parent_class_handle);
630 borrow = clh_to_clp(cbqp, acp->cbq_class.borrow_class_handle);
633 * A class must borrow from it's parent or it can not
634 * borrow at all. Hence, borrow can be null.
636 if (parent == NULL && (acp->cbq_class.flags & CBQCLF_ROOTCLASS) == 0) {
637 printf("cbq_add_class: no parent class!\n");
641 if ((borrow != parent) && (borrow != NULL)) {
642 printf("cbq_add_class: borrow class != parent\n");
646 return cbq_class_create(cbqp, acp, parent, borrow);
650 cbq_delete_class(dcp)
651 struct cbq_delete_class *dcp;
657 ifacename = dcp->cbq_iface.cbq_ifacename;
658 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
661 if ((cl = clh_to_clp(cbqp, dcp->cbq_class_handle)) == NULL)
664 /* if we are a parent class, then return an error. */
665 if (is_a_parent_class(cl))
668 /* if a filter has a reference to this class delete the filter */
669 acc_discard_filters(&cbqp->cbq_classifier, cl, 0);
671 return cbq_class_destroy(cbqp, cl);
675 cbq_modify_class(acp)
676 struct cbq_modify_class *acp;
682 ifacename = acp->cbq_iface.cbq_ifacename;
683 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
686 /* Get pointer to this class */
687 if ((cl = clh_to_clp(cbqp, acp->cbq_class_handle)) == NULL)
690 if (rmc_modclass(cl, acp->cbq_class.nano_sec_per_byte,
691 acp->cbq_class.maxq, acp->cbq_class.maxidle,
692 acp->cbq_class.minidle, acp->cbq_class.offtime,
693 acp->cbq_class.pktsize) < 0)
700 * cbq_class_create(cbq_mod_state_t *cbqp, struct cbq_add_class *acp,
701 * struct rm_class *parent, struct rm_class *borrow)
703 * This function create a new traffic class in the CBQ class hierarchy of
704 * given parameters. The class that created is either the root, default,
705 * or a new dynamic class. If CBQ is not initilaized, the root class
709 cbq_class_create(cbqp, acp, parent, borrow)
711 struct cbq_add_class *acp;
712 struct rm_class *parent, *borrow;
715 cbq_class_spec_t *spec = &acp->cbq_class;
720 * allocate class handle
722 for (i = 1; i < CBQ_MAX_CLASSES; i++)
723 if (cbqp->cbq_class_tbl[i] == NULL)
725 if (i == CBQ_MAX_CLASSES)
727 chandle = i; /* use the slot number as class handle */
730 * create a class. if this is a root class, initialize the
733 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
734 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, spec->nano_sec_per_byte,
735 cbqrestart, spec->maxq, RM_MAXQUEUED,
736 spec->maxidle, spec->minidle, spec->offtime,
738 cl = cbqp->ifnp.root_;
740 cl = rmc_newclass(spec->priority,
741 &cbqp->ifnp, spec->nano_sec_per_byte,
742 rmc_delay_action, spec->maxq, parent, borrow,
743 spec->maxidle, spec->minidle, spec->offtime,
744 spec->pktsize, spec->flags);
749 /* return handle to user space. */
750 acp->cbq_class_handle = chandle;
752 cl->stats_.handle = chandle;
753 cl->stats_.depth = cl->depth_;
755 /* save the allocated class */
756 cbqp->cbq_class_tbl[i] = cl;
758 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
759 cbqp->ifnp.default_ = cl;
760 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_CTLCLASS)
761 cbqp->ifnp.ctl_ = cl;
768 struct cbq_add_filter *afp;
774 ifacename = afp->cbq_iface.cbq_ifacename;
775 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
778 /* Get the pointer to class. */
779 if ((cl = clh_to_clp(cbqp, afp->cbq_class_handle)) == NULL)
782 return acc_add_filter(&cbqp->cbq_classifier, &afp->cbq_filter,
783 cl, &afp->cbq_filter_handle);
787 cbq_delete_filter(dfp)
788 struct cbq_delete_filter *dfp;
793 ifacename = dfp->cbq_iface.cbq_ifacename;
794 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
797 return acc_delete_filter(&cbqp->cbq_classifier,
798 dfp->cbq_filter_handle);
802 * cbq_clear_hierarchy deletes all classes and their filters on the
806 cbq_clear_hierarchy(ifacep)
807 struct cbq_interface *ifacep;
812 ifacename = ifacep->cbq_ifacename;
813 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
816 return cbq_clear_interface(cbqp);
821 * cbq_set_enable(struct cbq_enable *ep) - this function processed the
822 * ioctl request to enable class based queueing. It searches the list
823 * of interfaces for the specified interface and then enables CBQ on
826 * Returns: 0, for no error.
827 * EBADF, for specified inteface not found.
831 cbq_set_enable(ep, enable)
832 struct cbq_interface *ep;
839 ifacename = ep->cbq_ifacename;
840 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
845 if (cbqp->ifnp.root_ == NULL || cbqp->ifnp.default_ == NULL ||
846 cbqp->ifnp.ctl_ == NULL) {
847 if (cbqp->ifnp.root_ == NULL)
848 printf("No Root Class for %s\n", ifacename);
849 if (cbqp->ifnp.default_ == NULL)
850 printf("No Default Class for %s\n", ifacename);
851 if (cbqp->ifnp.ctl_ == NULL)
852 printf("No Control Class for %s\n", ifacename);
854 } else if ((error = altq_enable(cbqp->ifnp.ifq_)) == 0) {
860 error = altq_disable(cbqp->ifnp.ifq_);
868 struct cbq_getstats *gsp;
874 class_stats_t stats, *usp;
877 ifacename = gsp->iface.cbq_ifacename;
878 nclasses = gsp->nclasses;
881 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
886 for (n = 0, i = 0; n < nclasses && i < CBQ_MAX_CLASSES; n++, i++) {
887 while ((cl = cbqp->cbq_class_tbl[i]) == NULL)
888 if (++i >= CBQ_MAX_CLASSES)
891 get_class_stats(&stats, cl);
892 stats.handle = cl->stats_.handle;
894 if ((error = copyout((caddr_t)&stats, (caddr_t)usp++,
895 sizeof(stats))) != 0)
906 struct cbq_interface *ifacep;
910 cbq_state_t *new_cbqp;
913 ifacename = ifacep->cbq_ifacename;
914 if ((ifp = ifunit(ifacename)) == NULL)
916 if (!ALTQ_IS_READY(&ifp->if_snd))
919 /* allocate and initialize cbq_state_t */
920 new_cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
921 if (new_cbqp == NULL)
923 bzero(new_cbqp, sizeof(cbq_state_t));
924 CALLOUT_INIT(&new_cbqp->cbq_callout);
926 new_cbqp->cbq_qlen = 0;
927 new_cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
930 * set CBQ to this ifnet structure.
932 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, new_cbqp,
933 cbq_enqueue, cbq_dequeue, cbq_request,
934 &new_cbqp->cbq_classifier, acc_classify);
936 free(new_cbqp, M_DEVBUF);
940 /* prepend to the list of cbq_state_t's. */
941 new_cbqp->cbq_next = cbq_list;
949 struct cbq_interface *ifacep;
954 ifacename = ifacep->cbq_ifacename;
955 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
958 (void)cbq_set_enable(ifacep, DISABLE);
960 cbq_clear_interface(cbqp);
962 /* remove CBQ from the ifnet structure. */
963 (void)altq_detach(cbqp->ifnp.ifq_);
965 /* remove from the list of cbq_state_t's. */
966 if (cbq_list == cbqp)
967 cbq_list = cbqp->cbq_next;
971 for (cp = cbq_list; cp != NULL; cp = cp->cbq_next)
972 if (cp->cbq_next == cbqp) {
973 cp->cbq_next = cbqp->cbq_next;
979 /* deallocate cbq_state_t */
980 free(cbqp, M_DEVBUF);
986 * cbq device interface
992 cbqopen(dev, flag, fmt, p)
995 #if (__FreeBSD_version > 500000)
1005 cbqclose(dev, flag, fmt, p)
1008 #if (__FreeBSD_version > 500000)
1015 struct cbq_interface iface;
1019 ifp = cbq_list->ifnp.ifq_->altq_ifp;
1020 sprintf(iface.cbq_ifacename, "%s", ifp->if_xname);
1021 err = cbq_ifdetach(&iface);
1022 if (err != 0 && error == 0)
1030 cbqioctl(dev, cmd, addr, flag, p)
1035 #if (__FreeBSD_version > 500000)
1043 /* check cmd for superuser only */
1046 /* currently only command that an ordinary user can call */
1049 #if (__FreeBSD_version > 700000)
1050 error = priv_check(p, PRIV_ALTQ_MANAGE);
1051 #elsif (__FreeBSD_version > 400000)
1054 error = suser(p->p_ucred, &p->p_acflag);
1064 error = cbq_set_enable((struct cbq_interface *)addr, ENABLE);
1068 error = cbq_set_enable((struct cbq_interface *)addr, DISABLE);
1071 case CBQ_ADD_FILTER:
1072 error = cbq_add_filter((struct cbq_add_filter *)addr);
1075 case CBQ_DEL_FILTER:
1076 error = cbq_delete_filter((struct cbq_delete_filter *)addr);
1080 error = cbq_add_class((struct cbq_add_class *)addr);
1084 error = cbq_delete_class((struct cbq_delete_class *)addr);
1087 case CBQ_MODIFY_CLASS:
1088 error = cbq_modify_class((struct cbq_modify_class *)addr);
1091 case CBQ_CLEAR_HIERARCHY:
1092 error = cbq_clear_hierarchy((struct cbq_interface *)addr);
1096 error = cbq_ifattach((struct cbq_interface *)addr);
1100 error = cbq_ifdetach((struct cbq_interface *)addr);
1104 error = cbq_getstats((struct cbq_getstats *)addr);
1117 static void cbq_class_dump(int);
1119 static void cbq_class_dump(i)
1122 struct rm_class *cl;
1123 rm_class_stats_t *s;
1124 struct _class_queue_ *q;
1126 if (cbq_list == NULL) {
1127 printf("cbq_class_dump: no cbq_state found\n");
1130 cl = cbq_list->cbq_class_tbl[i];
1132 printf("class %d cl=%p\n", i, cl);
1137 printf("pri=%d, depth=%d, maxrate=%d, allotment=%d\n",
1138 cl->pri_, cl->depth_, cl->maxrate_, cl->allotment_);
1139 printf("w_allotment=%d, bytes_alloc=%d, avgidle=%d, maxidle=%d\n",
1140 cl->w_allotment_, cl->bytes_alloc_, cl->avgidle_,
1142 printf("minidle=%d, offtime=%d, sleeping=%d, leaf=%d\n",
1143 cl->minidle_, cl->offtime_, cl->sleeping_, cl->leaf_);
1144 printf("handle=%d, depth=%d, packets=%d, bytes=%d\n",
1145 s->handle, s->depth,
1146 (int)s->xmit_cnt.packets, (int)s->xmit_cnt.bytes);
1147 printf("over=%d\n, borrows=%d, drops=%d, overactions=%d, delays=%d\n",
1148 s->over, s->borrows, (int)s->drop_cnt.packets,
1149 s->overactions, s->delays);
1150 printf("tail=%p, head=%p, qlen=%d, qlim=%d, qthresh=%d,qtype=%d\n",
1151 q->tail_, q->head_, q->qlen_, q->qlim_,
1152 q->qthresh_, q->qtype_);
1159 static struct altqsw cbq_sw =
1160 {"cbq", cbqopen, cbqclose, cbqioctl};
1162 ALTQ_MODULE(altq_cbq, ALTQT_CBQ, &cbq_sw);
1163 MODULE_DEPEND(altq_cbq, altq_red, 1, 1, 1);
1164 MODULE_DEPEND(altq_cbq, altq_rio, 1, 1, 1);
1166 #endif /* KLD_MODULE */
1167 #endif /* ALTQ3_COMPAT */
1169 #endif /* ALTQ_CBQ */