diff --git a/filter/data.c b/filter/data.c index 56d746fd..183848db 100644 --- a/filter/data.c +++ b/filter/data.c @@ -315,6 +315,10 @@ clist_set_type(const struct f_tree *set, struct f_val *v) switch (set->from.type) { + case T_INT: + v->type = T_INT; + return 1; + case T_PAIR: v->type = T_PAIR; return 1; @@ -522,7 +526,7 @@ val_in_range(const struct f_val *v1, const struct f_val *v2) if ((v1->type == T_INT) && (v2->type == T_PATH)) return as_path_contains(v2->val.ad, v1->val.i, 1); - if (((v1->type == T_PAIR) || (v1->type == T_QUAD)) && (v2->type == T_CLIST)) + if (((v1->type == T_INT) || (v1->type == T_PAIR) || (v1->type == T_QUAD)) && (v2->type == T_CLIST)) return int_set_contains(v2->val.ad, v1->val.i); /* IP->Quad implicit conversion */ if (val_is_ip4(v1) && (v2->type == T_CLIST)) diff --git a/filter/f-inst.c b/filter/f-inst.c index e4b47ff4..bc15fe7e 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -1359,7 +1359,7 @@ /* Community (or cluster) list */ struct f_val dummy; - if ((v2.type == T_PAIR) || (v2.type == T_QUAD)) + if ((v2.type == T_INT) || (v2.type == T_PAIR) || (v2.type == T_QUAD)) RESULT_(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, v2.val.i) ]]); /* IP->Quad implicit conversion */ else if (val_is_ip4(&v2)) @@ -1421,7 +1421,7 @@ /* Community (or cluster) list */ struct f_val dummy; - if ((v2.type == T_PAIR) || (v2.type == T_QUAD)) + if ((v2.type == T_INT) || (v2.type == T_PAIR) || (v2.type == T_QUAD)) RESULT_(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, v2.val.i) ]]); /* IP->Quad implicit conversion */ else if (val_is_ip4(&v2)) diff --git a/filter/test.conf b/filter/test.conf index 1d291c69..a1e6f5f4 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -867,6 +867,25 @@ clist r; l = delete(l, [(*,(onef(5)))]); bt_assert(l = -empty-); + # clist with integer values instead of community pairs + clist li = add(add(add(add(add(-empty-, 100), 200), 300), 400), 500); + bt_assert(format(li) = "(clist (0,100) (0,200) (0,300) (0,400) (0,500))"); + + # clist add/delete/test for integer values + li = delete(li, 500); + li = add(li, 12345678); # Same as (188,24910) + bt_assert(200 ~ li); + bt_assert(500 !~ li); + bt_assert(12345678 ~ li); + bt_assert(12345679 !~ li); + bt_assert(format(li) = "(clist (0,100) (0,200) (0,300) (0,400) (188,24910))"); + + # clist filtered through integer set + li = delete(li, [101..1000]); + bt_assert(100 ~ li); + bt_assert(200 !~ li); + bt_assert(format(li) = "(clist (0,100) (188,24910))"); + l2 = add(l2, (3,6)); l = filter(l2, [(3,1..4)]); l2 = filter(l2, [(3,3..6)]);