diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2003-04-13 20:16:07 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2003-04-13 20:16:07 +0000 |
commit | 8eb1dafdd0f9eec7c42d6f64c12136246e1c035c (patch) | |
tree | 28e72829ef4c9bf05302b3bd5927a0003c062f67 /sbin | |
parent | c2189dae8d80d37c6a8b1288843dbb5724924787 (diff) |
pass down the struct node_queue_opts from the altqif/queuespec yacc targets
to expand_altq/expand_queue -> eval_pfaltq/eval_pfqueue and
further down to the new eval_queue_opts() instead of evaluating them directly
in the yacc grammar.
this will be needed to process the hfsc options which can contain relative
bandwidth specifications, and we can't break them down to an absolute one
earlier.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/pfctl/parse.y | 60 | ||||
-rw-r--r-- | sbin/pfctl/pfctl_altq.c | 41 | ||||
-rw-r--r-- | sbin/pfctl/pfctl_parser.h | 8 |
3 files changed, 57 insertions, 52 deletions
diff --git a/sbin/pfctl/parse.y b/sbin/pfctl/parse.y index 274b24cec61..bbb00c1992e 100644 --- a/sbin/pfctl/parse.y +++ b/sbin/pfctl/parse.y @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.y,v 1.358 2003/04/13 19:36:00 henning Exp $ */ +/* $OpenBSD: parse.y,v 1.359 2003/04/13 20:16:06 henning Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. @@ -223,9 +223,9 @@ void expand_rule(struct pf_rule *, struct node_if *, struct node_host *, struct node_host *, struct node_port *, struct node_uid *, struct node_gid *, struct node_icmp *); int expand_altq(struct pf_altq *, struct node_if *, struct node_queue *, - struct node_queue_bw bwspec); + struct node_queue_bw bwspec, struct node_queue_opt *); int expand_queue(struct pf_altq *, struct node_if *, struct node_queue *, - struct node_queue_bw); + struct node_queue_bw, struct node_queue_opt *); int check_rulestate(int); int kw_cmp(const void *, const void *); @@ -812,29 +812,14 @@ altqif : ALTQ interface queue_opts QUEUE qassign { YYERROR; } a.scheduler = $3.scheduler.qtype; - switch (a.scheduler) { - case ALTQT_CBQ: - 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; - case ALTQT_HFSC: - a.pq_u.hfsc_opts = - $3.scheduler.data.hfsc_opts; - break; - default: - break; - } a.qlimit = $3.qlimit; a.tbrsize = $3.tbrsize; if ($5 == NULL) { yyerror("no child queues specified"); YYERROR; } - if (expand_altq(&a, $2, $5, $3.queue_bwspec)) + if (expand_altq(&a, $2, $5, $3.queue_bwspec, + &$3.scheduler)) YYERROR; } ; @@ -864,23 +849,8 @@ queuespec : QUEUE STRING interface queue_opts qassign { a.priority = $4.priority; a.qlimit = $4.qlimit; a.scheduler = $4.scheduler.qtype; - switch (a.scheduler) { - case ALTQT_CBQ: - a.pq_u.cbq_opts = - $4.scheduler.data.cbq_opts; - break; - case ALTQT_PRIQ: - a.pq_u.priq_opts = - $4.scheduler.data.priq_opts; - break; - case ALTQT_HFSC: - a.pq_u.hfsc_opts = - $4.scheduler.data.hfsc_opts; - break; - default: - break; - } - if (expand_queue(&a, $3, $5, $4.queue_bwspec)) + if (expand_queue(&a, $3, $5, $4.queue_bwspec, + &$4.scheduler)) YYERROR; } ; @@ -3087,7 +3057,8 @@ expand_label(char *label, const char *ifname, sa_family_t af, int expand_altq(struct pf_altq *a, struct node_if *interfaces, - struct node_queue *nqueues, struct node_queue_bw bwspec) + struct node_queue *nqueues, struct node_queue_bw bwspec, + struct node_queue_opt *opts) { struct pf_altq pa, pb; char qname[PF_QNAME_SIZE]; @@ -3111,7 +3082,7 @@ expand_altq(struct pf_altq *a, struct node_if *interfaces, yyerror("altq on ! <interface> is not supported"); errs++; } else { - if (eval_pfaltq(pf, &pa, &bwspec)) + if (eval_pfaltq(pf, &pa, &bwspec, opts)) errs++; else if (pfctl_add_altq(pf, &pa)) @@ -3150,13 +3121,9 @@ expand_altq(struct pf_altq *a, struct node_if *interfaces, errx(1, "expand_altq: strlcpy"); pb.qlimit = pa.qlimit; pb.scheduler = pa.scheduler; - if (pa.scheduler == ALTQT_CBQ) - pb.pq_u.cbq_opts = pa.pq_u.cbq_opts; - if (pa.scheduler == ALTQT_HFSC) - pb.pq_u.hfsc_opts = pa.pq_u.hfsc_opts; bw.bw_absolute = pa.ifbandwidth; bw.bw_percent = 0; - if (eval_pfqueue(pf, &pb, &bw)) + if (eval_pfqueue(pf, &pb, &bw, opts)) errs++; else if (pfctl_add_altq(pf, &pb)) @@ -3199,7 +3166,8 @@ expand_altq(struct pf_altq *a, struct node_if *interfaces, int expand_queue(struct pf_altq *a, struct node_if *interfaces, - struct node_queue *nqueues, struct node_queue_bw bwspec) + struct node_queue *nqueues, struct node_queue_bw bwspec, + struct node_queue_opt *opts) { struct node_queue *n, *nq; struct pf_altq pa; @@ -3264,7 +3232,7 @@ expand_queue(struct pf_altq *a, struct node_if *interfaces, sizeof(pa.parent)) >= sizeof(pa.parent)) errx(1, "expand_queue: strlcpy"); - if (eval_pfqueue(pf, &pa, &bwspec)) + if (eval_pfqueue(pf, &pa, &bwspec, opts)) errs++; else if (pfctl_add_altq(pf, &pa)) diff --git a/sbin/pfctl/pfctl_altq.c b/sbin/pfctl/pfctl_altq.c index cc7a885be8c..444ef9e5351 100644 --- a/sbin/pfctl/pfctl_altq.c +++ b/sbin/pfctl/pfctl_altq.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_altq.c,v 1.59 2003/04/13 19:36:00 henning Exp $ */ +/* $OpenBSD: pfctl_altq.c,v 1.60 2003/04/13 20:16:06 henning Exp $ */ /* * Copyright (C) 2002 @@ -84,6 +84,8 @@ static double sc_x2y(struct service_curve *, double); u_int32_t getifspeed(char *); u_long getifmtu(char *); +int eval_queue_opts(struct pf_altq *, struct node_queue_opt *, + u_int32_t); static u_int32_t max_qid = 1; @@ -232,7 +234,8 @@ print_queue(const struct pf_altq *a, unsigned level, u_int16_t bwpercent, * eval_pfaltq computes the discipline parameters. */ int -eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw) +eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw, + struct node_queue_opt *opts) { u_int rate, size, errors = 0; @@ -250,6 +253,8 @@ eval_pfaltq(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw) else pa->ifbandwidth = rate; + errors += eval_queue_opts(pa, opts, rate); + /* if tbrsize is not specified, use heuristics */ if (pa->tbrsize == 0) { rate = pa->ifbandwidth; @@ -301,7 +306,8 @@ check_commit_altq(int dev, int opts) * eval_pfqueue computes the queue parameters. */ int -eval_pfqueue(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw) +eval_pfqueue(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw, + struct node_queue_opt *opts) { /* should be merged with expand_queue */ struct pf_altq *if_pa, *parent; @@ -359,6 +365,9 @@ eval_pfqueue(struct pfctl *pf, struct pf_altq *pa, struct node_queue_bw *bw) } } + if (eval_queue_opts(pa, opts, parent == NULL? 0 : parent->bandwidth)) + return (1); + switch (pa->scheduler) { case ALTQT_CBQ: error = eval_pfqueue_cbq(pf, pa); @@ -1122,3 +1131,29 @@ getifmtu(char *ifname) return (1500); } } + +int +eval_queue_opts(struct pf_altq *pa, struct node_queue_opt *opts, + u_int32_t ref_bw) +{ + int errors = 0; + + switch (pa->scheduler) { + case ALTQT_CBQ: + pa->pq_u.cbq_opts = opts->data.cbq_opts; + break; + case ALTQT_PRIQ: + pa->pq_u.priq_opts = opts->data.priq_opts; + break; + case ALTQT_HFSC: + pa->pq_u.hfsc_opts.flags = opts->data.hfsc_opts.flags; + break; + default: + warnx("eval_queue_opts: unknown scheduler type %u", + opts->qtype); + errors++; + break; + } + + return (errors); +} diff --git a/sbin/pfctl/pfctl_parser.h b/sbin/pfctl/pfctl_parser.h index 13360d6a143..495e5f01d84 100644 --- a/sbin/pfctl/pfctl_parser.h +++ b/sbin/pfctl/pfctl_parser.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pfctl_parser.h,v 1.54 2003/04/13 19:36:00 henning Exp $ */ +/* $OpenBSD: pfctl_parser.h,v 1.55 2003/04/13 20:16:06 henning Exp $ */ /* * Copyright (c) 2001 Daniel Hartmeier @@ -124,8 +124,10 @@ void print_pool(struct pf_pool *, u_int16_t, u_int16_t, sa_family_t, int); void print_rule(struct pf_rule *, int); void print_status(struct pf_status *); -int eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *); -int eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *); +int eval_pfaltq(struct pfctl *, struct pf_altq *, struct node_queue_bw *, + struct node_queue_opt *); +int eval_pfqueue(struct pfctl *, struct pf_altq *, struct node_queue_bw *, + struct node_queue_opt *); void pfctl_begin_table(void); void pfctl_append_addr(char *, int, int); |