]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Merge commit '0dbcc927' into thread-next
authorMaria Matejka <mq@ucw.cz>
Fri, 13 Oct 2023 11:36:47 +0000 (13:36 +0200)
committerMaria Matejka <mq@ucw.cz>
Fri, 13 Oct 2023 11:36:47 +0000 (13:36 +0200)
1  2 
conf/confbase.Y
filter/config.Y
filter/filter.c
filter/filter.h
nest/config.Y

diff --cc conf/confbase.Y
index cff1b794ff3427a1ae3a88af759d5b2d101ebfd6,e109ddf5a802421e35576ae507e3b8dcf95fb438..9725ef36c288ccdbff880af2f38d6750861567eb
@@@ -157,16 -154,16 +157,15 @@@ conf: definition 
  
  definition:
     DEFINE symbol '=' term ';' {
-      struct f_val val;
-      if (f_eval(f_linearize($4, 1), &val) > F_RETURN) cf_error("Runtime error");
-      cf_define_symbol($2, SYM_CONSTANT | val.type, val, lp_val_copy(cfg_mem, &val));
 -     struct f_val *val = cfg_allocz(sizeof(struct f_val));
 -     *val = cf_eval($4, T_VOID);
++     struct f_val *val = cf_eval($4, T_VOID);
+      cf_define_symbol($2, SYM_CONSTANT | val->type, val, val);
     }
   ;
  
  expr:
     NUM
-  | '(' term ')' { $$ = f_eval_int(f_linearize($2, 1)); }
+  | '(' term ')' { $$ = cf_eval_int($2); }
 - | CF_SYM_KNOWN {
 + | symbol_known {
       if ($1->class != (SYM_CONSTANT | T_INT)) cf_error("Number constant expected");
       $$ = SYM_VAL($1).i; }
   ;
diff --cc filter/config.Y
index 7bf13d9ce47a18ebc922c0162316b0e503b30346,2a298843fd192a302f21267585c3b37d6b13a910..238a1c468e2bf0cc1c94732495caefaf9774f6f1
@@@ -598,10 -573,10 +598,10 @@@ set_atom
   | VPN_RD { $$.type = T_RD; $$.val.ec = $1; }
   | ENUM   { $$.type = pair_a($1); $$.val.i = pair_b($1); }
   | '(' term ')' {
-      if (f_eval(f_linearize($2, 1), &($$)) > F_RETURN) cf_error("Runtime error");
 -     $$ = cf_eval($2, T_VOID);
++     $$ = cf_eval_tmp($2, T_VOID);
       if (!f_valid_set_type($$.type)) cf_error("Set-incompatible type");
     }
 - | CF_SYM_KNOWN {
 + | symbol_known {
       cf_assert_symbol($1, SYM_CONSTANT);
       if (!f_valid_set_type(SYM_TYPE($1))) cf_error("%s: set-incompatible type", $1->name);
       $$ = *$1->val;
  
  switch_atom:
     NUM   { $$.type = T_INT; $$.val.i = $1; }
-  | '(' term ')' { $$.type = T_INT; $$.val.i = f_eval_int(f_linearize($2, 1)); }
 - | '(' term ')' { $$ = cf_eval($2, T_INT); }
++ | '(' term ')' { $$ = cf_eval_tmp($2, T_INT); }
   | fipa  { $$ = $1; }
   | ENUM  { $$.type = pair_a($1); $$.val.i = pair_b($1); }
   ;
diff --cc filter/filter.c
index 931bc85eb7dbe5298a12600283faf65f35425cc2,d080cadcf747244e21a74e1ed986c191983b1310..7eb109a17f2fd79be5985768e07dc1c2e986db25
@@@ -277,29 -373,24 +277,23 @@@ f_eval(const struct f_line *expr, struc
  }
  
  /*
-  * f_eval_int - get an integer value of a term
 - * cf_eval - evaluate a value of a term and check its type
-- * Called internally from the config parser, uses its internal memory pool
-- * for allocations. Do not call in other cases.
++ * cf_eval_tmp - evaluate a value of a term and check its type
   */
- uint
- f_eval_int(const struct f_line *expr)
+ struct f_val
 -cf_eval(const struct f_inst *inst, int type)
++cf_eval_tmp(const struct f_inst *inst, int type)
  {
-   /* Called independently in parse-time to eval expressions */
-   filter_state = (struct filter_state) {};
-   f_stack_init(filter_state);
    struct f_val val;
  
-   if (interpret(&filter_state, expr, &val) > F_RETURN)
 -  if (f_eval(f_linearize(inst, 1), cfg_mem, &val) > F_RETURN)
++  if (f_eval(f_linearize(inst, 1), &val) > F_RETURN)
      cf_error("Runtime error while evaluating expression; see log for details");
  
-   if (val.type != T_INT)
-     cf_error("Integer expression expected");
+   if (type != T_VOID && val.type != type)
+     cf_error("Expression of type %s expected", f_type_name(type));
  
-   return val.val.i;
+   return val;
  }
  
++
  /*
   * f_eval_buf - get a value of a term and print it to the supplied buffer
   */
diff --cc filter/filter.h
index 3f2e62ebf74f2710f8e03d4de770e71a6bdf1a45,91de696cfd7be9a6a42e853f45e80be510a605d4..1ece636a95d4328222403a669962135aa716d8a5
  #include "lib/resource.h"
  #include "lib/ip.h"
  #include "lib/macro.h"
 -#include "nest/route.h"
 -#include "nest/attrs.h"
 +#include "nest/rt.h"
 +#include "lib/attrs.h"
+ #include "filter/data.h"
++#include "conf/conf.h"
  
  /* Possible return values of filter execution */
  enum filter_return {
@@@ -51,11 -51,13 +52,19 @@@ struct filter 
  
  struct rte;
  
 -enum filter_return f_run(const struct filter *filter, struct rte **rte, struct linpool *tmp_pool, int flags);
 -enum filter_return f_eval_rte(const struct f_line *expr, struct rte **rte, struct linpool *tmp_pool);
 -enum filter_return f_eval_buf(const struct f_line *expr, struct linpool *tmp_pool, buffer *buf);
 +enum filter_return f_run(const struct filter *filter, struct rte *rte, int flags);
 +enum filter_return f_eval_rte(const struct f_line *expr, struct rte *rte);
- uint f_eval_int(const struct f_line *expr);
 +enum filter_return f_eval_buf(const struct f_line *expr, buffer *buf);
  
 -struct f_val cf_eval(const struct f_inst *inst, int type);
 -static inline uint cf_eval_int(const struct f_inst *inst) { return cf_eval(inst, T_INT).val.i; };
++struct f_val cf_eval_tmp(const struct f_inst *inst, int type);
++static inline struct f_val *cf_eval(const struct f_inst *inst, int type)
++{
++  struct f_val val = cf_eval_tmp(inst, type);
++  return lp_val_copy(cfg_mem, &val);
++}
++
++static inline uint cf_eval_int(const struct f_inst *inst) { return cf_eval_tmp(inst, T_INT).val.i; };
  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);
diff --cc nest/config.Y
Simple merge