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_WAITOK);
277 bzero(cbqp, sizeof(cbq_state_t));
278 CALLOUT_INIT(&cbqp->cbq_callout);
280 cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
282 /* keep the state in pf_altq */
289 cbq_remove_altq(struct pf_altq *a)
293 if ((cbqp = a->altq_disc) == NULL)
297 cbq_clear_interface(cbqp);
299 if (cbqp->ifnp.default_)
300 cbq_class_destroy(cbqp, cbqp->ifnp.default_);
301 if (cbqp->ifnp.root_)
302 cbq_class_destroy(cbqp, cbqp->ifnp.root_);
304 /* deallocate cbq_state_t */
305 free(cbqp, M_DEVBUF);
311 cbq_add_queue(struct pf_altq *a)
313 struct rm_class *borrow, *parent;
316 struct cbq_opts *opts;
319 if ((cbqp = a->altq_disc) == NULL)
325 * find a free slot in the class table. if the slot matching
326 * the lower bits of qid is free, use this slot. otherwise,
327 * use the first free slot.
329 i = a->qid % CBQ_MAX_CLASSES;
330 if (cbqp->cbq_class_tbl[i] != NULL) {
331 for (i = 0; i < CBQ_MAX_CLASSES; i++)
332 if (cbqp->cbq_class_tbl[i] == NULL)
334 if (i == CBQ_MAX_CLASSES)
338 opts = &a->pq_u.cbq_opts;
339 /* check parameters */
340 if (a->priority >= CBQ_MAXPRI)
343 /* Get pointers to parent and borrow classes. */
344 parent = clh_to_clp(cbqp, a->parent_qid);
345 if (opts->flags & CBQCLF_BORROW)
351 * A class must borrow from it's parent or it can not
352 * borrow at all. Hence, borrow can be null.
354 if (parent == NULL && (opts->flags & CBQCLF_ROOTCLASS) == 0) {
355 printf("cbq_add_queue: no parent class!\n");
359 if ((borrow != parent) && (borrow != NULL)) {
360 printf("cbq_add_class: borrow class != parent\n");
367 switch (opts->flags & CBQCLF_CLASSMASK) {
368 case CBQCLF_ROOTCLASS:
371 if (cbqp->ifnp.root_)
374 case CBQCLF_DEFCLASS:
375 if (cbqp->ifnp.default_)
383 /* more than two flags bits set */
388 * create a class. if this is a root class, initialize the
391 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
392 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, opts->ns_per_byte,
393 cbqrestart, a->qlimit, RM_MAXQUEUED,
394 opts->maxidle, opts->minidle, opts->offtime,
396 cl = cbqp->ifnp.root_;
398 cl = rmc_newclass(a->priority,
399 &cbqp->ifnp, opts->ns_per_byte,
400 rmc_delay_action, a->qlimit, parent, borrow,
401 opts->maxidle, opts->minidle, opts->offtime,
402 opts->pktsize, opts->flags);
407 /* return handle to user space. */
408 cl->stats_.handle = a->qid;
409 cl->stats_.depth = cl->depth_;
411 /* save the allocated class */
412 cbqp->cbq_class_tbl[i] = cl;
414 if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
415 cbqp->ifnp.default_ = cl;
421 cbq_remove_queue(struct pf_altq *a)
427 if ((cbqp = a->altq_disc) == NULL)
430 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
433 /* if we are a parent class, then return an error. */
434 if (is_a_parent_class(cl))
437 /* delete the class */
438 rmc_delete_class(&cbqp->ifnp, cl);
441 * free the class handle
443 for (i = 0; i < CBQ_MAX_CLASSES; i++)
444 if (cbqp->cbq_class_tbl[i] == cl) {
445 cbqp->cbq_class_tbl[i] = NULL;
446 if (cl == cbqp->ifnp.root_)
447 cbqp->ifnp.root_ = NULL;
448 if (cl == cbqp->ifnp.default_)
449 cbqp->ifnp.default_ = NULL;
457 cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes)
464 if ((cbqp = altq_lookup(a->ifname, ALTQT_CBQ)) == NULL)
467 if ((cl = clh_to_clp(cbqp, a->qid)) == NULL)
470 if (*nbytes < sizeof(stats))
473 get_class_stats(&stats, cl);
475 if ((error = copyout((caddr_t)&stats, ubuf, sizeof(stats))) != 0)
477 *nbytes = sizeof(stats);
483 * cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pattr)
484 * - Queue data packets.
486 * cbq_enqueue is set to ifp->if_altqenqueue and called by an upper
487 * layer (e.g. ether_output). cbq_enqueue queues the given packet
488 * to the cbq, then invokes the driver's start routine.
490 * Assumptions: called in splimp
491 * Returns: 0 if the queueing is successful.
492 * ENOBUFS if a packet dropping occurred as a result of
497 cbq_enqueue(struct ifaltq *ifq, struct mbuf *m, struct altq_pktattr *pktattr)
499 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
504 IFQ_LOCK_ASSERT(ifq);
506 /* grab class set by classifier */
507 if ((m->m_flags & M_PKTHDR) == 0) {
508 /* should not happen */
509 printf("altq: packet for %s does not have pkthdr\n",
510 ifq->altq_ifp->if_xname);
515 if ((t = pf_find_mtag(m)) != NULL)
516 cl = clh_to_clp(cbqp, t->qid);
518 else if ((ifq->altq_flags & ALTQF_CLASSIFY) && pktattr != NULL)
519 cl = pktattr->pattr_class;
522 cl = cbqp->ifnp.default_;
530 cl->pktattr_ = pktattr; /* save proto hdr used by ECN */
535 if (rmc_queue_packet(cl, m) != 0) {
536 /* drop occurred. some mbuf was freed in rmc_queue_packet. */
537 PKTCNTR_ADD(&cl->stats_.drop_cnt, len);
541 /* successfully queued. */
548 cbq_dequeue(struct ifaltq *ifq, int op)
550 cbq_state_t *cbqp = (cbq_state_t *)ifq->altq_disc;
553 IFQ_LOCK_ASSERT(ifq);
555 m = rmc_dequeue_next(&cbqp->ifnp, op);
557 if (m && op == ALTDQ_REMOVE) {
558 --cbqp->cbq_qlen; /* decrement # of packets in cbq */
561 /* Update the class. */
562 rmc_update_class_util(&cbqp->ifnp);
569 * cbqrestart(queue_t *) - Restart sending of data.
570 * called from rmc_restart in splimp via timeout after waking up
576 cbqrestart(struct ifaltq *ifq)
581 IFQ_LOCK_ASSERT(ifq);
583 if (!ALTQ_IS_ENABLED(ifq))
584 /* cbq must have been detached */
587 if ((cbqp = (cbq_state_t *)ifq->altq_disc) == NULL)
588 /* should not happen */
593 cbqp->cbq_qlen > 0 && (ifp->if_drv_flags & IFF_DRV_OACTIVE) == 0) {
595 (*ifp->if_start)(ifp);
600 static void cbq_purge(cbq_state_t *cbqp)
605 for (i = 0; i < CBQ_MAX_CLASSES; i++)
606 if ((cl = cbqp->cbq_class_tbl[i]) != NULL)
608 if (ALTQ_IS_ENABLED(cbqp->ifnp.ifq_))
609 cbqp->ifnp.ifq_->ifq_len = 0;
615 struct cbq_add_class *acp;
618 struct rm_class *borrow, *parent;
621 ifacename = acp->cbq_iface.cbq_ifacename;
622 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
625 /* check parameters */
626 if (acp->cbq_class.priority >= CBQ_MAXPRI ||
627 acp->cbq_class.maxq > CBQ_MAXQSIZE)
630 /* Get pointers to parent and borrow classes. */
631 parent = clh_to_clp(cbqp, acp->cbq_class.parent_class_handle);
632 borrow = clh_to_clp(cbqp, acp->cbq_class.borrow_class_handle);
635 * A class must borrow from it's parent or it can not
636 * borrow at all. Hence, borrow can be null.
638 if (parent == NULL && (acp->cbq_class.flags & CBQCLF_ROOTCLASS) == 0) {
639 printf("cbq_add_class: no parent class!\n");
643 if ((borrow != parent) && (borrow != NULL)) {
644 printf("cbq_add_class: borrow class != parent\n");
648 return cbq_class_create(cbqp, acp, parent, borrow);
652 cbq_delete_class(dcp)
653 struct cbq_delete_class *dcp;
659 ifacename = dcp->cbq_iface.cbq_ifacename;
660 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
663 if ((cl = clh_to_clp(cbqp, dcp->cbq_class_handle)) == NULL)
666 /* if we are a parent class, then return an error. */
667 if (is_a_parent_class(cl))
670 /* if a filter has a reference to this class delete the filter */
671 acc_discard_filters(&cbqp->cbq_classifier, cl, 0);
673 return cbq_class_destroy(cbqp, cl);
677 cbq_modify_class(acp)
678 struct cbq_modify_class *acp;
684 ifacename = acp->cbq_iface.cbq_ifacename;
685 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
688 /* Get pointer to this class */
689 if ((cl = clh_to_clp(cbqp, acp->cbq_class_handle)) == NULL)
692 if (rmc_modclass(cl, acp->cbq_class.nano_sec_per_byte,
693 acp->cbq_class.maxq, acp->cbq_class.maxidle,
694 acp->cbq_class.minidle, acp->cbq_class.offtime,
695 acp->cbq_class.pktsize) < 0)
702 * cbq_class_create(cbq_mod_state_t *cbqp, struct cbq_add_class *acp,
703 * struct rm_class *parent, struct rm_class *borrow)
705 * This function create a new traffic class in the CBQ class hierarchy of
706 * given paramters. The class that created is either the root, default,
707 * or a new dynamic class. If CBQ is not initilaized, the the root class
711 cbq_class_create(cbqp, acp, parent, borrow)
713 struct cbq_add_class *acp;
714 struct rm_class *parent, *borrow;
717 cbq_class_spec_t *spec = &acp->cbq_class;
722 * allocate class handle
724 for (i = 1; i < CBQ_MAX_CLASSES; i++)
725 if (cbqp->cbq_class_tbl[i] == NULL)
727 if (i == CBQ_MAX_CLASSES)
729 chandle = i; /* use the slot number as class handle */
732 * create a class. if this is a root class, initialize the
735 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) {
736 rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, spec->nano_sec_per_byte,
737 cbqrestart, spec->maxq, RM_MAXQUEUED,
738 spec->maxidle, spec->minidle, spec->offtime,
740 cl = cbqp->ifnp.root_;
742 cl = rmc_newclass(spec->priority,
743 &cbqp->ifnp, spec->nano_sec_per_byte,
744 rmc_delay_action, spec->maxq, parent, borrow,
745 spec->maxidle, spec->minidle, spec->offtime,
746 spec->pktsize, spec->flags);
751 /* return handle to user space. */
752 acp->cbq_class_handle = chandle;
754 cl->stats_.handle = chandle;
755 cl->stats_.depth = cl->depth_;
757 /* save the allocated class */
758 cbqp->cbq_class_tbl[i] = cl;
760 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS)
761 cbqp->ifnp.default_ = cl;
762 if ((spec->flags & CBQCLF_CLASSMASK) == CBQCLF_CTLCLASS)
763 cbqp->ifnp.ctl_ = cl;
770 struct cbq_add_filter *afp;
776 ifacename = afp->cbq_iface.cbq_ifacename;
777 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
780 /* Get the pointer to class. */
781 if ((cl = clh_to_clp(cbqp, afp->cbq_class_handle)) == NULL)
784 return acc_add_filter(&cbqp->cbq_classifier, &afp->cbq_filter,
785 cl, &afp->cbq_filter_handle);
789 cbq_delete_filter(dfp)
790 struct cbq_delete_filter *dfp;
795 ifacename = dfp->cbq_iface.cbq_ifacename;
796 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
799 return acc_delete_filter(&cbqp->cbq_classifier,
800 dfp->cbq_filter_handle);
804 * cbq_clear_hierarchy deletes all classes and their filters on the
808 cbq_clear_hierarchy(ifacep)
809 struct cbq_interface *ifacep;
814 ifacename = ifacep->cbq_ifacename;
815 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
818 return cbq_clear_interface(cbqp);
823 * cbq_set_enable(struct cbq_enable *ep) - this function processed the
824 * ioctl request to enable class based queueing. It searches the list
825 * of interfaces for the specified interface and then enables CBQ on
828 * Returns: 0, for no error.
829 * EBADF, for specified inteface not found.
833 cbq_set_enable(ep, enable)
834 struct cbq_interface *ep;
841 ifacename = ep->cbq_ifacename;
842 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
847 if (cbqp->ifnp.root_ == NULL || cbqp->ifnp.default_ == NULL ||
848 cbqp->ifnp.ctl_ == NULL) {
849 if (cbqp->ifnp.root_ == NULL)
850 printf("No Root Class for %s\n", ifacename);
851 if (cbqp->ifnp.default_ == NULL)
852 printf("No Default Class for %s\n", ifacename);
853 if (cbqp->ifnp.ctl_ == NULL)
854 printf("No Control Class for %s\n", ifacename);
856 } else if ((error = altq_enable(cbqp->ifnp.ifq_)) == 0) {
862 error = altq_disable(cbqp->ifnp.ifq_);
870 struct cbq_getstats *gsp;
876 class_stats_t stats, *usp;
879 ifacename = gsp->iface.cbq_ifacename;
880 nclasses = gsp->nclasses;
883 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
888 for (n = 0, i = 0; n < nclasses && i < CBQ_MAX_CLASSES; n++, i++) {
889 while ((cl = cbqp->cbq_class_tbl[i]) == NULL)
890 if (++i >= CBQ_MAX_CLASSES)
893 get_class_stats(&stats, cl);
894 stats.handle = cl->stats_.handle;
896 if ((error = copyout((caddr_t)&stats, (caddr_t)usp++,
897 sizeof(stats))) != 0)
908 struct cbq_interface *ifacep;
912 cbq_state_t *new_cbqp;
915 ifacename = ifacep->cbq_ifacename;
916 if ((ifp = ifunit(ifacename)) == NULL)
918 if (!ALTQ_IS_READY(&ifp->if_snd))
921 /* allocate and initialize cbq_state_t */
922 new_cbqp = malloc(sizeof(cbq_state_t), M_DEVBUF, M_WAITOK);
923 if (new_cbqp == NULL)
925 bzero(new_cbqp, sizeof(cbq_state_t));
926 CALLOUT_INIT(&new_cbqp->cbq_callout);
928 new_cbqp->cbq_qlen = 0;
929 new_cbqp->ifnp.ifq_ = &ifp->if_snd; /* keep the ifq */
932 * set CBQ to this ifnet structure.
934 error = altq_attach(&ifp->if_snd, ALTQT_CBQ, new_cbqp,
935 cbq_enqueue, cbq_dequeue, cbq_request,
936 &new_cbqp->cbq_classifier, acc_classify);
938 free(new_cbqp, M_DEVBUF);
942 /* prepend to the list of cbq_state_t's. */
943 new_cbqp->cbq_next = cbq_list;
951 struct cbq_interface *ifacep;
956 ifacename = ifacep->cbq_ifacename;
957 if ((cbqp = altq_lookup(ifacename, ALTQT_CBQ)) == NULL)
960 (void)cbq_set_enable(ifacep, DISABLE);
962 cbq_clear_interface(cbqp);
964 /* remove CBQ from the ifnet structure. */
965 (void)altq_detach(cbqp->ifnp.ifq_);
967 /* remove from the list of cbq_state_t's. */
968 if (cbq_list == cbqp)
969 cbq_list = cbqp->cbq_next;
973 for (cp = cbq_list; cp != NULL; cp = cp->cbq_next)
974 if (cp->cbq_next == cbqp) {
975 cp->cbq_next = cbqp->cbq_next;
981 /* deallocate cbq_state_t */
982 free(cbqp, M_DEVBUF);
988 * cbq device interface
994 cbqopen(dev, flag, fmt, p)
997 #if (__FreeBSD_version > 500000)
1007 cbqclose(dev, flag, fmt, p)
1010 #if (__FreeBSD_version > 500000)
1017 struct cbq_interface iface;
1021 ifp = cbq_list->ifnp.ifq_->altq_ifp;
1022 sprintf(iface.cbq_ifacename, "%s", ifp->if_xname);
1023 err = cbq_ifdetach(&iface);
1024 if (err != 0 && error == 0)
1032 cbqioctl(dev, cmd, addr, flag, p)
1037 #if (__FreeBSD_version > 500000)
1045 /* check cmd for superuser only */
1048 /* currently only command that an ordinary user can call */
1051 #if (__FreeBSD_version > 700000)
1052 error = priv_check(p, PRIV_ALTQ_MANAGE);
1053 #elsif (__FreeBSD_version > 400000)
1056 error = suser(p->p_ucred, &p->p_acflag);
1066 error = cbq_set_enable((struct cbq_interface *)addr, ENABLE);
1070 error = cbq_set_enable((struct cbq_interface *)addr, DISABLE);
1073 case CBQ_ADD_FILTER:
1074 error = cbq_add_filter((struct cbq_add_filter *)addr);
1077 case CBQ_DEL_FILTER:
1078 error = cbq_delete_filter((struct cbq_delete_filter *)addr);
1082 error = cbq_add_class((struct cbq_add_class *)addr);
1086 error = cbq_delete_class((struct cbq_delete_class *)addr);
1089 case CBQ_MODIFY_CLASS:
1090 error = cbq_modify_class((struct cbq_modify_class *)addr);
1093 case CBQ_CLEAR_HIERARCHY:
1094 error = cbq_clear_hierarchy((struct cbq_interface *)addr);
1098 error = cbq_ifattach((struct cbq_interface *)addr);
1102 error = cbq_ifdetach((struct cbq_interface *)addr);
1106 error = cbq_getstats((struct cbq_getstats *)addr);
1119 static void cbq_class_dump(int);
1121 static void cbq_class_dump(i)
1124 struct rm_class *cl;
1125 rm_class_stats_t *s;
1126 struct _class_queue_ *q;
1128 if (cbq_list == NULL) {
1129 printf("cbq_class_dump: no cbq_state found\n");
1132 cl = cbq_list->cbq_class_tbl[i];
1134 printf("class %d cl=%p\n", i, cl);
1139 printf("pri=%d, depth=%d, maxrate=%d, allotment=%d\n",
1140 cl->pri_, cl->depth_, cl->maxrate_, cl->allotment_);
1141 printf("w_allotment=%d, bytes_alloc=%d, avgidle=%d, maxidle=%d\n",
1142 cl->w_allotment_, cl->bytes_alloc_, cl->avgidle_,
1144 printf("minidle=%d, offtime=%d, sleeping=%d, leaf=%d\n",
1145 cl->minidle_, cl->offtime_, cl->sleeping_, cl->leaf_);
1146 printf("handle=%d, depth=%d, packets=%d, bytes=%d\n",
1147 s->handle, s->depth,
1148 (int)s->xmit_cnt.packets, (int)s->xmit_cnt.bytes);
1149 printf("over=%d\n, borrows=%d, drops=%d, overactions=%d, delays=%d\n",
1150 s->over, s->borrows, (int)s->drop_cnt.packets,
1151 s->overactions, s->delays);
1152 printf("tail=%p, head=%p, qlen=%d, qlim=%d, qthresh=%d,qtype=%d\n",
1153 q->tail_, q->head_, q->qlen_, q->qlim_,
1154 q->qthresh_, q->qtype_);
1161 static struct altqsw cbq_sw =
1162 {"cbq", cbqopen, cbqclose, cbqioctl};
1164 ALTQ_MODULE(altq_cbq, ALTQT_CBQ, &cbq_sw);
1165 MODULE_DEPEND(altq_cbq, altq_red, 1, 1, 1);
1166 MODULE_DEPEND(altq_cbq, altq_rio, 1, 1, 1);
1168 #endif /* KLD_MODULE */
1169 #endif /* ALTQ3_COMPAT */
1171 #endif /* ALTQ_CBQ */