summaryrefslogtreecommitdiffstats
path: root/filter
diff options
context:
space:
mode:
authorPavel Machek <pavel@ucw.cz>2000-04-17 13:06:39 +0200
committerPavel Machek <pavel@ucw.cz>2000-04-17 13:06:39 +0200
commit684c6f5a0e134426159be7dbd514271aea9f4d3d (patch)
tree0e5acd2b882f7e05365d6e50a3a6fcc2f41ed974 /filter
parentecd25633bdc3e491a0eca44c63c158eeff388f13 (diff)
downloadbird-684c6f5a0e134426159be7dbd514271aea9f4d3d.tar
bird-684c6f5a0e134426159be7dbd514271aea9f4d3d.zip
Path_getlen moved to nest and length was made callable from filters.
Diffstat (limited to 'filter')
-rw-r--r--filter/config.Y2
-rw-r--r--filter/filter.c28
-rw-r--r--filter/test.conf2
3 files changed, 14 insertions, 18 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 0c2247d..6ce89e7 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -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 */
diff --git a/filter/filter.c b/filter/filter.c
index 768ff93..6763f0c 100644
--- a/filter/filter.c
+++ b/filter/filter.c
@@ -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; } } \
diff --git a/filter/test.conf b/filter/test.conf
index a31c7f2..a39e6a3 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -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()