]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Filters: Fixes pm_same() w.r.t. ASN ranges and ASN expressions
authorOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 8 Jun 2016 22:30:41 +0000 (00:30 +0200)
committerOndrej Zajicek (work) <santiago@crfreenet.org>
Wed, 8 Jun 2016 22:30:41 +0000 (00:30 +0200)
This is necessary for proper detection of filter changes during
reconfigurations.

filter/config.Y
filter/filter.c
filter/test.conf

index e53d8def04e57066a9311f9ebf12ebc6e2236572..da6057103f626387534b112557790e7772801d84 100644 (file)
@@ -626,17 +626,17 @@ bgp_path:
  ;
 
 bgp_path_tail1:
-   NUM bgp_path_tail1 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASN;      $$->val = $1; }
- | NUM DDOT NUM bgp_path_tail1 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $4; $$->kind = PM_ASN_RANGE;      $$->val = $1; $$->val2 = $3; }
- | '*' bgp_path_tail1 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASTERISK; $$->val  = 0; }
- | '?' bgp_path_tail1 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_QUESTION; $$->val  = 0; }
- | bgp_path_expr bgp_path_tail1 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASN_EXPR; $$->val = (uintptr_t) $1; }
- |                   { $$ = NULL; }
+   NUM bgp_path_tail1          { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASN; $$->val = $1; }
+ | NUM DDOT NUM bgp_path_tail1 { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $4; $$->kind = PM_ASN_RANGE; $$->val = $1; $$->val2 = $3; }
+ | '*' bgp_path_tail1          { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASTERISK; }
+ | '?' bgp_path_tail1          { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_QUESTION; }
+ | bgp_path_expr bgp_path_tail1        { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASN_EXPR; $$->val = (uintptr_t) $1; }
+ |                             { $$ = NULL; }
  ;
 
 bgp_path_tail2:
-   NUM bgp_path_tail2 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASN;      $$->val = $1; }
- | '?' bgp_path_tail2 { $$ = cfg_alloc(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASTERISK; $$->val  = 0; }
+   NUM bgp_path_tail2 { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASN; $$->val = $1; }
+ | '?' bgp_path_tail2 { $$ = cfg_allocz(sizeof(struct f_path_mask)); $$->next = $2; $$->kind = PM_ASTERISK; }
  |                   { $$ = NULL; }
  ;
 
index dce98e4d32c0ef1e32fb8fe710353372f8c50b4f..c61377b7c3963e96e05fe75c8a5d927eae155c75 100644 (file)
@@ -163,13 +163,24 @@ val_compare(struct f_val v1, struct f_val v2)
 }
 
 static int
-pm_path_same(struct f_path_mask *m1, struct f_path_mask *m2)
+pm_same(struct f_path_mask *m1, struct f_path_mask *m2)
 {
   while (m1 && m2)
   {
-    if ((m1->kind != m2->kind) || (m1->val != m2->val))
+    if (m1->kind != m2->kind)
       return 0;
 
+    if (m1->kind == PM_ASN_EXPR)
+    {
+      if (!i_same((struct f_inst *) m1->val, (struct f_inst *) m2->val))
+       return 0;
+    }
+    else
+    {
+      if ((m1->val != m2->val) || (m1->val2 != m2->val2))
+       return 0;
+    }
+
     m1 = m1->next;
     m2 = m2->next;
   }
@@ -199,7 +210,7 @@ val_same(struct f_val v1, struct f_val v2)
 
   switch (v1.type) {
   case T_PATH_MASK:
-    return pm_path_same(v1.val.path_mask, v2.val.path_mask);
+    return pm_same(v1.val.path_mask, v2.val.path_mask);
   case T_PATH:
   case T_CLIST:
   case T_ECLIST:
index ad8f9386cc7903f4bd28f9ad2bd4690d4e4cbb73..f61f0658e05bfb3ea3c0d5e453697367a0a0e752 100644 (file)
@@ -109,6 +109,9 @@ eclist el2;
        print "Should be true: ", p2 ~ [= 5..6 4..10 1..3 1..3 1..65536 =];
        print "Should be true: ", p2 ~ [= (3+2) (2*2) 3 2 1 =], " ", p2 ~ mkpath(5, 4);
        print "Should be true: ", p2.len = 5, " ", p2.first = 5, " ", p2.last = 1;
+       print "Should be true: ", pm1 = [= 4 3 2 1 =], " ", pm1 != [= 4 3 1 2 =], " ",
+                               pm2 = [= 3..6 3 2 1..2 =], " ", pm2 != [= 3..6 3 2 1..3 =], " ",
+                               [= 1 2 (1+2) =] = [= 1 2 (1+2) =], " ", [= 1 2 (1+2) =] != [= 1 2 (2+1) =];
        print "5 = ", p2.len;
        print "Delete 3:   ", delete(p2, 3);
        print "Filter 1-3: ", filter(p2, [1..3]);