mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2025-01-18 06:51:54 +00:00
Merge commit 'ba91f4c831f057b81104d1453f99b012c01f9c9e' into thread-next
This commit is contained in:
commit
e8dcc62ecd
@ -112,7 +112,7 @@ static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
|
|||||||
* TWOARGS macro to get both of them evaluated.
|
* TWOARGS macro to get both of them evaluated.
|
||||||
*/
|
*/
|
||||||
static enum filter_return
|
static enum filter_return
|
||||||
interpret(struct filter_state *fs, const struct f_line *line, uint argc, const struct f_val *argv, struct f_val *val)
|
interpret(struct filter_state *fs, const struct f_line *line, uint argc, const struct f_val *argv, uint resc, struct f_val *resv)
|
||||||
{
|
{
|
||||||
/* Check of appropriate number of arguments */
|
/* Check of appropriate number of arguments */
|
||||||
ASSERT(line->args == argc);
|
ASSERT(line->args == argc);
|
||||||
@ -178,21 +178,14 @@ interpret(struct filter_state *fs, const struct f_line *line, uint argc, const s
|
|||||||
fstk->ecnt--;
|
fstk->ecnt--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fstk->vcnt == 0) {
|
if (fstk->vcnt != resc)
|
||||||
if (val) {
|
{
|
||||||
log_rl(&rl_runtime_err, L_ERR "filters: No value left on stack");
|
log_rl(&rl_runtime_err, L_ERR "Filter expected to leave %d values on stack but %d left instead", resc, fstk->vcnt);
|
||||||
return F_ERROR;
|
return F_ERROR;
|
||||||
}
|
|
||||||
return F_NOP;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (val && (fstk->vcnt == 1)) {
|
memcpy(resv, fstk->vstk, sizeof(struct f_val) * resc);
|
||||||
*val = fstk->vstk[0];
|
return F_NOP;
|
||||||
return F_NOP;
|
|
||||||
}
|
|
||||||
|
|
||||||
log_rl(&rl_runtime_err, L_ERR "Too many items left on stack: %u", fstk->vcnt);
|
|
||||||
return F_ERROR;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -232,7 +225,7 @@ f_run_args(const struct filter *filter, struct rte *rte, uint argc, const struct
|
|||||||
f_stack_init(filter_state);
|
f_stack_init(filter_state);
|
||||||
|
|
||||||
/* Run the interpreter itself */
|
/* Run the interpreter itself */
|
||||||
enum filter_return fret = interpret(&filter_state, filter->root, argc, argv, NULL);
|
enum filter_return fret = interpret(&filter_state, filter->root, argc, argv, 0, NULL);
|
||||||
|
|
||||||
/* Process the filter output, log it and return */
|
/* Process the filter output, log it and return */
|
||||||
if (fret < F_ACCEPT) {
|
if (fret < F_ACCEPT) {
|
||||||
@ -258,7 +251,7 @@ f_run_args(const struct filter *filter, struct rte *rte, uint argc, const struct
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
enum filter_return
|
enum filter_return
|
||||||
f_eval_rte(const struct f_line *expr, struct rte *rte, uint argc, const struct f_val *argv, struct f_val *pres)
|
f_eval_rte(const struct f_line *expr, struct rte *rte, uint argc, const struct f_val *argv, uint resc, struct f_val *resv)
|
||||||
{
|
{
|
||||||
filter_state = (struct filter_state) {
|
filter_state = (struct filter_state) {
|
||||||
.rte = rte,
|
.rte = rte,
|
||||||
@ -266,14 +259,14 @@ f_eval_rte(const struct f_line *expr, struct rte *rte, uint argc, const struct f
|
|||||||
|
|
||||||
f_stack_init(filter_state);
|
f_stack_init(filter_state);
|
||||||
|
|
||||||
return interpret(&filter_state, expr, argc, argv, pres);
|
return interpret(&filter_state, expr, argc, argv, resc, resv);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* f_eval - get a value of a term
|
* f_eval - get a value of a term
|
||||||
* @expr: filter line containing the term
|
* @expr: filter line containing the term
|
||||||
* @tmp_pool: long data may get allocated from this pool
|
* @tmp_pool: long data may get allocated from this pool
|
||||||
* @pres: here the output will be stored
|
* @pres: here the output will be stored if requested
|
||||||
*/
|
*/
|
||||||
enum filter_return
|
enum filter_return
|
||||||
f_eval(const struct f_line *expr, struct f_val *pres)
|
f_eval(const struct f_line *expr, struct f_val *pres)
|
||||||
@ -282,7 +275,7 @@ f_eval(const struct f_line *expr, struct f_val *pres)
|
|||||||
|
|
||||||
f_stack_init(filter_state);
|
f_stack_init(filter_state);
|
||||||
|
|
||||||
enum filter_return fret = interpret(&filter_state, expr, 0, NULL, pres);
|
enum filter_return fret = interpret(&filter_state, expr, 0, NULL, !!pres, pres);
|
||||||
return fret;
|
return fret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,7 +54,7 @@ struct rte;
|
|||||||
|
|
||||||
enum filter_return f_run(const struct filter *filter, struct rte *rte, int flags);
|
enum filter_return f_run(const struct filter *filter, struct rte *rte, int flags);
|
||||||
enum filter_return f_run_args(const struct filter *filter, struct rte *rte, uint argc, const struct f_val *argv, int flags);
|
enum filter_return f_run_args(const struct filter *filter, struct rte *rte, uint argc, const struct f_val *argv, int flags);
|
||||||
enum filter_return f_eval_rte(const struct f_line *expr, struct rte *rte, uint argc, const struct f_val *argv, struct f_val *pres);
|
enum filter_return f_eval_rte(const struct f_line *expr, struct rte *rte, uint argc, const struct f_val *argv, uint resc, struct f_val *resv);
|
||||||
enum filter_return f_eval_buf(const struct f_line *expr, buffer *buf);
|
enum filter_return f_eval_buf(const struct f_line *expr, buffer *buf);
|
||||||
|
|
||||||
struct f_val cf_eval_tmp(const struct f_inst *inst, int type);
|
struct f_val cf_eval_tmp(const struct f_inst *inst, int type);
|
||||||
|
@ -122,7 +122,7 @@ static_announce_rte(struct static_proto *p, struct static_route *r)
|
|||||||
|
|
||||||
/* Evaluate the filter */
|
/* Evaluate the filter */
|
||||||
if (r->cmds)
|
if (r->cmds)
|
||||||
f_eval_rte(r->cmds, e, 0, NULL, NULL);
|
f_eval_rte(r->cmds, e, 0, NULL, 0, NULL);
|
||||||
|
|
||||||
rte_update(p->p.main_channel, r->net, e, src);
|
rte_update(p->p.main_channel, r->net, e, src);
|
||||||
static_free_source(src, r->index);
|
static_free_source(src, r->index);
|
||||||
|
Loading…
Reference in New Issue
Block a user