diff --git a/conf/conf.h b/conf/conf.h index 4ccaa54e..d193155b 100644 --- a/conf/conf.h +++ b/conf/conf.h @@ -124,6 +124,7 @@ struct symbol { struct ea_class *attribute; /* For SYM_ATTRIBUTE */ struct f_val *val; /* For SYM_CONSTANT */ uint offset; /* For SYM_VARIABLE */ + struct channel_config *ch_config; /* For SYM_COUNTER */ }; char name[0]; @@ -156,6 +157,7 @@ struct bytestring { #define SYM_FILTER 4 #define SYM_TABLE 5 #define SYM_ATTRIBUTE 6 +#define SYM_COUNTER 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 8cecf936..23b258cd 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -758,6 +758,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; 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 e7b642ab..4dfd276b 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -473,6 +473,12 @@ RESULT_VAL(fstk->vstk[curline.vbase + sym->offset]); } + INST(FI_COUNTER, 0, 1) { + SYMBOL; + NEVER_CONSTANT; + RESULT(T_INT, i, get_stats_sum(sym)); + } + INST(FI_CONSTANT, 0, 1) { FID_MEMBER( struct f_val, diff --git a/filter/filter.c b/filter/filter.c index ad2fafe2..bd65777f 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -43,6 +43,7 @@ #include "filter/filter.h" #include "filter/f-inst.h" #include "filter/data.h" +#include "proto/stats/stats.h" /* provides function get_stats_sum used in f-inst.c */ /* Exception bits */ diff --git a/proto/stats/config.Y b/proto/stats/config.Y index b32ea773..087ac75a 100644 --- a/proto/stats/config.Y +++ b/proto/stats/config.Y @@ -61,6 +61,9 @@ stats_channel_start: net_type symbol { this_channel = channel_config_get(&channel_stats, $2->name, $1, this_proto); STATS_CC->max_generation = 16; + /* from filter/config.Y: + cf_define_symbol($3, SYM_VARIABLE | $2, offset, $3->scope->slots++) */ + $2 = cf_define_symbol($2, SYM_COUNTER, ch_config, this_channel); } stats_proto: diff --git a/proto/stats/stats.h b/proto/stats/stats.h index 51802341..d061e4ea 100644 --- a/proto/stats/stats.h +++ b/proto/stats/stats.h @@ -35,6 +35,13 @@ struct stats_channel_config { u8 max_generation; }; - +static inline int +get_stats_sum(struct symbol *sym) +{ + if (sym->ch_config->channel) + return (int) ((struct stats_channel *) sym->ch_config->channel)->sum; + else + return 0; +} #endif