]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Allow silent filter execution
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 16 Jan 2018 15:20:01 +0000 (16:20 +0100)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 16 Jan 2018 15:20:01 +0000 (16:20 +0100)
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.

filter/filter.c
filter/filter.h
nest/rt-table.c
sysdep/unix/krt.c

index 1e8f7d5ae78c470bc5a96bd7ecdbc250057ca99e..b0c560462c23cb7fa526b3712a5dac3a4d68c8ee 100644 (file)
@@ -590,7 +590,8 @@ f_rta_cow(void)
 static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
 
 #define runtime(x) do { \
-    log_rl(&rl_runtime_err, L_ERR "filters, line %d: %s", what->lineno, x); \
+    if (!(f_flags & FF_SILENT)) \
+      log_rl(&rl_runtime_err, L_ERR "filters, line %d: %s", what->lineno, x); \
     res.type = T_RETURN; \
     res.val.i = F_ERROR; \
     return res; \
@@ -889,7 +890,8 @@ interpret(struct f_inst *what)
     break;
   case P('p',','):
     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);
 
     switch (what->a2.i) {
@@ -1723,7 +1725,8 @@ f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struc
 
 
   if (res.type != T_RETURN) {
-    log_rl(&rl_runtime_err, L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name);
+    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);
     return F_ERROR;
   }
   DBG( "done (%u)\n", res.val.i );
index 72b37461788ae508d702563603bca6e7bea340b6..efb4b978cf091a81c0be3c1650bf813db961e5ae 100644 (file)
@@ -227,5 +227,6 @@ struct f_trie
 #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_SILENT 2                    /* Silent filter execution */
 
 #endif
index bcb48b53d2c49f0eb05d24febfc626d445f2aac1..28fe5baaec26212027b335e8cb508e9853b1a8e5 100644 (file)
@@ -273,7 +273,8 @@ export_filter_(struct announce_hook *ah, rte *rt0, rte **rt_free, ea_list **tmpa
     }
 
   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 (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);
   int v = p->import_control ? p->import_control(p, &rt, &tmpa, rte_update_pool) : 0;
   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 */
   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.
               */
              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))
                goto skip;
index 07a55c0d29f15e5a7edb2324994cdc2e9ac021bb..526c0cab64a70a96f0f7a5a30f0722260b8351ff 100644 (file)
@@ -632,7 +632,7 @@ krt_export_net(struct krt_proto *p, net *net, rte **rt_free, ea_list **tmpa)
   if (filter == FILTER_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;