diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2002-12-17 20:06:06 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2002-12-17 20:06:06 +0000 |
commit | 75aa64eeb6c2773b729a6c953f99f4fc76a9c7b0 (patch) | |
tree | 8a7171121aa8fb7dc4a1d4a94490b291df9c7194 /sbin | |
parent | 4e4f1f07e39d95aa348511b7ef0121e2f263754c (diff) |
add support for the PRIQ scheduler
partitially from kjc@
ok kjc@ dhartmei@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/pfctl/parse.y | 71 | ||||
-rw-r--r-- | sbin/pfctl/pfctl.c | 25 | ||||
-rw-r--r-- | sbin/pfctl/pfctl_altq.c | 43 |
3 files changed, 96 insertions, 43 deletions
diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index aeac5d4592c..efe7c933627 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.260 2002/12/17 12:36:59 mcbride Exp $ */ +/* $OpenBSD: parse.y,v 1.261 2002/12/17 20:06:05 henning Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. @@ -165,14 +165,16 @@ struct node_queue { char queue[PF_QNAME_SIZE]; char parent[PF_QNAME_SIZE]; char ifname[IFNAMSIZ]; + int scheduler; struct node_queue *next; struct node_queue *tail; } *queues = NULL; struct node_queue_opt { int qtype; - union { /* options for other schedulers will follow */ - struct cbq_opts cbq_opts; + union { + struct cbq_opts cbq_opts; + struct priq_opts priq_opts; } data; }; @@ -380,7 +382,7 @@ typedef struct { %token REQUIREORDER YES %token ANTISPOOF FOR %token BITMASK RANDOM SOURCEHASH ROUNDROBIN STATICPORT -%token ALTQ CBQ BANDWIDTH TBRSIZE +%token ALTQ CBQ PRIQ BANDWIDTH TBRSIZE %token QUEUE PRIORITY QLIMIT %token DEFAULT CONTROL BORROW RED ECN RIO %token <v.string> STRING @@ -417,6 +419,7 @@ typedef struct { %type <v.queue> qassign qassign_list qassign_item %type <v.queue_options> scheduler %type <v.number> cbqflags_list cbqflags_item +%type <v.number> priqflags_list priqflags_item %type <v.queue_bwspec> bandwidth %type <v.filter_opts> filter_opts filter_opt filter_opts_l %type <v.queue_opts> queue_opts queue_opt queue_opts_l @@ -747,6 +750,10 @@ altqif : ALTQ interface queue_opts QUEUE qassign { a.pq_u.cbq_opts = $3.scheduler.data.cbq_opts; break; + case ALTQT_PRIQ: + a.pq_u.priq_opts = + $3.scheduler.data.priq_opts; + break; default: break; } @@ -791,6 +798,10 @@ queuespec : QUEUE STRING queue_opts qassign { a.pq_u.cbq_opts = $3.scheduler.data.cbq_opts; break; + case ALTQT_PRIQ: + a.pq_u.priq_opts = + $3.scheduler.data.priq_opts; + break; default: break; } @@ -916,6 +927,14 @@ scheduler : CBQ { $$.qtype = ALTQT_CBQ; $$.data.cbq_opts.flags = $3; } + | PRIQ { + $$.qtype = ALTQT_PRIQ; + $$.data.priq_opts.flags = 0; + } + | PRIQ '(' priqflags_list ')' { + $$.qtype = ALTQT_PRIQ; + $$.data.priq_opts.flags = $3; + } ; cbqflags_list : cbqflags_item { $$ |= $1; } @@ -930,6 +949,16 @@ cbqflags_item : DEFAULT { $$ = CBQCLF_DEFCLASS; } | RIO { $$ = CBQCLF_RIO; } ; +priqflags_list : priqflags_item { $$ |= $1; } + | priqflags_list comma priqflags_item { $$ |= $3; } + ; + +priqflags_item : DEFAULT { $$ = PRCF_DEFAULTCLASS; } + | RED { $$ = PRCF_RED; } + | ECN { $$ = PRCF_RED|PRCF_ECN; } + | RIO { $$ = PRCF_RIO; } + ; + qassign : /* empty */ { $$ = NULL; } | qassign_item { $$ = $1; } | '{' qassign_list '}' { $$ = $2; } @@ -2873,9 +2902,12 @@ expand_altq(struct pf_altq *a, struct node_if *interfaces, n = calloc(1, sizeof(struct node_queue)); if (n == NULL) err(1, "expand_altq: calloc"); - strlcpy(n->parent, qname, PF_QNAME_SIZE); + if (pa.scheduler == ALTQT_CBQ) + strlcpy(n->parent, qname, + PF_QNAME_SIZE); strlcpy(n->queue, queue->queue, PF_QNAME_SIZE); strlcpy(n->ifname, interface->ifname, IFNAMSIZ); + n->scheduler = pa.scheduler; n->next = NULL; n->tail = n; if (queues == NULL) @@ -2905,6 +2937,33 @@ expand_queue(struct pf_altq *a, struct node_queue *nqueues, if (!strncmp(a->qname, tqueue->queue, PF_QNAME_SIZE)) { /* found ourselve in queues */ found++; + + if (a->scheduler != ALTQT_NONE && + a->scheduler != tqueue->scheduler) { + yyerror("exactly one scheduler type per " + "interface allowed"); + return (1); + } + a->scheduler = tqueue->scheduler; + + /* scheduler dependent error checking */ + switch (a->scheduler) { + case ALTQT_PRIQ: + if (nqueues != NULL) { + yyerror("priq queues cannot have " + "child queues"); + return (1); + } + if (bwspec.bw_absolute > 0 || + bwspec.bw_percent < 100) { + yyerror("priq doesn't take bandwidth"); + return (1); + } + break; + default: + break; + } + LOOP_THROUGH(struct node_queue, queue, nqueues, n = calloc(1, sizeof(struct node_queue)); if (n == NULL) @@ -2912,6 +2971,7 @@ expand_queue(struct pf_altq *a, struct node_queue *nqueues, strlcpy(n->parent, a->qname, PF_QNAME_SIZE); strlcpy(n->queue, queue->queue, PF_QNAME_SIZE); strlcpy(n->ifname, tqueue->ifname, IFNAMSIZ); + n->scheduler = a->scheduler; n->next = NULL; n->tail = n; if (queues == NULL) @@ -3341,6 +3401,7 @@ lookup(char *s) { "pass", PASS}, { "port", PORT}, { "priority", PRIORITY}, + { "priq", PRIQ}, { "proto", PROTO}, { "qlimit", QLIMIT}, { "queue", QUEUE}, diff --git a/sbin/pfctl/pfctl.c b/sbin/pfctl/pfctl.c index d5dc35b74c1..76191150464 100644 --- a/sbin/pfctl/pfctl.c +++ b/sbin/pfctl/pfctl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl.c,v 1.104 2002/12/17 12:36:59 mcbride Exp $ */ +/* $OpenBSD: pfctl.c,v 1.105 2002/12/17 20:06:05 henning Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -735,19 +735,16 @@ pfctl_add_altq(struct pfctl *pf, struct pf_altq *a) (loadopt & (PFCTL_FLAG_ALTQ | PFCTL_FLAG_ALL)) != 0) { memcpy(&pf->paltq->altq, a, sizeof(struct pf_altq)); if ((pf->opts & PF_OPT_NOACTION) == 0) { - /* only cbq needs a root queue */ - if (a->scheduler == ALTQT_CBQ || - a->qname[0] == 0 || a->parent[0] != 0) - if (ioctl(pf->dev, DIOCADDALTQ, pf->paltq)) { - if (errno == ENXIO) - fprintf(stderr, - "qtype not configured\n"); - else if (errno == ENODEV) - fprintf(stderr, - "driver does not support " - "altq\n"); - err(1, "DIOCADDALTQ"); - } + if (ioctl(pf->dev, DIOCADDALTQ, pf->paltq)) { + if (errno == ENXIO) + fprintf(stderr, + "qtype not configured\n"); + else if (errno == ENODEV) + fprintf(stderr, + "driver does not support " + "altq\n"); + err(1, "DIOCADDALTQ"); + } } pfaltq_store(&pf->paltq->altq); } diff --git a/sbin/pfctl/pfctl_altq.c b/sbin/pfctl/pfctl_altq.c index e35b34a10ec..78567709127 100644 --- a/sbin/pfctl/pfctl_altq.c +++ b/sbin/pfctl/pfctl_altq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_altq.c,v 1.24 2002/12/17 11:29:04 henning Exp $ */ +/* $OpenBSD: pfctl_altq.c,v 1.25 2002/12/17 20:06:05 henning Exp $ */ /* * Copyright (C) 2002 @@ -203,7 +203,8 @@ print_queue(const struct pf_altq *a, unsigned level) for (i = 0; i < level; ++i) printf(" "); printf("%s ", a->qname); - printf("bandwidth %s ", rate2str((double)a->bandwidth)); + if (a->scheduler == ALTQT_CBQ || a->scheduler == ALTQT_HFSC) + printf("bandwidth %s ", rate2str((double)a->bandwidth)); if (a->priority != DEFAULT_PRIORITY) printf("priority %u ", a->priority); if (a->qlimit != DEFAULT_QLIMIT) @@ -320,18 +321,22 @@ eval_pfqueue(struct pfctl *pf, struct pf_altq *pa, u_int32_t bw_absolute, if (pa->qlimit == 0) pa->qlimit = DEFAULT_QLIMIT; - if (bw_absolute > 0) - pa->bandwidth = bw_absolute; - else if (bw_percent > 0 && parent != NULL) - pa->bandwidth = parent->bandwidth / 100 * bw_percent; - else - errx(1, "bandwidth for %s invalid (%d / %d)", pa->qname, - bw_absolute, bw_percent); + if (pa->scheduler == ALTQT_CBQ || pa->scheduler == ALTQT_HFSC) { + if (bw_absolute > 0) + pa->bandwidth = bw_absolute; + else if (bw_percent > 0 && parent != NULL) + pa->bandwidth = parent->bandwidth / 100 * bw_percent; + else + errx(1, "bandwidth for %s invalid (%d / %d)", pa->qname, + bw_absolute, bw_percent); - if (pa->bandwidth > pa->ifbandwidth) - errx(1, "bandwidth for %s higher than interface", pa->qname); - if (parent != NULL && pa->bandwidth > parent->bandwidth) - errx(1, "bandwidth for %s higher than parent", pa->qname); + if (pa->bandwidth > pa->ifbandwidth) + errx(1, "bandwidth for %s higher than interface", + pa->qname); + if (parent != NULL && pa->bandwidth > parent->bandwidth) + errx(1, "bandwidth for %s higher than parent", + pa->qname); + } switch (pa->scheduler) { case ALTQT_CBQ: @@ -552,10 +557,6 @@ eval_pfqueue_priq(struct pfctl *pf, struct pf_altq *pa) { struct pf_altq *altq; - if (pa->parent[0] == 0) - /* this is for dummy root */ - return (0); - if (pa->priority >= PRIQ_MAXPRI) { warnx("priority out of range: max %d", PRIQ_MAXPRI - 1); return (-1); @@ -563,17 +564,13 @@ eval_pfqueue_priq(struct pfctl *pf, struct pf_altq *pa) /* the priority should be unique for the interface */ TAILQ_FOREACH(altq, &altqs, entries) { if (strncmp(altq->ifname, pa->ifname, IFNAMSIZ) == 0 && - altq->qname[0] != 0 && altq->parent[0] != 0 && - altq->priority == pa->priority) { + altq->qname[0] != 0 && altq->priority == pa->priority) { warnx("%s and %s have the same priority", altq->qname, pa->qname); return (-1); } } - if (pa->bandwidth != pa->ifbandwidth) - warnx("priq does not have a bandwidth parameter -- ignored"); - return (0); } @@ -593,8 +590,6 @@ check_commit_priq(int dev, int opts, struct pf_altq *pa) continue; if (altq->qname[0] == 0) /* this is for interface */ continue; - if (altq->parent[0] == 0) /* dummy root */ - continue; if (altq->pq_u.priq_opts.flags & PRCF_DEFAULTCLASS) default_class++; } |