From dc96390f9e05cb1309e6c9fa128c0a72b89f0738 Mon Sep 17 00:00:00 2001 From: Kenjiro Cho Date: Wed, 14 Jan 2004 08:42:24 +0000 Subject: eliminate the predefined special qids so that qids become simple identifiers without embedded meanings. this also allows us to make the semantics of the qid assignment in line with the tag assignment in the next step. ok, henning@ --- sys/altq/altq_cbq.c | 130 ++++++++++++++++++++++++--------------------------- sys/altq/altq_cbq.h | 11 ++--- sys/altq/altq_hfsc.c | 76 ++++++++++++++++++++++++------ sys/altq/altq_hfsc.h | 3 +- sys/altq/altq_priq.c | 16 +++---- sys/altq/altq_priq.h | 3 +- sys/altq/altq_subr.c | 3 +- sys/altq/altq_var.h | 13 +++--- 8 files changed, 141 insertions(+), 114 deletions(-) (limited to 'sys/altq') diff --git a/sys/altq/altq_cbq.c b/sys/altq/altq_cbq.c index 64f82fbc138..604cbbdb207 100644 --- a/sys/altq/altq_cbq.c +++ b/sys/altq/altq_cbq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_cbq.c,v 1.17 2003/08/20 12:33:57 henning Exp $ */ +/* $OpenBSD: altq_cbq.c,v 1.18 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_cbq.c,v 1.9 2000/12/14 08:12:45 thorpej Exp $ */ /* @@ -69,9 +69,7 @@ static void cbq_purge(cbq_state_t *); static int cbq_class_destroy(cbq_state_t *cbqp, struct rm_class *cl) { - u_int32_t chandle; - - chandle = cl->stats_.handle; + int i; /* delete the class */ rmc_delete_class(&cbqp->ifnp, cl); @@ -79,21 +77,14 @@ cbq_class_destroy(cbq_state_t *cbqp, struct rm_class *cl) /* * free the class handle */ - switch (chandle) { - case ROOT_CLASS_HANDLE: + for (i = 0; i < CBQ_MAX_CLASSES; i++) + if (cbqp->cbq_class_tbl[i] == cl) + cbqp->cbq_class_tbl[i] = NULL; + + if (cl == cbqp->ifnp.root_) cbqp->ifnp.root_ = NULL; - break; - case DEFAULT_CLASS_HANDLE: + if (cl == cbqp->ifnp.default_) cbqp->ifnp.default_ = NULL; - break; - case NULL_CLASS_HANDLE: - break; - default: - if (chandle >= CBQ_MAX_CLASSES) - break; - cbqp->cbq_class_tbl[chandle] = NULL; - } - return (0); } @@ -101,19 +92,24 @@ cbq_class_destroy(cbq_state_t *cbqp, struct rm_class *cl) static struct rm_class * clh_to_clp(cbq_state_t *cbqp, u_int32_t chandle) { - switch (chandle) { - case NULL_CLASS_HANDLE: - return (NULL); - case ROOT_CLASS_HANDLE: - return (cbqp->ifnp.root_); - case DEFAULT_CLASS_HANDLE: - return (cbqp->ifnp.default_); - } + int i; + struct rm_class *cl; - if (chandle >= CBQ_MAX_CLASSES) + if (chandle == 0) return (NULL); - - return (cbqp->cbq_class_tbl[chandle]); + /* + * first, try the slot corresponding to the lower bits of the handle. + * if it does not match, do the linear table search. + */ + i = chandle % CBQ_MAX_CLASSES; + if ((cl = cbqp->cbq_class_tbl[i]) != NULL && + cl->stats_.handle == chandle) + return (cl); + for (i = 0; i < CBQ_MAX_CLASSES; i++) + if ((cl = cbqp->cbq_class_tbl[i]) != NULL && + cl->stats_.handle == chandle) + return (cl); + return (NULL); } static int @@ -132,19 +128,13 @@ cbq_clear_interface(cbq_state_t *cbqp) else { cbq_class_destroy(cbqp, cl); cbqp->cbq_class_tbl[i] = NULL; + if (cl == cbqp->ifnp.root_) + cbqp->ifnp.root_ = NULL; + if (cl == cbqp->ifnp.default_) + cbqp->ifnp.default_ = NULL; } } } - if (cbqp->ifnp.default_ != NULL && - !is_a_parent_class(cbqp->ifnp.default_)) { - cbq_class_destroy(cbqp, cbqp->ifnp.default_); - cbqp->ifnp.default_ = NULL; - } - if (cbqp->ifnp.root_ != NULL && - !is_a_parent_class(cbqp->ifnp.root_)) { - cbq_class_destroy(cbqp, cbqp->ifnp.root_); - cbqp->ifnp.root_ = NULL; - } } while (again); return (0); @@ -167,6 +157,7 @@ cbq_request(struct ifaltq *ifq, int req, void *arg) static void get_class_stats(class_stats_t *statsp, struct rm_class *cl) { + statsp->handle = cl->stats_.handle; statsp->xmit_cnt = cl->stats_.xmit_cnt; statsp->drop_cnt = cl->stats_.drop_cnt; statsp->over = cl->stats_.over; @@ -266,9 +257,26 @@ cbq_add_queue(struct pf_altq *a) cbq_state_t *cbqp; struct rm_class *cl; struct cbq_opts *opts; + int i; if ((cbqp = a->altq_disc) == NULL) return (EINVAL); + if (a->qid == 0) + return (EINVAL); + + /* + * find a free slot in the class table. if the slot matching + * the lower bits of qid is free, use this slot. otherwise, + * use the first free slot. + */ + i = a->qid % CBQ_MAX_CLASSES; + if (cbqp->cbq_class_tbl[i] != NULL) { + for (i = 0; i < CBQ_MAX_CLASSES; i++) + if (cbqp->cbq_class_tbl[i] == NULL) + break; + if (i == CBQ_MAX_CLASSES) + return (EINVAL); + } opts = &a->pq_u.cbq_opts; /* check parameters */ @@ -305,21 +313,14 @@ cbq_add_queue(struct pf_altq *a) return (EINVAL); if (cbqp->ifnp.root_) return (EINVAL); - a->qid = ROOT_CLASS_HANDLE; break; case CBQCLF_DEFCLASS: if (cbqp->ifnp.default_) return (EINVAL); - a->qid = DEFAULT_CLASS_HANDLE; break; case 0: if (a->qid == 0) return (EINVAL); - if (a->qid >= CBQ_MAX_CLASSES && - a->qid != DEFAULT_CLASS_HANDLE) - return (EINVAL); - if (cbqp->cbq_class_tbl[a->qid] != NULL) - return (EBUSY); break; default: /* more than two flags bits set */ @@ -330,7 +331,7 @@ cbq_add_queue(struct pf_altq *a) * create a class. if this is a root class, initialize the * interface. */ - if (a->qid == ROOT_CLASS_HANDLE) { + if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_ROOTCLASS) { rmc_init(cbqp->ifnp.ifq_, &cbqp->ifnp, opts->ns_per_byte, cbqrestart, a->qlimit, RM_MAXQUEUED, opts->maxidle, opts->minidle, opts->offtime, @@ -351,17 +352,11 @@ cbq_add_queue(struct pf_altq *a) cl->stats_.depth = cl->depth_; /* save the allocated class */ - switch (a->qid) { - case NULL_CLASS_HANDLE: - case ROOT_CLASS_HANDLE: - break; - case DEFAULT_CLASS_HANDLE: + cbqp->cbq_class_tbl[i] = cl; + + if ((opts->flags & CBQCLF_CLASSMASK) == CBQCLF_DEFCLASS) cbqp->ifnp.default_ = cl; - break; - default: - cbqp->cbq_class_tbl[a->qid] = cl; - break; - } + return (0); } @@ -370,6 +365,7 @@ cbq_remove_queue(struct pf_altq *a) { struct rm_class *cl; cbq_state_t *cbqp; + int i; if ((cbqp = a->altq_disc) == NULL) return (EINVAL); @@ -387,20 +383,15 @@ cbq_remove_queue(struct pf_altq *a) /* * free the class handle */ - switch (a->qid) { - case ROOT_CLASS_HANDLE: - cbqp->ifnp.root_ = NULL; - break; - case DEFAULT_CLASS_HANDLE: - cbqp->ifnp.default_ = NULL; - break; - case NULL_CLASS_HANDLE: - break; - default: - if (a->qid >= CBQ_MAX_CLASSES) + for (i = 0; i < CBQ_MAX_CLASSES; i++) + if (cbqp->cbq_class_tbl[i] == cl) { + cbqp->cbq_class_tbl[i] = NULL; + if (cl == cbqp->ifnp.root_) + cbqp->ifnp.root_ = NULL; + if (cl == cbqp->ifnp.default_) + cbqp->ifnp.default_ = NULL; break; - cbqp->cbq_class_tbl[a->qid] = NULL; - } + } return (0); } @@ -423,7 +414,6 @@ cbq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) return (EINVAL); get_class_stats(&stats, cl); - stats.handle = a->qid; if ((error = copyout((caddr_t)&stats, ubuf, sizeof(stats))) != 0) return (error); diff --git a/sys/altq/altq_cbq.h b/sys/altq/altq_cbq.h index f0cec7251f1..efb4b1da4af 100644 --- a/sys/altq/altq_cbq.h +++ b/sys/altq/altq_cbq.h @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_cbq.h,v 1.9 2003/08/22 21:50:34 david Exp $ */ +/* $OpenBSD: altq_cbq.h,v 1.10 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_cbq.h,v 1.5 2000/12/02 13:44:40 kjc Exp $ */ /* @@ -43,12 +43,7 @@ extern "C" { #endif -/* - * Define a well known class handles - */ -#define NULL_CLASS_HANDLE 0xffffffff -#define ROOT_CLASS_HANDLE 0xfffffffe -#define DEFAULT_CLASS_HANDLE 0xfffffffd +#define NULL_CLASS_HANDLE 0 /* class flags should be same as class flags in rm_class.h */ #define CBQCLF_RED 0x0001 /* use RED */ @@ -102,7 +97,7 @@ typedef struct _cbq_class_stats_ { /* * Define macros only good for kernel drivers and modules. */ -#define CBQ_WATCHDOG (HZ / 20) +#define CBQ_WATCHDOG (hz / 20) #define CBQ_TIMEOUT 10 #define CBQ_LS_TIMEOUT (20 * hz / 1000) diff --git a/sys/altq/altq_hfsc.c b/sys/altq/altq_hfsc.c index 0a245d9b6ea..e78965cf9b2 100644 --- a/sys/altq/altq_hfsc.c +++ b/sys/altq/altq_hfsc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_hfsc.c,v 1.20 2003/12/06 06:39:51 kjc Exp $ */ +/* $OpenBSD: altq_hfsc.c,v 1.21 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_hfsc.c,v 1.17 2002/11/29 07:48:33 kjc Exp $ */ /* @@ -206,13 +206,15 @@ hfsc_add_queue(struct pf_altq *a) opts = &a->pq_u.hfsc_opts; - parent = NULL; - if (a->qid != HFSC_ROOTCLASS_HANDLE) - if ((parent = clh_to_clp(hif, a->parent_qid)) == NULL) - return (EINVAL); + if (a->parent_qid == HFSC_NULLCLASS_HANDLE && + hif->hif_rootclass == NULL) + parent = NULL; + else if ((parent = clh_to_clp(hif, a->parent_qid)) == NULL) + return (EINVAL); - if (a->qid >= HFSC_MAX_CLASSES || a->qid == 0) + if (a->qid == 0) return (EINVAL); + if (clh_to_clp(hif, a->qid) != NULL) return (EBUSY); @@ -333,7 +335,10 @@ hfsc_class_create(struct hfsc_if *hif, struct service_curve *rsc, struct hfsc_class *parent, int qlimit, int flags, int qid) { struct hfsc_class *cl, *p; - int s; + int i, s; + + if (hif->hif_classes >= HFSC_MAX_CLASSES) + return (NULL); #ifndef ALTQ_RED if (flags & HFCF_RED) { @@ -443,7 +448,27 @@ hfsc_class_create(struct hfsc_if *hif, struct service_curve *rsc, s = splimp(); hif->hif_classes++; - hif->hif_class_tbl[qid - 1] = cl; + + /* + * find a free slot in the class table. if the slot matching + * the lower bits of qid is free, use this slot. otherwise, + * use the first free slot. + */ + i = qid % HFSC_MAX_CLASSES; + if (hif->hif_class_tbl[i] == NULL) + hif->hif_class_tbl[i] = cl; + else { + for (i = 0; i < HFSC_MAX_CLASSES; i++) + if (hif->hif_class_tbl[i] == NULL) { + hif->hif_class_tbl[i] = cl; + break; + } + if (i == HFSC_MAX_CLASSES) { + splx(s); + goto err_ret; + } + } + if (flags & HFCF_DEFAULTCLASS) hif->hif_defaultclass = cl; @@ -492,7 +517,7 @@ hfsc_class_create(struct hfsc_if *hif, struct service_curve *rsc, static int hfsc_class_destroy(struct hfsc_class *cl) { - int s; + int i, s; if (cl == NULL) return (0); @@ -520,7 +545,13 @@ hfsc_class_destroy(struct hfsc_class *cl) } while ((p = p->cl_siblings) != NULL); ASSERT(p != NULL); } - cl->cl_hif->hif_class_tbl[cl->cl_handle - 1] = NULL; + + for (i = 0; i < HFSC_MAX_CLASSES; i++) + if (cl->cl_hif->hif_class_tbl[i] == cl) { + cl->cl_hif->hif_class_tbl[i] = NULL; + break; + } + cl->cl_hif->hif_classes--; splx(s); @@ -536,6 +567,12 @@ hfsc_class_destroy(struct hfsc_class *cl) red_destroy(cl->cl_red); #endif } + + if (cl == cl->cl_hif->hif_rootclass) + cl->cl_hif->hif_rootclass = NULL; + if (cl == cl->cl_hif->hif_defaultclass) + cl->cl_hif->hif_defaultclass = NULL; + if (cl->cl_usc != NULL) FREE(cl->cl_usc, M_DEVBUF); if (cl->cl_fsc != NULL) @@ -1586,12 +1623,21 @@ get_class_stats(struct hfsc_classstats *sp, struct hfsc_class *cl) static struct hfsc_class * clh_to_clp(struct hfsc_if *hif, u_int32_t chandle) { - u_int idx; + int i; + struct hfsc_class *cl; if (chandle == 0) return (NULL); - idx = chandle - 1; - if (idx >= HFSC_MAX_CLASSES) - return (NULL); - return (hif->hif_class_tbl[idx]); + /* + * first, try the slot corresponding to the lower bits of the handle. + * if it does not match, do the linear table search. + */ + i = chandle % HFSC_MAX_CLASSES; + if ((cl = hif->hif_class_tbl[i]) != NULL && cl->cl_handle == chandle) + return (cl); + for (i = 0; i < HFSC_MAX_CLASSES; i++) + if ((cl = hif->hif_class_tbl[i]) != NULL && + cl->cl_handle == chandle) + return (cl); + return (NULL); } diff --git a/sys/altq/altq_hfsc.h b/sys/altq/altq_hfsc.h index af21c6be765..85d5f20afb0 100644 --- a/sys/altq/altq_hfsc.h +++ b/sys/altq/altq_hfsc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_hfsc.h,v 1.5 2003/12/06 06:39:51 kjc Exp $ */ +/* $OpenBSD: altq_hfsc.h,v 1.6 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_hfsc.h,v 1.8 2002/11/29 04:36:23 kjc Exp $ */ /* @@ -50,7 +50,6 @@ struct service_curve { /* special class handles */ #define HFSC_NULLCLASS_HANDLE 0 -#define HFSC_ROOTCLASS_HANDLE 1 #define HFSC_MAX_CLASSES 64 /* hfsc class flags */ diff --git a/sys/altq/altq_priq.c b/sys/altq/altq_priq.c index 59d212cc586..436aa6829ea 100644 --- a/sys/altq/altq_priq.c +++ b/sys/altq/altq_priq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_priq.c,v 1.16 2003/04/03 14:31:02 henning Exp $ */ +/* $OpenBSD: altq_priq.c,v 1.17 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_priq.c,v 1.1 2000/10/18 09:15:23 kjc Exp $ */ /* * Copyright (C) 2000 @@ -137,8 +137,8 @@ priq_add_queue(struct pf_altq *a) return (EINVAL); if (a->qid == 0) return (EINVAL); - if (a->qid > PRIQ_MAXQID) - return (EINVAL); + if (pif->pif_classes[a->priority] != NULL) + return (EBUSY); if (clh_to_clp(pif, a->qid) != NULL) return (EBUSY); @@ -183,9 +183,6 @@ priq_getqstats(struct pf_altq *a, void *ubuf, int *nbytes) return (EINVAL); get_class_stats(&stats, cl); -#if 0 - stats.handle = a->qid; -#endif if ((error = copyout((caddr_t)&stats, ubuf, sizeof(stats))) != 0) return (error); @@ -561,15 +558,16 @@ get_class_stats(struct priq_classstats *sp, struct priq_class *cl) static struct priq_class * clh_to_clp(struct priq_if *pif, u_int32_t chandle) { + struct priq_class *cl; int idx; if (chandle == 0) return (NULL); for (idx = pif->pif_maxpri; idx >= 0; idx--) - if (pif->pif_classes[idx] != NULL && - pif->pif_classes[idx]->cl_handle == chandle) - return (pif->pif_classes[idx]); + if ((cl = pif->pif_classes[idx]) != NULL && + cl->cl_handle == chandle) + return (cl); return (NULL); } diff --git a/sys/altq/altq_priq.h b/sys/altq/altq_priq.h index 7e3628b6353..776ab52ca00 100644 --- a/sys/altq/altq_priq.h +++ b/sys/altq/altq_priq.h @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_priq.h,v 1.5 2003/04/03 14:31:02 henning Exp $ */ +/* $OpenBSD: altq_priq.h,v 1.6 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_priq.h,v 1.1 2000/10/18 09:15:23 kjc Exp $ */ /* * Copyright (C) 2000-2002 @@ -39,7 +39,6 @@ extern "C" { #endif #define PRIQ_MAXPRI 16 /* upper limit of the number of priorities */ -#define PRIQ_MAXQID 256 /* upper limit of queues */ /* priq class flags */ #define PRCF_RED 0x0001 /* use RED */ diff --git a/sys/altq/altq_subr.c b/sys/altq/altq_subr.c index b8f73473c8c..6599c79b680 100644 --- a/sys/altq/altq_subr.c +++ b/sys/altq/altq_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_subr.c,v 1.15 2003/10/17 19:13:01 henning Exp $ */ +/* $OpenBSD: altq_subr.c,v 1.16 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_subr.c,v 1.11 2002/01/11 08:11:49 kjc Exp $ */ /* @@ -37,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/sys/altq/altq_var.h b/sys/altq/altq_var.h index 1dcd943a806..20e88412ea8 100644 --- a/sys/altq/altq_var.h +++ b/sys/altq/altq_var.h @@ -1,4 +1,4 @@ -/* $OpenBSD: altq_var.h,v 1.12 2003/03/27 17:51:11 henning Exp $ */ +/* $OpenBSD: altq_var.h,v 1.13 2004/01/14 08:42:23 kjc Exp $ */ /* $KAME: altq_var.h,v 1.8 2001/02/09 09:44:41 kjc Exp $ */ /* @@ -97,13 +97,14 @@ extern int pfaltq_running; struct ifnet; struct mbuf; struct pf_altq; struct pf_qstats; -void *altq_lookup(char *, int); +void *altq_lookup(char *, int); u_int8_t read_dsfield(struct mbuf *, struct altq_pktattr *); -void write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t); -void altq_assert(const char *, int, const char *); -int tbr_set(struct ifaltq *, struct tb_profile *); -int tbr_get(struct ifaltq *, struct tb_profile *); +void write_dsfield(struct mbuf *, struct altq_pktattr *, u_int8_t); +void altq_assert(const char *, int, const char *); +int tbr_set(struct ifaltq *, struct tb_profile *); +int tbr_get(struct ifaltq *, struct tb_profile *); int altq_pfattach(struct pf_altq *); + int altq_pfdetach(struct pf_altq *); int altq_add(struct pf_altq *); int altq_remove(struct pf_altq *); -- cgit v1.2.3