diff --git a/filter/config.Y b/filter/config.Y index 53884bb7..194e312d 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -207,11 +207,11 @@ f_generate_empty(const struct symbol *sym) cf_error("Can't empty %s: not an attribute", sym->name); const struct ea_class *def = sym->attribute; - const struct f_val *empty = f_get_empty(def->type); - if (!empty) + const struct f_val empty = f_get_empty(def->type); + if (empty.type == T_VOID) cf_error("Can't empty attribute %s", def->name); - return f_new_inst(FI_EA_SET, f_new_inst(FI_CONSTANT, *empty), def); + return f_new_inst(FI_EA_SET, f_new_inst(FI_CONSTANT, empty), def); } static inline struct f_inst * @@ -875,10 +875,10 @@ term: | dynamic_attr '.' RESET{ } */ - | '+' EMPTY '+' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_path); } - | '-' EMPTY '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_clist); } - | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_eclist); } - | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_lclist); } + | '+' EMPTY '+' { $$ = f_new_inst(FI_CONSTANT, f_get_empty(T_PATH)); } + | '-' EMPTY '-' { $$ = f_new_inst(FI_CONSTANT, f_get_empty(T_CLIST)); } + | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_get_empty(T_ECLIST)); } + | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_get_empty(T_LCLIST)); } | PREPEND '(' term ',' term ')' { $$ = f_new_inst(FI_PATH_PREPEND, $3, $5); } | ADD '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_ADD, $3, $5); } | DELETE '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_DEL, $3, $5); } diff --git a/filter/data.c b/filter/data.c index 9794f230..68f834a2 100644 --- a/filter/data.c +++ b/filter/data.c @@ -81,20 +81,7 @@ f_type_element_type(btype t) } const struct f_trie f_const_empty_trie = { .ipv4 = -1, }; - -const struct f_val f_const_empty_path = { - .type = T_PATH, - .val.ad = &null_adata, -}, f_const_empty_clist = { - .type = T_CLIST, - .val.ad = &null_adata, -}, f_const_empty_eclist = { - .type = T_ECLIST, - .val.ad = &null_adata, -}, f_const_empty_lclist = { - .type = T_LCLIST, - .val.ad = &null_adata, -}, f_const_empty_prefix_set = { +const struct f_val f_const_empty_prefix_set = { .type = T_PREFIX_SET, .val.ti = &f_const_empty_trie, }; diff --git a/filter/data.h b/filter/data.h index b5db4aec..cecb7bd5 100644 --- a/filter/data.h +++ b/filter/data.h @@ -242,15 +242,20 @@ undef_value(struct f_val v) (v.val.ad == &null_adata); } -extern const struct f_val f_const_empty_path, f_const_empty_clist, f_const_empty_eclist, f_const_empty_lclist, f_const_empty_prefix_set; -static inline const struct f_val *f_get_empty(btype t) +extern const struct f_val f_const_empty_prefix_set; +static inline struct f_val f_get_empty(btype t) { switch (t) { - case T_PATH: return &f_const_empty_path; - case T_CLIST: return &f_const_empty_clist; - case T_ECLIST: return &f_const_empty_eclist; - case T_LCLIST: return &f_const_empty_lclist; - default: return NULL; + case T_PATH: + case T_CLIST: + case T_ECLIST: + case T_LCLIST: + return (struct f_val) { + .type = t, + .val.ad = &null_adata, + }; + default: + return (struct f_val) { .type = T_VOID }; } } diff --git a/filter/f-inst.c b/filter/f-inst.c index bc5477a3..de5314fc 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -873,7 +873,7 @@ ACCESS_RTE; RESULT_TYPE(da->type); { - const struct f_val *empty; + struct f_val empty; const eattr *e = ea_find(fs->rte->attrs, da->id); if (e) @@ -891,8 +891,8 @@ }]]); } } - else if (empty = f_get_empty(da->type)) - RESULT_VAL(*empty); + else if ((empty = f_get_empty(da->type)).type != T_VOID) + RESULT_VAL(empty); else RESULT_VOID; }