]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filter: Allow to use set constants / expressions in path masks
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 6 Aug 2019 16:54:19 +0000 (18:54 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Tue, 6 Aug 2019 16:54:19 +0000 (18:54 +0200)
Allow to not only use set literals in path masks, but also existing
set constants or set expressions.

filter/f-inst.c
filter/test.conf
nest/a-path.c
nest/attrs.h

index 0867ac4a1784dce12e423a95474f376537da03af..49ae993a2e158a7950fc54dab021d61992d86ef5 100644 (file)
        case T_PATH_MASK_ITEM:
          pm->item[i] = vv(i).val.pmi;
          break;
+
        case T_INT:
          pm->item[i] = (struct f_path_mask_item) {
            .asn = vv(i).val.i,
            .kind = PM_ASN,
          };
          break;
+
+       case T_SET:
+         if (vv(i).val.t->from.type != T_INT)
+           runtime("Only integer sets allowed in path mask");
+
+         pm->item[i] = (struct f_path_mask_item) {
+           .set = vv(i).val.t,
+           .kind = PM_ASN_SET,
+         };
+         break;
+
        default:
          runtime( "Error resolving path mask template: value not an integer" );
       }
index 04074965c06e904845ff4801e7bf5395e266dd87..09a4a88add5e3420f2c89834b05c7d0b986998dd 100644 (file)
@@ -597,11 +597,15 @@ function mkpath(int a; int b)
        return [= a b 3 2 1 =];
 }
 
+define set35 = [3 .. 5];
+
 function t_path()
 bgpmask pm1;
 bgppath p2;
+int set set12;
 {
        pm1 = [= 4 3 2 1 =];
+       set12 = [1, 2];
 
        bt_assert(format(pm1) = "[= 4 3 2 1 =]");
 
@@ -627,6 +631,7 @@ bgppath p2;
        bt_assert(p2 ~ [= * 4 3 * 1 =]);
        bt_assert(p2 ~ [= (3+2) (2*2) 3 2 1 =]);
        bt_assert(p2 ~ [= 5 [2, 4, 6] 3 [1..2] 1 =]);
+       bt_assert(p2 ~ [= 5 set35 3 set12 set12 =]);
        bt_assert(p2 ~ mkpath(5, 4));
 
        bt_assert(p2.len = 5);
index 4ee34cf4ee38fcbd24b80d0934b23c02dfd9cb0e..b6a30f548f31d3f1776ad4aaf35efb01ddf68cb4 100644 (file)
@@ -741,7 +741,7 @@ pm_match(struct pm_pos *pos, u32 asn, u32 asn2)
 }
 
 static int
-pm_match_set(struct pm_pos *pos, struct f_tree *set)
+pm_match_set(struct pm_pos *pos, const struct f_tree *set)
 {
   struct f_val asn = { .type = T_INT };
 
index a17b8c0517e255f24741ff3ba34f1a5029de4e04..6fb0a8fa32ecf04076e2029de46c40a0fdb4a842 100644 (file)
@@ -65,8 +65,8 @@ static inline struct adata *as_path_prepend(struct linpool *pool, const struct a
 struct f_path_mask_item {
   union {
     u32 asn; /* PM_ASN */
-    struct f_line *expr; /* PM_ASN_EXPR */
-    struct f_tree *set; /* PM_ASN_SET */
+    const struct f_line *expr; /* PM_ASN_EXPR */
+    const struct f_tree *set; /* PM_ASN_SET */
     struct { /* PM_ASN_RANGE */
       u32 from;
       u32 to;