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 <net/if_var.h>
58 #include <netinet/in.h>
60 #include <netpfil/pf/pf.h>
61 #include <netpfil/pf/pf_altq.h>
62 #include <netpfil/pf/pf_mtag.h>
63 #include <altq/altq.h>
64 #include <altq/altq_cbq.h>
66 #include <altq/altq_conf.h>
71 * Local Data structures.
73 static cbq_state_t *cbq_list = NULL;
77 * Forward Declarations.
79 static int cbq_class_destroy(cbq_state_t *, struct rm_class *);
80 static struct rm_class *clh_to_clp(cbq_state_t *, u_int32_t);
81 static int cbq_clear_interface(cbq_state_t *);
82 static int cbq_request(struct ifaltq *, int, void *);
83 static int cbq_enqueue(struct ifaltq *, struct mbuf *,
84 struct altq_pktattr *);
85 static struct mbuf *cbq_dequeue(struct ifaltq *, int);
86 static void cbqrestart(struct ifaltq *);
87 static void get_class_stats(class_stats_t *, struct rm_class *);
88 static void cbq_purge(cbq_state_t *);
90 static int cbq_add_class(struct cbq_add_class *);
91 static int cbq_delete_class(struct cbq_delete_class *);
92 static int cbq_modify_class(struct cbq_modify_class *);
93 static int cbq_class_create(cbq_state_t *, struct cbq_add_class *,
94 struct rm_class *, struct rm_class *);
95 static int cbq_clear_hierarchy(struct cbq_interface *);
96 static int cbq_set_enable(struct cbq_interface *, int);
97 static int cbq_ifattach(struct cbq_interface *);
98 static int cbq_ifdetach(struct cbq_interface *);
99 static int cbq_getstats(struct cbq_getstats *);
101 static int cbq_add_filter(struct cbq_add_filter *);
102 static int cbq_delete_filter(struct cbq_delete_filter *);
103 #endif /* ALTQ3_COMPAT */
107 * cbq_class_destroy(cbq_mod_state_t *, struct rm_class *) - This
108 * function destroys a given traffic class. Before destroying
109 * the class, all traffic for that class is released.
112 cbq_class_destroy(cbq_state_t *cbqp, struct rm_class *cl)
116 /* delete the class */
117 rmc_delete_class(&cbqp->ifnp, cl);
120 * free the class handle
122 for (i = 0; i < CBQ_MAX_CLASSES; i++)
123 if (cbqp->cbq_class_tbl[i] == cl)
124 cbqp->cbq_class_tbl[i] = NULL;
126 if (cl == cbqp->ifnp.root_)
127 cbqp->ifnp.root_ = NULL;
128 if (cl == cbqp->ifnp.default_)
129 cbqp->ifnp.default_ = NULL;
131 if (cl == cbqp->ifnp.ctl_)
132 cbqp->ifnp.ctl_ = NULL;
137 /* convert class handle to class pointer */
138 static struct rm_class *
139 clh_to_clp(cbq_state_t *cbqp, u_int32_t chandle)
147 * first, try optimistically the slot matching the lower bits of
148 * the handle. if it fails, do the linear table search.
150 i = chandle % CBQ_MAX_CLASSES;
151 if ((cl = cbqp->cbq_class_tbl[i]) != NULL &&
152 cl->stats_.handle == chandle)
154 for (i = 0; i < CBQ_MAX_CLASSES; i++)
155 if ((cl = cbqp->cbq_class_tbl[i]) != NULL &&
156 cl->stats_.handle == chandle)
162 cbq_clear_interface(cbq_state_t *cbqp)
167 #ifdef ALTQ3_CLFIER_COMPAT
168 /* free the filters for this interface */
169 acc_discard_filters(&cbqp->cbq_classifier, NULL, 1);
172 /* clear out the classes now */
175 for (i = 0; i < CBQ_MAX_CLASSES; i++) {
176 if ((cl = cbqp->cbq_class_tbl[i]) != NULL) {
177 if (is_a_parent_class(cl))
180 cbq_class_destroy(cbqp, cl);
181 cbqp->cbq_class_tbl[i] = NULL;
182 if (cl == cbqp->ifnp.root_)
183 cbqp->ifnp.root_ = NULL;
184 if (cl == cbqp->ifnp.default_)
185 cbqp->ifnp.default_ = NULL;
187 if (cl == cbqp->ifnp.ctl_)
188 cbqp->ifnp.ctl_ = NULL;
199 cbq_request(struct ifaltq *ifq, int req, void *arg)
201 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
203 IFQ_LOCK_ASSERT(ifq);
213 /* copy the stats info in rm_class to class_states_t */
215 get_class_stats(class_stats_t *statsp, struct rm_class *cl)
217 statsp->xmit_cnt = cl->stats_.xmit_cnt;
218 statsp->drop_cnt = cl->stats_.drop_cnt;
219 statsp->over = cl->stats_.over;
220 statsp->borrows = cl->stats_.borrows;
221 statsp->overactions = cl->stats_.overactions;
222 statsp->delays = cl->stats_.delays;
224 statsp->depth = cl->depth_;
225 statsp->priority = cl->pri_;
226 statsp->maxidle = cl->maxidle_;
227 statsp->minidle = cl->minidle_;
228 statsp->offtime = cl->offtime_;
229 statsp->qmax = qlimit(cl->q_);
230 statsp->ns_per_byte = cl->ns_per_byte_;
231 statsp->wrr_allot = cl->w_allotment_;
232 statsp->qcnt = qlen(cl->q_);
233 statsp->avgidle = cl->avgidle_;
235 statsp->qtype = qtype(cl->q_);
237 if (q_is_red(cl->q_))
238 red_getstats(cl->red_, &statsp->red[0]);
241 if (q_is_rio(cl->q_))
242 rio_getstats((rio_t *)cl->red_, &statsp->red[0]);
247 cbq_pfattach(struct pf_altq *a)
252 if ((ifp = ifunit(a->ifname)) == NULL || a->altq_disc == NULL)
259 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, a->altq_disc,
260 cbq_enqueue, cbq_dequeue, cbq_request, NULL, NULL);
266 cbq_add_altq(struct pf_altq *a)
271 if ((ifp = ifunit(a->ifname)) == NULL)
273 if (!ALTQ_IS_READY(&ifp->if_snd))
276 /* allocate and initialize cbq_state_t */
277 cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_NOWAIT | M_ZERO);
280 CALLOUT_INIT(&cbqp->cbq_callout);
282 cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
284 /* keep the state in pf_altq */
291 cbq_remove_altq(struct pf_altq *a)
295 if ((cbqp = a->altq_disc) == NULL)
299 cbq_clear_interface(cbqp);
301 if (cbqp->ifnp.default_)
302 cbq_class_destroy(cbqp, cbqp->ifnp.default_);
303 if (cbqp->ifnp.root_)
304 cbq_class_destroy(cbqp, cbqp->ifnp.root_);
306 /* deallocate cbq_state_t */
307 free(cbqp, M_DEVBUF);
313 cbq_add_queue(struct pf_altq *a)
315 struct rm_class *borrow, *parent;
318 struct cbq_opts *opts;
321 if ((cbqp = a->altq_disc) == NULL)
327 * find a free slot in the class table. if the slot matching
328 * the lower bits of qid is free, use this slot. otherwise,
329 * use the first free slot.
331 i = a->qid % CBQ_MAX_CLASSES;
332 if (cbqp->cbq_class_tbl[i] != NULL) {
333 for (i = 0; i < CBQ_MAX_CLASSES; i++)
334 if (cbqp->cbq_class_tbl[i] == NULL)
336 if (i == CBQ_MAX_CLASSES)
340 opts = &a->pq_u.cbq_opts;
341 /* check parameters */
342 if (a->priority >= CBQ_MAXPRI)
345 /* Get pointers to parent and borrow classes. */
346 parent = clh_to_clp(cbqp, a->parent_qid);
347 if (opts->flags & CBQCLF_BORROW)
353 * A class must borrow from it's parent or it can not
354 * borrow at all. Hence, borrow can be null.
356 if (parent == NULL && (opts->flags & CBQCLF_ROOTCLASS) == 0) {
357 printf("cbq_add_queue: no parent class!\n");
361 if ((borrow != parent) && (borrow != NULL)) {
362 printf("cbq_add_class: borrow class != parent\n");
369 switch (opts->flags & CBQCLF_CLASSMASK) {
370 case CBQCLF_ROOTCLASS:
373 if (cbqp->ifnp.root_)
376 case CBQCLF_DEFCLASS:
377 if (cbqp->ifnp.default_)
385 /* more than two flags bits set */
390 * create a class. if this is a root class, initialize the
393 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
394 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, opts->ns_per_byte,
395 cbqrestart, a->qlimit, RM_MAXQUEUED,
396 opts->maxidle, opts->minidle, opts->offtime,
398 cl = cbqp->ifnp.root_;
400 cl = rmc_newclass(a->priority,
401 &cbqp->ifnp, opts->ns_per_byte,
402 rmc_delay_action, a->qlimit, parent, borrow,
403 opts->maxidle, opts->minidle, opts->offtime,
404 opts->pktsize, opts->flags);
409 /* return handle to user space. */
410 cl->stats_.handle = a->qid;
411 cl->stats_.depth = cl->depth_;
413 /* save the allocated class */
414 cbqp->cbq_class_tbl[i] = cl;
416 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
417 cbqp->ifnp.default_ = cl;
423 cbq_remove_queue(struct pf_altq *a)
429 if ((cbqp = a->altq_disc) == NULL)
432 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
435 /* if we are a parent class, then return an error. */
436 if (is_a_parent_class(cl))
439 /* delete the class */
440 rmc_delete_class(&cbqp->ifnp, cl);
443 * free the class handle
445 for (i = 0; i < CBQ_MAX_CLASSES; i++)
446 if (cbqp->cbq_class_tbl[i] == cl) {
447 cbqp->cbq_class_tbl[i] = NULL;
448 if (cl == cbqp->ifnp.root_)
449 cbqp->ifnp.root_ = NULL;
450 if (cl == cbqp->ifnp.default_)
451 cbqp->ifnp.default_ = NULL;
459 cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes)
466 if ((cbqp = altq_lookup(a->ifname, ALTQT_CBQ)) == NULL)
469 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
472 if (*nbytes < sizeof(stats))
475 get_class_stats(&stats, cl);
477 if ((error = copyout((caddr_t)&stats, ubuf, sizeof(stats))) != 0)
479 *nbytes = sizeof(stats);
485 * cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pattr)
486 * - Queue data packets.
488 * cbq_enqueue is set to ifp->if_altqenqueue and called by an upper
489 * layer (e.g. ether_output). cbq_enqueue queues the given packet
490 * to the cbq, then invokes the driver's start routine.
492 * Assumptions: called in splimp
493 * Returns: 0 if the queueing is successful.
494 * ENOBUFS if a packet dropping occurred as a result of
499 cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pktattr)
501 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
506 IFQ_LOCK_ASSERT(ifq);
508 /* grab class set by classifier */
509 if ((m->m_flags & M_PKTHDR) == 0) {
510 /* should not happen */
511 printf("altq: packet for %s does not have pkthdr\n",
512 ifq->altq_ifp->if_xname);
517 if ((t = pf_find_mtag(m)) != NULL)
518 cl = clh_to_clp(cbqp, t->qid);
520 else if ((ifq->altq_flags & ALTQF_CLASSIFY) && pktattr != NULL)
521 cl = pktattr->pattr_class;
524 cl = cbqp->ifnp.default_;
532 cl->pktattr_ = pktattr; /* save proto hdr used by ECN */
537 if (rmc_queue_packet(cl, m) != 0) {
538 /* drop occurred. some mbuf was freed in rmc_queue_packet. */
539 PKTCNTR_ADD(&cl->stats_.drop_cnt, len);
543 /* successfully queued. */
550 cbq_dequeue(struct ifaltq *ifq, int op)
552 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
555 IFQ_LOCK_ASSERT(ifq);
557 m = rmc_dequeue_next(&cbqp->ifnp, op);
559 if (m && op == ALTDQ_REMOVE) {
560 --cbqp->cbq_qlen; /* decrement # of packets in cbq */
563 /* Update the class. */
564 rmc_update_class_util(&cbqp->ifnp);
571 * cbqrestart(queue_t *) - Restart sending of data.
572 * called from rmc_restart in splimp via timeout after waking up
578 cbqrestart(struct ifaltq *ifq)
583 IFQ_LOCK_ASSERT(ifq);
585 if (!ALTQ_IS_ENABLED(ifq))
586 /* cbq must have been detached */
589 if ((cbqp = (cbq_state_t *)ifq->altq_disc) == NULL)
590 /* should not happen */
595 cbqp->cbq_qlen > 0 && (ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
597 (*ifp->if_start)(ifp);
602 static void cbq_purge(cbq_state_t *cbqp)
607 for (i = 0; i < CBQ_MAX_CLASSES; i++)
608 if ((cl = cbqp->cbq_class_tbl[i]) != NULL)
610 if (ALTQ_IS_ENABLED(cbqp->ifnp.ifq_))
611 cbqp->ifnp.ifq_->ifq_len = 0;
617 struct cbq_add_class *acp;
620 struct rm_class *borrow, *parent;
623 ifacename = acp->cbq_iface.cbq_ifacename;
624 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
627 /* check parameters */
628 if (acp->cbq_class.priority >= CBQ_MAXPRI ||
629 acp->cbq_class.maxq > CBQ_MAXQSIZE)
632 /* Get pointers to parent and borrow classes. */
633 parent = clh_to_clp(cbqp, acp->cbq_class.parent_class_handle);
634 borrow = clh_to_clp(cbqp, acp->cbq_class.borrow_class_handle);
637 * A class must borrow from it's parent or it can not
638 * borrow at all. Hence, borrow can be null.
640 if (parent == NULL && (acp->cbq_class.flags & CBQCLF_ROOTCLASS) == 0) {
641 printf("cbq_add_class: no parent class!\n");
645 if ((borrow != parent) && (borrow != NULL)) {
646 printf("cbq_add_class: borrow class != parent\n");
650 return cbq_class_create(cbqp, acp, parent, borrow);
654 cbq_delete_class(dcp)
655 struct cbq_delete_class *dcp;
661 ifacename = dcp->cbq_iface.cbq_ifacename;
662 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
665 if ((cl = clh_to_clp(cbqp, dcp->cbq_class_handle)) == NULL)
668 /* if we are a parent class, then return an error. */
669 if (is_a_parent_class(cl))
672 /* if a filter has a reference to this class delete the filter */
673 acc_discard_filters(&cbqp->cbq_classifier, cl, 0);
675 return cbq_class_destroy(cbqp, cl);
679 cbq_modify_class(acp)
680 struct cbq_modify_class *acp;
686 ifacename = acp->cbq_iface.cbq_ifacename;
687 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
690 /* Get pointer to this class */
691 if ((cl = clh_to_clp(cbqp, acp->cbq_class_handle)) == NULL)
694 if (rmc_modclass(cl, acp->cbq_class.nano_sec_per_byte,
695 acp->cbq_class.maxq, acp->cbq_class.maxidle,
696 acp->cbq_class.minidle, acp->cbq_class.offtime,
697 acp->cbq_class.pktsize) < 0)
704 * cbq_class_create(cbq_mod_state_t *cbqp, struct cbq_add_class *acp,
705 * struct rm_class *parent, struct rm_class *borrow)
707 * This function create a new traffic class in the CBQ class hierarchy of
708 * given paramters. The class that created is either the root, default,
709 * or a new dynamic class. If CBQ is not initilaized, the the root class
713 cbq_class_create(cbqp, acp, parent, borrow)
715 struct cbq_add_class *acp;
716 struct rm_class *parent, *borrow;
719 cbq_class_spec_t *spec = &acp->cbq_class;
724 * allocate class handle
726 for (i = 1; i < CBQ_MAX_CLASSES; i++)
727 if (cbqp->cbq_class_tbl[i] == NULL)
729 if (i == CBQ_MAX_CLASSES)
731 chandle = i; /* use the slot number as class handle */
734 * create a class. if this is a root class, initialize the
737 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
738 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, spec->nano_sec_per_byte,
739 cbqrestart, spec->maxq, RM_MAXQUEUED,
740 spec->maxidle, spec->minidle, spec->offtime,
742 cl = cbqp->ifnp.root_;
744 cl = rmc_newclass(spec->priority,
745 &cbqp->ifnp, spec->nano_sec_per_byte,
746 rmc_delay_action, spec->maxq, parent, borrow,
747 spec->maxidle, spec->minidle, spec->offtime,
748 spec->pktsize, spec->flags);
753 /* return handle to user space. */
754 acp->cbq_class_handle = chandle;
756 cl->stats_.handle = chandle;
757 cl->stats_.depth = cl->depth_;
759 /* save the allocated class */
760 cbqp->cbq_class_tbl[i] = cl;
762 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
763 cbqp->ifnp.default_ = cl;
764 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_CTLCLASS)
765 cbqp->ifnp.ctl_ = cl;
772 struct cbq_add_filter *afp;
778 ifacename = afp->cbq_iface.cbq_ifacename;
779 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
782 /* Get the pointer to class. */
783 if ((cl = clh_to_clp(cbqp, afp->cbq_class_handle)) == NULL)
786 return acc_add_filter(&cbqp->cbq_classifier, &afp->cbq_filter,
787 cl, &afp->cbq_filter_handle);
791 cbq_delete_filter(dfp)
792 struct cbq_delete_filter *dfp;
797 ifacename = dfp->cbq_iface.cbq_ifacename;
798 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
801 return acc_delete_filter(&cbqp->cbq_classifier,
802 dfp->cbq_filter_handle);
806 * cbq_clear_hierarchy deletes all classes and their filters on the
810 cbq_clear_hierarchy(ifacep)
811 struct cbq_interface *ifacep;
816 ifacename = ifacep->cbq_ifacename;
817 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
820 return cbq_clear_interface(cbqp);
825 * cbq_set_enable(struct cbq_enable *ep) - this function processed the
826 * ioctl request to enable class based queueing. It searches the list
827 * of interfaces for the specified interface and then enables CBQ on
830 * Returns: 0, for no error.
831 * EBADF, for specified inteface not found.
835 cbq_set_enable(ep, enable)
836 struct cbq_interface *ep;
843 ifacename = ep->cbq_ifacename;
844 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
849 if (cbqp->ifnp.root_ == NULL || cbqp->ifnp.default_ == NULL ||
850 cbqp->ifnp.ctl_ == NULL) {
851 if (cbqp->ifnp.root_ == NULL)
852 printf("No Root Class for %s\n", ifacename);
853 if (cbqp->ifnp.default_ == NULL)
854 printf("No Default Class for %s\n", ifacename);
855 if (cbqp->ifnp.ctl_ == NULL)
856 printf("No Control Class for %s\n", ifacename);
858 } else if ((error = altq_enable(cbqp->ifnp.ifq_)) == 0) {
864 error = altq_disable(cbqp->ifnp.ifq_);
872 struct cbq_getstats *gsp;
878 class_stats_t stats, *usp;
881 ifacename = gsp->iface.cbq_ifacename;
882 nclasses = gsp->nclasses;
885 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
890 for (n = 0, i = 0; n < nclasses && i < CBQ_MAX_CLASSES; n++, i++) {
891 while ((cl = cbqp->cbq_class_tbl[i]) == NULL)
892 if (++i >= CBQ_MAX_CLASSES)
895 get_class_stats(&stats, cl);
896 stats.handle = cl->stats_.handle;
898 if ((error = copyout((caddr_t)&stats, (caddr_t)usp++,
899 sizeof(stats))) != 0)
910 struct cbq_interface *ifacep;
914 cbq_state_t *new_cbqp;
917 ifacename = ifacep->cbq_ifacename;
918 if ((ifp = ifunit(ifacename)) == NULL)
920 if (!ALTQ_IS_READY(&ifp->if_snd))
923 /* allocate and initialize cbq_state_t */
924 new_cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
925 if (new_cbqp == NULL)
927 bzero(new_cbqp, sizeof(cbq_state_t));
928 CALLOUT_INIT(&new_cbqp->cbq_callout);
930 new_cbqp->cbq_qlen = 0;
931 new_cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
934 * set CBQ to this ifnet structure.
936 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, new_cbqp,
937 cbq_enqueue, cbq_dequeue, cbq_request,
938 &new_cbqp->cbq_classifier, acc_classify);
940 free(new_cbqp, M_DEVBUF);
944 /* prepend to the list of cbq_state_t's. */
945 new_cbqp->cbq_next = cbq_list;
953 struct cbq_interface *ifacep;
958 ifacename = ifacep->cbq_ifacename;
959 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
962 (void)cbq_set_enable(ifacep, DISABLE);
964 cbq_clear_interface(cbqp);
966 /* remove CBQ from the ifnet structure. */
967 (void)altq_detach(cbqp->ifnp.ifq_);
969 /* remove from the list of cbq_state_t's. */
970 if (cbq_list == cbqp)
971 cbq_list = cbqp->cbq_next;
975 for (cp = cbq_list; cp != NULL; cp = cp->cbq_next)
976 if (cp->cbq_next == cbqp) {
977 cp->cbq_next = cbqp->cbq_next;
983 /* deallocate cbq_state_t */
984 free(cbqp, M_DEVBUF);
990 * cbq device interface
996 cbqopen(dev, flag, fmt, p)
999 #if (__FreeBSD_version > 500000)
1009 cbqclose(dev, flag, fmt, p)
1012 #if (__FreeBSD_version > 500000)
1019 struct cbq_interface iface;
1023 ifp = cbq_list->ifnp.ifq_->altq_ifp;
1024 sprintf(iface.cbq_ifacename, "%s", ifp->if_xname);
1025 err = cbq_ifdetach(&iface);
1026 if (err != 0 && error == 0)
1034 cbqioctl(dev, cmd, addr, flag, p)
1039 #if (__FreeBSD_version > 500000)
1047 /* check cmd for superuser only */
1050 /* currently only command that an ordinary user can call */
1053 #if (__FreeBSD_version > 700000)
1054 error = priv_check(p, PRIV_ALTQ_MANAGE);
1055 #elsif (__FreeBSD_version > 400000)
1058 error = suser(p->p_ucred, &p->p_acflag);
1068 error = cbq_set_enable((struct cbq_interface *)addr, ENABLE);
1072 error = cbq_set_enable((struct cbq_interface *)addr, DISABLE);
1075 case CBQ_ADD_FILTER:
1076 error = cbq_add_filter((struct cbq_add_filter *)addr);
1079 case CBQ_DEL_FILTER:
1080 error = cbq_delete_filter((struct cbq_delete_filter *)addr);
1084 error = cbq_add_class((struct cbq_add_class *)addr);
1088 error = cbq_delete_class((struct cbq_delete_class *)addr);
1091 case CBQ_MODIFY_CLASS:
1092 error = cbq_modify_class((struct cbq_modify_class *)addr);
1095 case CBQ_CLEAR_HIERARCHY:
1096 error = cbq_clear_hierarchy((struct cbq_interface *)addr);
1100 error = cbq_ifattach((struct cbq_interface *)addr);
1104 error = cbq_ifdetach((struct cbq_interface *)addr);
1108 error = cbq_getstats((struct cbq_getstats *)addr);
1121 static void cbq_class_dump(int);
1123 static void cbq_class_dump(i)
1126 struct rm_class *cl;
1127 rm_class_stats_t *s;
1128 struct _class_queue_ *q;
1130 if (cbq_list == NULL) {
1131 printf("cbq_class_dump: no cbq_state found\n");
1134 cl = cbq_list->cbq_class_tbl[i];
1136 printf("class %d cl=%p\n", i, cl);
1141 printf("pri=%d, depth=%d, maxrate=%d, allotment=%d\n",
1142 cl->pri_, cl->depth_, cl->maxrate_, cl->allotment_);
1143 printf("w_allotment=%d, bytes_alloc=%d, avgidle=%d, maxidle=%d\n",
1144 cl->w_allotment_, cl->bytes_alloc_, cl->avgidle_,
1146 printf("minidle=%d, offtime=%d, sleeping=%d, leaf=%d\n",
1147 cl->minidle_, cl->offtime_, cl->sleeping_, cl->leaf_);
1148 printf("handle=%d, depth=%d, packets=%d, bytes=%d\n",
1149 s->handle, s->depth,
1150 (int)s->xmit_cnt.packets, (int)s->xmit_cnt.bytes);
1151 printf("over=%d\n, borrows=%d, drops=%d, overactions=%d, delays=%d\n",
1152 s->over, s->borrows, (int)s->drop_cnt.packets,
1153 s->overactions, s->delays);
1154 printf("tail=%p, head=%p, qlen=%d, qlim=%d, qthresh=%d,qtype=%d\n",
1155 q->tail_, q->head_, q->qlen_, q->qlim_,
1156 q->qthresh_, q->qtype_);
1163 static struct altqsw cbq_sw =
1164 {"cbq", cbqopen, cbqclose, cbqioctl};
1166 ALTQ_MODULE(altq_cbq, ALTQT_CBQ, &cbq_sw);
1167 MODULE_DEPEND(altq_cbq, altq_red, 1, 1, 1);
1168 MODULE_DEPEND(altq_cbq, altq_rio, 1, 1, 1);
1170 #endif /* KLD_MODULE */
1171 #endif /* ALTQ3_COMPAT */
1173 #endif /* ALTQ_CBQ */