]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Allow integers in operations on clists oz-clist-int
authorOndrej Zajicek <santiago@crfreenet.org>
Tue, 28 Feb 2023 16:02:21 +0000 (17:02 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Tue, 28 Feb 2023 16:02:21 +0000 (17:02 +0100)
The clists are internally implemented as integer lists. We currently
allow pair values (communities in community list) and quad values
(cluster ids in cluster lists) for add/del/member/filter operations
on clists. Allow also generic integers, so it can be used as a generic
integer list.

filter/data.c
filter/f-inst.c
filter/test.conf

index 56d746fde6db418160004cd3e2efb68ebb43bfd6..183848db1e0d25dc67d91a0e66b86f2e13258f29 100644 (file)
@@ -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))
index e4b47ff48499fed83a4a103b82ebe8d4a66812f8..bc15fe7ee30b29e0a14fb58f28d4de3af3db537e 100644 (file)
       /* 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))
       /* 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))
index 1d291c695b2cf073b446e0fc34c9636b6800c115..a1e6f5f4acb8f6de8fafc3df648200ad934a14d1 100644 (file)
@@ -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)]);