diff options
author | Ondrej Zajicek <santiago@crfreenet.org> | 2009-10-08 16:23:24 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2009-10-08 16:23:24 +0200 |
commit | 7ea5b00f42bd3d1fdafb0be349e3ebbcdf3ea466 (patch) | |
tree | b61d47b763c823837fb3efe2b443348270e1ce06 /filter | |
parent | 43c7a1ffa07dda2a9f37c046e1cd9a75242db2b7 (diff) | |
download | bird-7ea5b00f42bd3d1fdafb0be349e3ebbcdf3ea466.tar bird-7ea5b00f42bd3d1fdafb0be349e3ebbcdf3ea466.zip |
First and last accessors to as_paths.
Diffstat (limited to 'filter')
-rw-r--r-- | filter/config.Y | 4 | ||||
-rw-r--r-- | filter/filter.c | 21 |
2 files changed, 24 insertions, 1 deletions
diff --git a/filter/config.Y b/filter/config.Y index ee4e638..22206d0 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -36,7 +36,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, LEN, DEFINED, ADD, DELETE, CONTAINS, RESET, - PREPEND, MATCH, + PREPEND, FIRST, LAST, MATCH, EMPTY, FILTER, WHERE, EVAL) @@ -448,6 +448,8 @@ term: | term '.' IP { $$ = f_new_inst(); $$->code = P('c','p'); $$->a1.p = $1; $$->aux = T_IP; } | 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; } + | term '.' FIRST { $$ = f_new_inst(); $$->code = P('a','f'); $$->a1.p = $1; } + | term '.' LAST { $$ = f_new_inst(); $$->code = P('a','l'); $$->a1.p = $1; } /* Communities */ /* This causes one shift/reduce conflict diff --git a/filter/filter.c b/filter/filter.c index 8c0c4ab..7bcf383 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -353,6 +353,7 @@ interpret(struct f_inst *what) struct f_val v1, v2, res; unsigned u1, u2; int i; + u32 as; res.type = T_VOID; if (!what) @@ -727,6 +728,26 @@ interpret(struct f_inst *what) default: bug( "Unknown prefix to conversion" ); } break; + case P('a','f'): /* Get first ASN from AS PATH */ + ONEARG; + if (v1.type != T_PATH) + runtime( "AS Path expected" ); + + as = 0; + as_path_get_last(v1.val.ad, &as); /* really last */ + res.type = T_INT; + res.val.i = as; + break; + case P('a','l'): /* Get last ASN from AS PATH */ + ONEARG; + if (v1.type != T_PATH) + runtime( "AS path expected" ); + + as = 0; + as_path_get_first(v1.val.ad, &as); /* really first */ + res.type = T_INT; + res.val.i = as; + break; case 'r': ONEARG; res = v1; |