]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Path_getlen moved to nest and length was made callable from filters.
authorPavel Machek <pavel@ucw.cz>
Mon, 17 Apr 2000 11:06:39 +0000 (11:06 +0000)
committerPavel Machek <pavel@ucw.cz>
Mon, 17 Apr 2000 11:06:39 +0000 (11:06 +0000)
filter/config.Y
filter/filter.c
filter/test.conf
nest/a-path.c
nest/attrs.h

index 0c2247dc633389da547bf41db33422c307556dc4..6ce89e7acab8d22c186b9abc1c05cee70ec7daa7 100644 (file)
@@ -407,7 +407,7 @@ term:
  | rtadot dynamic_attr { $$ = $2; $$->code = P('e','a'); }
 
  | term '.' IP { $$ = f_new_inst(); $$->code = P('c','p'); $$->a1.p = $1; $$->aux = T_IP; }
- | term '.' LEN { $$ = f_new_inst(); $$->code = P('c','p'); $$->a1.p = $1; $$->aux = T_INT; }
+ | term '.' LEN { $$ = f_new_inst(); $$->code = 'L'; $$->a1.p = $1; }
  | term '.' MASK '(' term ')' { $$ = f_new_inst(); $$->code = P('i','M'); $$->a1.p = $1; $$->a2.p = $5; }
 
 /* Communities */
index 768ff9382f4dbeffb19ce70ed44a0e5534d2744b..6763f0cea688bc2d168a21eddd7e2da4dec17dfc 100644 (file)
@@ -404,13 +404,22 @@ interpret(struct f_inst *what)
     }
     break;
 
+  case 'L':    /* Get length of */
+    ONEARG;
+    res.type = T_INT;
+    switch(v1.type) {
+    case T_PREFIX: res.val.i = v1.val.px.len; break;
+    case T_PATH:   res.val.i = as_path_getlen(v1.val.ad); break;
+    default: bug( "Length of what?" );
+    }
+    break;
   case P('c','p'):     /* Convert prefix to ... */
     ONEARG;
     if (v1.type != T_PREFIX)
       runtime( "Can not convert non-prefix this way" );
     res.type = what->aux;
     switch(res.type) {
-    case T_INT:        res.val.i = v1.val.px.len; break;
+      /*    case T_INT:        res.val.i = v1.val.px.len; break; Not needed any more */
     case T_IP: res.val.px.ip = v1.val.px.ip; break;
     default: bug( "Unknown prefix to conversion" );
     }
@@ -536,7 +545,7 @@ i_same(struct f_inst *f1, struct f_inst *f2)
     if (val_compare(* (struct f_val *) f1->a1.p, * (struct f_val *) f2->a2.p))
       return 0;
     break;
-  case 'p': ONEARG; break;
+  case 'p': case 'L': ONEARG; break;
   case '?': TWOARGS; break;
   case '0': case 'E': break;
   case P('p',','): ONEARG; A2_SAME; break;
@@ -612,21 +621,6 @@ filter_same(struct filter *new, struct filter *old)
  * Or maybe both versions are usefull?
  */
 
-int
-path_getlen(u8 *p, int len)
-{
-  int res = 0;
-  u8 *q = p+len;
-  while (p<q) {
-    switch (*p++) {
-    case 1: len = *p++; res++;    p += 2*len; break;
-    case 2: len = *p++; res+=len; p += 2*len; break;
-    default: bug("This should not be in path");
-    }
-  }
-  return res;
-}
-
 #define MASK_PLUS do { mask = mask->next; if (!mask) return next == q; \
                       asterix = (mask->val == PM_ANY); \
                        if (asterix) { mask = mask->next; if (!mask) { return 1; } } \
index a31c7f2dc9ffe23e6d4d3f9c30df518f1324896e..a39e6a3d65aae69ba3c9f1f4b08366f8bd1f6d6b 100644 (file)
@@ -41,9 +41,11 @@ bgppath p2;
        p2 = prepend( p2, 4 );
        print "Testing paths: ", p2;
        print "Should be true: ", p2 ~ p;
+       print "4 = ", p2.len;
        p2 = prepend( p2, 5 );
        print "Should be false: ", p2 ~ p;
        print "Should be true: ", p2 ~ / * 4 3 2 1 /, p2, / * 4 3 2 1 /;
+       print "5 = ", p2.len;
 }
 
 function startup() 
index ca39e29624ac5c7330881a93852c7aa6cc189f70..d808bc9a34b49959e757b528111909cf507687d1 100644 (file)
@@ -81,3 +81,21 @@ as_path_format(struct adata *path, byte *buf, unsigned int size)
     }
   *buf = 0;
 }
+
+int
+as_path_getlen(struct adata *path)
+{
+  int res = 0;
+  u8 *p = path->data;
+  u8 *q = p+path->length;
+  int len;
+
+  while (p<q) {
+    switch (*p++) {
+    case 1: len = *p++; res++;    p += 2*len; break;
+    case 2: len = *p++; res+=len; p += 2*len; break;
+    default: bug("This should not be in path");
+    }
+  }
+  return res;
+}
index fc960fb5cbcd0d76574d1bc73ac1e6e610dd4f6b..67ec52d80a597e5b113d1100c5323f437330745f 100644 (file)
 
 /* a-path.c */
 
-struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as);
-void as_path_format(struct adata *path, byte *buf, unsigned int size);
-
 #define AS_PATH_SET            1       /* Types of path segments */
 #define AS_PATH_SEQUENCE       2
 
+struct adata *as_path_prepend(struct linpool *pool, struct adata *olda, int as);
+void as_path_format(struct adata *path, byte *buf, unsigned int size);
+int as_path_getlen(struct adata *path);
+
 /* a-set.c */
 
 void int_set_format(struct adata *set, byte *buf, unsigned int size);