diff options
-rw-r--r-- | filter/f-inst.c | 101 | ||||
-rw-r--r-- | filter/test.conf | 12 |
2 files changed, 85 insertions, 28 deletions
diff --git a/filter/f-inst.c b/filter/f-inst.c index 33b294fa..e4a10221 100644 --- a/filter/f-inst.c +++ b/filter/f-inst.c @@ -1270,22 +1270,39 @@ } /* Community list add */ - INST(FI_CLIST_ADD, 2, 1) { + INST(FI_CLIST_ADD_PAIR, 2, 1) { ARG(1, T_CLIST); - ARG_ANY(2); + ARG(2, T_PAIR); METHOD_CONSTRUCTOR("add"); - struct f_val dummy; - if ((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)) - RESULT(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, ipa_to_u32(v2.val.ip)) ]]); - else if ((v2.type == T_SET) && clist_set_type(v2.val.t, &dummy)) - runtime("Can't add set"); - else if (v2.type == T_CLIST) - RESULT(T_CLIST, ad, [[ int_set_union(fpool, v1.val.ad, v2.val.ad) ]]); - else - runtime("Can't add non-pair"); + RESULT(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, v2.val.i) ]]); + } + + INST(FI_CLIST_ADD_IP, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_IP); + METHOD_CONSTRUCTOR("add"); + + FID_NEW_BODY(); + /* IP->Quad implicit conversion, must be before FI_CLIST_ADD_QUAD */ + cf_warn("Method add(clist, ip) is deprecated, please use add(clist, quad)"); + + FID_INTERPRET_BODY(); + if (!val_is_ip4(&v2)) runtime("Mismatched IP type"); + RESULT(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, ipa_to_u32(v2.val.ip)) ]]); + } + + INST(FI_CLIST_ADD_QUAD, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_QUAD); + METHOD_CONSTRUCTOR("add"); + RESULT(T_CLIST, ad, [[ int_set_add(fpool, v1.val.ad, v2.val.i) ]]); + } + + INST(FI_CLIST_ADD_CLIST, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_CLIST); + METHOD_CONSTRUCTOR("add"); + RESULT(T_CLIST, ad, [[ int_set_union(fpool, v1.val.ad, v2.val.ad) ]]); } INST(FI_ECLIST_ADD_EC, 2, 1) { @@ -1354,22 +1371,50 @@ } /* Community list delete */ - INST(FI_CLIST_DELETE, 2, 1) { + INST(FI_CLIST_DELETE_PAIR, 2, 1) { ARG(1, T_CLIST); - ARG_ANY(2); + ARG(2, T_PAIR); METHOD_CONSTRUCTOR("delete"); - /* Community (or cluster) list */ - struct f_val dummy; - - if ((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)) - RESULT(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, ipa_to_u32(v2.val.ip)) ]]); - else if ((v2.type == T_SET) && clist_set_type(v2.val.t, &dummy) || (v2.type == T_CLIST)) - RESULT(T_CLIST, ad, [[ clist_filter(fpool, v1.val.ad, &v2, 0) ]]); - else - runtime("Can't delete non-pair"); + RESULT(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, v2.val.i) ]]); + } + + INST(FI_CLIST_DELETE_IP, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_IP); + METHOD_CONSTRUCTOR("delete"); + + FID_NEW_BODY(); + /* IP->Quad implicit conversion, must be before FI_CLIST_DELETE_QUAD */ + cf_warn("Method delete(clist, ip) is deprecated, please use delete(clist, quad)"); + + FID_INTERPRET_BODY(); + if (!val_is_ip4(&v2)) runtime("Mismatched IP type"); + RESULT(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, ipa_to_u32(v2.val.ip)) ]]); + } + + INST(FI_CLIST_DELETE_QUAD, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_QUAD); + METHOD_CONSTRUCTOR("delete"); + RESULT(T_CLIST, ad, [[ int_set_del(fpool, v1.val.ad, v2.val.i) ]]); + } + + INST(FI_CLIST_DELETE_CLIST, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_CLIST); + METHOD_CONSTRUCTOR("delete"); + RESULT(T_CLIST, ad, [[ clist_filter(fpool, v1.val.ad, &v2, 0) ]]); + } + + INST(FI_CLIST_DELETE_SET, 2, 1) { + ARG(1, T_CLIST); + ARG(2, T_SET); + METHOD_CONSTRUCTOR("delete"); + + if (!clist_set_type(v2.val.t, &(struct f_val){})) + runtime("Mismatched set type"); + + RESULT(T_CLIST, ad, [[ clist_filter(fpool, v1.val.ad, &v2, 0) ]]); } INST(FI_ECLIST_DELETE_EC, 2, 1) { diff --git a/filter/test.conf b/filter/test.conf index 62993898..22b4984a 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -1010,6 +1010,12 @@ clist r; l = filter(l2, [(3,1..4)]); l2 = filter(l2, [(3,3..6)]); + quad q = 2.0.1.0; + clist ql = add(add(add(-empty-, 1.0.0.1), q), 3.1.0.0); + bt_assert(delete(ql, 1.0.0.1) = add(add(-empty-, 2.0.1.0), 3.1.0.0)); + bt_assert(delete(ql, [2.0.0.0 .. 4.0.0.0]) = add(-empty-, 1.0.0.1)); + bt_assert(filter(ql, [3.0.0.0 .. 4.0.0.0]) = add(-empty-, 3.1.0.0)); + # clist A (10,20,30) bt_assert(l = add(add(add(add(-empty-, (3,1)), (3,2)), (3,3)), (3,4))); bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))"); @@ -1132,6 +1138,12 @@ function t_clist_new() l = l2.filter([(3,1..4)]); l2.filter([(3,3..6)]); + quad q = 2.0.1.0; + clist ql = -empty-.add(1.0.0.1).add(q).add(3.1.0.0); + bt_assert(delete(ql, 1.0.0.1) = -empty-.add(2.0.1.0).add(3.1.0.0)); + bt_assert(delete(ql, [2.0.0.0 .. 4.0.0.0]) = -empty-.add(1.0.0.1)); + bt_assert(filter(ql, [3.0.0.0 .. 4.0.0.0]) = -empty-.add(3.1.0.0)); + # clist A (10,20,30) bt_assert(l = -empty-.add((3,1)).add((3,2)).add((3,3)).add((3,4))); bt_assert(format(l) = "(clist (3,1) (3,2) (3,3) (3,4))"); |