diff options
Diffstat (limited to 'filter')
-rw-r--r-- | filter/config.Y | 14 | ||||
-rw-r--r-- | filter/f-inst.c | 16 | ||||
-rw-r--r-- | filter/f-inst.h | 4 | ||||
-rw-r--r-- | filter/test.conf | 4 |
4 files changed, 19 insertions, 19 deletions
diff --git a/filter/config.Y b/filter/config.Y index dabe4781..67bd04b4 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -308,7 +308,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, %type <xp> cmds_int cmd_prep %type <x> term block cmd cmds constant constructor print_list var_list function_call symbol_value bgp_path_expr bgp_path bgp_path_tail -%type <fda> dynamic_attr +%type <fda> dynamic_attr attr_bit %type <fsa> static_attr %type <f> filter where_filter %type <fl> filter_body function_body @@ -802,6 +802,10 @@ term: | static_attr { $$ = f_new_inst(FI_RTA_GET, $1); } | dynamic_attr { $$ = f_new_inst(FI_EA_GET, $1); } + | attr_bit { + struct f_inst *c = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_INT, .val.i = (1U << $1.bit)}); + $$ = f_new_inst(FI_EQ, c, f_new_inst(FI_BITAND, f_new_inst(FI_EA_GET, $1), c)); + } | term '.' IS_V4 { $$ = f_new_inst(FI_IS_V4, $1); } | term '.' TYPE { $$ = f_new_inst(FI_TYPE, $1); } @@ -899,6 +903,14 @@ cmd: | UNSET '(' dynamic_attr ')' ';' { $$ = f_new_inst(FI_EA_UNSET, $3); } + | attr_bit '=' term ';' { + $$ = f_new_inst(FI_CONDITION, $3, + f_generate_complex(FI_BITOR, $1, + f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_INT, .val.i = (1U << $1.bit)})), + f_generate_complex(FI_BITAND, $1, + f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_INT, .val.i = ~(1U << $1.bit)})) + ); + } | break_command print_list ';' { struct f_inst *breaker = f_new_inst(FI_DIE, $1); if ($2) { diff --git a/filter/f-inst.c b/filter/f-inst.c index 0050c237..8bfec479 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -712,9 +712,6 @@ case EAF_TYPE_AS_PATH: RESULT_(T_PATH, ad, e->u.ptr); break; - case EAF_TYPE_BITFIELD: - RESULT_(T_BOOL, i, !!(e->u.data & (1u << da.bit))); - break; case EAF_TYPE_INT_SET: RESULT_(T_CLIST, ad, e->u.ptr); break; @@ -774,19 +771,6 @@ l->attrs[0].u.ptr = v1.val.ad; break; - case EAF_TYPE_BITFIELD: - { - /* First, we have to find the old value */ - eattr *e = ea_find(*fs->eattrs, da.ea_code); - u32 data = e ? e->u.data : 0; - - if (v1.val.i) - l->attrs[0].u.data = data | (1u << da.bit); - else - l->attrs[0].u.data = data & ~(1u << da.bit); - } - break; - default: bug("Unknown dynamic attribute type"); } diff --git a/filter/f-inst.h b/filter/f-inst.h index df45f88e..9265ecec 100644 --- a/filter/f-inst.h +++ b/filter/f-inst.h @@ -89,8 +89,8 @@ void f_add_lines(const struct f_line_item *what, struct filter_iterator *fit); struct filter *f_new_where(struct f_inst *); static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ { return (struct f_dynamic_attr) { .type = type, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ -static inline struct f_dynamic_attr f_new_dynamic_attr_bit(u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ -{ return (struct f_dynamic_attr) { .type = EAF_TYPE_BITFIELD, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ +static inline struct f_dynamic_attr f_new_dynamic_attr_bit(u8 bit, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ +{ return (struct f_dynamic_attr) { .type = EAF_TYPE_INT, .bit = bit, .f_type = T_INT, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly) { return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; } struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument); diff --git a/filter/test.conf b/filter/test.conf index 1058d34e..ee2f5be4 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -1342,6 +1342,10 @@ int j; rip_metric = 14; unset(rip_metric); +# krt_lock_mtu = false; +# krt_lock_window = true; +# krt_lock_rtt = krt_lock_rttvar && krt_lock_sstresh || krt_lock_cwnd; + accept "ok I take that"; } |