diff --git a/filter/data.c b/filter/data.c index 7295887d..09c71e5a 100644 --- a/filter/data.c +++ b/filter/data.c @@ -79,6 +79,8 @@ f_type_element_type(enum f_type 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, @@ -91,6 +93,9 @@ const struct f_val f_const_empty_path = { }, f_const_empty_lclist = { .type = T_LCLIST, .val.ad = &null_adata, +}, f_const_empty_prefix_set = { + .type = T_PREFIX_SET, + .val.ti = &f_const_empty_trie, }; static struct adata * @@ -187,6 +192,11 @@ val_compare(const struct f_val *v1, const struct f_val *v2) if (val_is_ip4(v1) && (v2->type == T_QUAD)) return uint_cmp(ipa_to_u32(v1->val.ip), v2->val.i); + if ((v1->type == T_SET) && (v2->type == T_PREFIX_SET)) + return (!v1->val.t) && (v2->val.ti == &f_const_empty_trie) ? 0 : F_CMP_ERROR; + if ((v1->type == T_PREFIX_SET) && (v2->type == T_SET)) + return (v1->val.ti == &f_const_empty_trie) && (!v2->val.t) ? 0 : F_CMP_ERROR; + debug( "Types do not match in val_compare\n" ); return F_CMP_ERROR; } diff --git a/filter/data.h b/filter/data.h index 84d48a7c..221e4229 100644 --- a/filter/data.h +++ b/filter/data.h @@ -299,7 +299,7 @@ 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; +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; enum filter_return f_eval(const struct f_line *expr, struct linpool *tmp_pool, struct f_val *pres); diff --git a/filter/decl.m4 b/filter/decl.m4 index 75e65212..24d831b3 100644 --- a/filter/decl.m4 +++ b/filter/decl.m4 @@ -497,10 +497,7 @@ f_const_promotion(struct f_inst *arg, enum f_type want) else if ((c->type == T_SET) && (want == T_PREFIX_SET)) { if (c->val.t) return 0; - *c = (struct f_val) { - .type = T_PREFIX_SET, - .val.ti = f_new_trie(cfg_mem, 0), - }; + *c = f_const_empty_prefix_set; return 1; } diff --git a/filter/f-inst.c b/filter/f-inst.c index 999b7fc7..b0dce4f9 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -1282,14 +1282,12 @@ u32 key = 0; int use_set = 0; - if (v2.type == T_INT) - key = v2.val.i; - else if ((v2.type == T_SET) && path_set_type(v2.val.t)) { + if ((v2.type == T_SET) && path_set_type(v2.val.t)) { use_set = 1; set = v2.val.t; } else - runtime("Can't filter non-integer (set)"); + runtime("Can't filter integer"); RESULT_(T_PATH, ad, [[ as_path_filter(fpool, v1.val.ad, set, key, use_set, 1) ]]); }