Filter: Allow silent filter execution

A filter should log messages only if executed explicitly (e.g., during
route export or route import). When a filter is executed for technical
reasons (e.g., to establish whether a route was exported before), it
should run silently.
This commit is contained in:
Ondrej Zajicek (work) 2018-01-16 16:20:01 +01:00
parent 0ff86d054e
commit b940579115
4 changed files with 14 additions and 7 deletions

View file

@ -590,6 +590,7 @@ f_rta_cow(void)
static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS; static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
#define runtime(x) do { \ #define runtime(x) do { \
if (!(f_flags & FF_SILENT)) \
log_rl(&rl_runtime_err, L_ERR "filters, line %d: %s", what->lineno, x); \ log_rl(&rl_runtime_err, L_ERR "filters, line %d: %s", what->lineno, x); \
res.type = T_RETURN; \ res.type = T_RETURN; \
res.val.i = F_ERROR; \ res.val.i = F_ERROR; \
@ -889,7 +890,8 @@ interpret(struct f_inst *what)
break; break;
case P('p',','): case P('p',','):
ONEARG; ONEARG;
if (what->a2.i == F_NOP || (what->a2.i != F_NONL && what->a1.p)) if ((what->a2.i == F_NOP || (what->a2.i != F_NONL && what->a1.p)) &&
!(f_flags & FF_SILENT))
log_commit(*L_INFO, &f_buf); log_commit(*L_INFO, &f_buf);
switch (what->a2.i) { switch (what->a2.i) {
@ -1723,6 +1725,7 @@ f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struc
if (res.type != T_RETURN) { if (res.type != T_RETURN) {
if (!(f_flags & FF_SILENT))
log_rl(&rl_runtime_err, L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name); log_rl(&rl_runtime_err, L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name);
return F_ERROR; return F_ERROR;
} }

View file

@ -227,5 +227,6 @@ struct f_trie
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); #define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
#define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */ #define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */
#define FF_SILENT 2 /* Silent filter execution */
#endif #endif

View file

@ -273,7 +273,8 @@ export_filter_(struct announce_hook *ah, rte *rt0, rte **rt_free, ea_list **tmpa
} }
v = filter && ((filter == FILTER_REJECT) || v = filter && ((filter == FILTER_REJECT) ||
(f_run(filter, &rt, tmpa, pool, FF_FORCE_TMPATTR) > F_ACCEPT)); (f_run(filter, &rt, tmpa, pool,
FF_FORCE_TMPATTR | (silent ? FF_SILENT : 0)) > F_ACCEPT));
if (v) if (v)
{ {
if (silent) if (silent)
@ -1298,7 +1299,8 @@ rt_examine(rtable *t, ip_addr prefix, int pxlen, struct proto *p, struct filter
ea_list *tmpa = rte_make_tmp_attrs(rt, rte_update_pool); ea_list *tmpa = rte_make_tmp_attrs(rt, rte_update_pool);
int v = p->import_control ? p->import_control(p, &rt, &tmpa, rte_update_pool) : 0; int v = p->import_control ? p->import_control(p, &rt, &tmpa, rte_update_pool) : 0;
if (v == RIC_PROCESS) if (v == RIC_PROCESS)
v = (f_run(filter, &rt, &tmpa, rte_update_pool, FF_FORCE_TMPATTR) <= F_ACCEPT); v = (f_run(filter, &rt, &tmpa, rte_update_pool,
FF_FORCE_TMPATTR | FF_SILENT) <= F_ACCEPT);
/* Discard temporary rte */ /* Discard temporary rte */
if (rt != n->routes) if (rt != n->routes)
@ -2493,7 +2495,8 @@ rt_show_net(struct cli *c, net *n, struct rt_show_data *d)
* command may change the export filter and do not update routes. * command may change the export filter and do not update routes.
*/ */
int do_export = (ic > 0) || int do_export = (ic > 0) ||
(f_run(a->out_filter, &e, &tmpa, rte_update_pool, FF_FORCE_TMPATTR) <= F_ACCEPT); (f_run(a->out_filter, &e, &tmpa, rte_update_pool,
FF_FORCE_TMPATTR | FF_SILENT) <= F_ACCEPT);
if (do_export != (d->export_mode == RSEM_EXPORT)) if (do_export != (d->export_mode == RSEM_EXPORT))
goto skip; goto skip;

View file

@ -632,7 +632,7 @@ krt_export_net(struct krt_proto *p, net *net, rte **rt_free, ea_list **tmpa)
if (filter == FILTER_ACCEPT) if (filter == FILTER_ACCEPT)
goto accept; goto accept;
if (f_run(filter, &rt, tmpa, krt_filter_lp, FF_FORCE_TMPATTR) > F_ACCEPT) if (f_run(filter, &rt, tmpa, krt_filter_lp, FF_FORCE_TMPATTR | FF_SILENT) > F_ACCEPT)
goto reject; goto reject;