]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter global values are not used directly from config
authorMaria Matejka <mq@ucw.cz>
Thu, 13 Jun 2024 13:49:56 +0000 (15:49 +0200)
committerMaria Matejka <mq@ucw.cz>
Fri, 14 Jun 2024 21:16:07 +0000 (23:16 +0200)
conf/conf.c
filter/config.Y
filter/filter.c
filter/filter.h

index 02a750a4b5fc056681a8bb7bdf52c6e710dd7228..981db7091bf6ad3410b619095824862ff2fd481b 100644 (file)
@@ -139,6 +139,7 @@ config_parse(struct config *c)
     goto cleanup;
 
   cf_lex_init(NULL, c);
+  filter_preconfig(c);
   sysdep_preconfig(c);
   protos_preconfig(c);
   mpls_preconfig(c);
index 353e27ae4c2bc3adba5b5d75fcbab68517ff65a4..4d8b30c75e5390cc2e88ae61356365f6d28b3c22 100644 (file)
@@ -401,6 +401,9 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
 CF_GRAMMAR
 
 conf: FILTER STACKS expr expr ';' {
+  if (($3 < 16) || ($4 < 16))
+    /* Check for self-crippling values */
+    cf_error("Filter stack values lesser than 16 not supported");
   new_config->filter_vstk = $3;
   new_config->filter_estk = $4;
  }
index fd2c16b13b93eee1f0ab84eae4e297c59e267a2e..c9a49bacfd231d745a942681ffcac8d2030affcc 100644 (file)
@@ -50,6 +50,15 @@ enum f_exception {
   FE_RETURN = 0x1,
 };
 
+/* Global filter runtime */
+static struct {
+  _Atomic u16 filter_vstk;
+  _Atomic u16 filter_estk;
+} global_filter_runtime = {
+  .filter_vstk = 128,
+  .filter_estk = 128,
+};
+
 struct filter_exec_stack {
   const struct f_line *line;           /* The line that is being executed */
   uint pos;                            /* Instruction index in the line */
@@ -90,9 +99,9 @@ _Thread_local static struct filter_state filter_state;
 
 void (*bt_assert_hook)(int result, const struct f_line_item *assert);
 
-#define _f_stack_init(fs, px, def) ((fs).stack.px##stk = alloca(sizeof(*(fs).stack.px##stk) * ((fs).stack.px##len = (config && config->filter_##px##stk) ? config->filter_##px##stk : (def))))
+#define _f_stack_init(fs, px) ((fs).stack.px##stk = alloca(sizeof(*(fs).stack.px##stk) * ((fs).stack.px##len = atomic_load_explicit(&global_filter_runtime.filter_##px##stk, memory_order_relaxed))))
 
-#define f_stack_init(fs) ( _f_stack_init(fs, v, 128), _f_stack_init(fs, e, 128) )
+#define f_stack_init(fs) ( _f_stack_init(fs, v), _f_stack_init(fs, e) )
 
 static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
 
@@ -340,12 +349,24 @@ filter_same(const struct filter *new, const struct filter *old)
   return new->sym->flags & SYM_FLAG_SAME;
 }
 
+/* Initialize filter knobs */
+void
+filter_preconfig(struct config *new)
+{
+  new->filter_vstk = 128;
+  new->filter_estk = 128;
+}
+
 /**
  * filter_commit - do filter comparisons on all the named functions and filters
  */
 void
 filter_commit(struct config *new, struct config *old)
 {
+  /* Update filter stack size variables */
+  atomic_store_explicit(&global_filter_runtime.filter_vstk, new->filter_vstk, memory_order_relaxed);
+  atomic_store_explicit(&global_filter_runtime.filter_estk, new->filter_estk, memory_order_relaxed);
+
   if (!old)
     return;
 
index 8d495e2d8ed651ac5cddc3a830a98639dc036cb1..d76d1d4956b62317dbbaaed875717d6efe71d89f 100644 (file)
@@ -70,6 +70,7 @@ const char *filter_name(const struct filter *filter);
 int filter_same(const struct filter *new, const struct filter *old);
 int f_same(const struct f_line *f1, const struct f_line *f2);
 
+void filter_preconfig(struct config *new);
 void filter_commit(struct config *new, struct config *old);
 
 void filters_dump_all(void);