From a36fc2b2cda346902771cb876caa4cb9a5405e18 Mon Sep 17 00:00:00 2001 From: Maria Matejka Date: Sun, 2 Jul 2023 16:09:33 +0200 Subject: [PATCH] TMP --- conf/conf.h | 1 + filter/config.Y | 41 +++++++++++++++++++++++++++++------------ filter/f-inst.c | 9 +++++---- filter/f-inst.h | 11 +++++++++++ nest/rt.h | 2 ++ 5 files changed, 48 insertions(+), 16 deletions(-) diff --git a/conf/conf.h b/conf/conf.h index b6d1598f..43d6ee81 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -163,6 +163,7 @@ struct bytestring { #define SYM_FILTER 4 #define SYM_TABLE 5 #define SYM_ATTRIBUTE 6 +#define SYM_VOLATILE 7 #define SYM_VARIABLE 0x100 /* 0x100-0x1ff are variable types */ #define SYM_VARIABLE_RANGE SYM_VARIABLE ... (SYM_VARIABLE | 0xff) diff --git a/filter/config.Y b/filter/config.Y index e590da57..6dc218b9 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -12,6 +12,7 @@ CF_HDR #include "filter/f-inst.h" #include "filter/data.h" +#include "nest/volatile.h" CF_DEFINES @@ -366,16 +367,35 @@ conf: definition ; definition: DEFINE symbol '=' term ';' { struct f_line *line = f_linearize($4, 1); + int volat = 0; struct filter_iterator fit; - FILTER_ITERATE_INIT(&fit, - if + FILTER_ITERATE_INIT(&fit, line, new_config->pool); + FILTER_ITERATE(&fit, fi) + { + switch (fi->fi_code) + { + case FI_VOLATILE_ROUTE_COUNTER: + case FI_VOLATILE_TERM: + volat = 1; + break; + default: + break; + } + } + FILTER_ITERATE_END; + FILTER_ITERATE_CLEANUP(&fit); - struct f_val val; - if (f_eval(, &val) > F_RETURN) cf_error("Runtime error"); - cf_define_symbol($2, SYM_CONSTANT | val.type, val, lp_val_copy(cfg_mem, &val)); + if (volat) + cf_define_symbol($2, SYM_VOLATILE, volat, f_volatile_term(line)); + else + { + struct f_val val; + if (f_eval(line, &val) > F_RETURN) cf_error("Runtime error"); + cf_define_symbol($2, SYM_CONSTANT | val.type, val, lp_val_copy(cfg_mem, &val)); + } } | DEFINE symbol '=' COUNT ROUTE r_args ';' { - cf_define_symbol($2, SYM_VOLATILE, volat, f_volatile_counter($6)); + cf_define_symbol($2, SYM_VOLATILE, volat, rt_volatile_route_counter($6)); } ; @@ -820,12 +840,9 @@ symbol_value: symbol_known case SYM_ATTRIBUTE: $$ = f_new_inst(FI_EA_GET, $1->attribute); break; - case SYM_COUNTER: - $$ = f_new_inst(FI_COUNTER, $1); - break; - case SYM_COUNTER_TERM: - $$ = f_new_inst(FI_COUNTER_TERM, $1); - break; + case SYM_VOLATILE: + $$ = f_copy_inst($1->volat->inst); + break; default: cf_error("Can't get value of symbol %s", $1->name); } diff --git a/filter/f-inst.c b/filter/f-inst.c index ba202507..32d3c053 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -542,13 +542,14 @@ RESULT_VAL(fstk->vstk[curline.vbase + sym->offset]); } - INST(FI_COUNTER, 0, 1) { - SYMBOL; + INST(FI_VOLATILE_ROUTE_COUNTER, 0, 1) { + FID_MEMBER(struct volatile_route_counter_config *, vrcc, vrcc->vc.sym->flags & SYM_FLAG_SAME, "count route %p", item->vrcc); + NEVER_CONSTANT; - RESULT(T_INT, i, stats_get_counter(sym)); + RESULT(T_INT, i, vrcc->counter_pub); } - INST(FI_COUNTER_TERM, 0, 1) { + INST(FI_VOLATILE_TERM, 0, 1) { SYMBOL; NEVER_CONSTANT; diff --git a/filter/f-inst.h b/filter/f-inst.h index 44516174..52e2b8ae 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -29,6 +29,15 @@ enum f_instruction_flags { #include "filter/inst-gen.h" #define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) +static inline struct f_inst * +f_copy_inst(struct f_inst *i) +{ + ASSERT_DIE(i->next == NULL); + struct f_inst *ii = tmp_allocz(sizeof *ii); + memcpy(ii, i, sizeof *ii); + ii->lineno = ifs->lino; + return ii; +} /* Convert the instruction back to the enum name */ const char *f_instruction_name_(enum f_instruction_code fi); @@ -94,6 +103,8 @@ void f_add_lines(const struct f_line_item *what, struct filter_iterator *fit); struct filter *f_new_where(struct f_inst *); +struct volatile_config *f_volatile_term(const struct f_line *); + static inline struct f_static_attr f_new_static_attr(btype type, int code, int readonly) { return (struct f_static_attr) { .type = type, .sa_code = code, .readonly = readonly }; } struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn); diff --git a/nest/rt.h b/nest/rt.h index 79694016..839250e7 100644 --- a/nest/rt.h +++ b/nest/rt.h @@ -666,6 +666,8 @@ void rt_show(struct rt_show_data *); struct rt_show_data_rtable * rt_show_add_exporter(struct rt_show_data *d, struct rt_exporter *t, const char *name); struct rt_show_data_rtable * rt_show_add_table(struct rt_show_data *d, rtable *t); +struct volatile_config *rt_volatile_route_counter(struct rt_show_data *); + /* Value of table definition mode in struct rt_show_data */ #define RSD_TDB_DEFAULT 0 /* no table specified */ #define RSD_TDB_INDIRECT 0 /* show route ... protocol P ... */