From e58f8c28d252a9979c07b478091b8d0ef40a9f22 Mon Sep 17 00:00:00 2001 From: Pavel Tvrdik Date: Wed, 29 Jun 2016 12:21:43 +0200 Subject: [PATCH] Add `.maxlen' operator to all ROA prefixes in filters Example: bird> eval (1.2.0.0/16 max 20 as 1234).maxlen 20 Todo: Should be described in user docs --- filter/config.Y | 3 ++- filter/filter.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/filter/config.Y b/filter/config.Y index 6783ea10..79247ac9 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -279,7 +279,7 @@ CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN, FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, CAST, DEST, IFNAME, IFINDEX, PREFERENCE, ROA_CHECK, ASN, - LEN, + LEN, MAXLEN, DEFINED, ADD, DELETE, CONTAINS, RESET, PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH, @@ -740,6 +740,7 @@ 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 '.' MAXLEN { $$ = f_new_inst(); $$->code = P('R','m'); $$->a1.p = $1; } | term '.' ASN { $$ = f_new_inst(); $$->code = P('R','a'); $$->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; } diff --git a/filter/filter.c b/filter/filter.c index ba1ba753..ebdd02f2 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -1029,6 +1029,16 @@ interpret(struct f_inst *what) default: runtime( "Prefix, path, clist or eclist expected" ); } break; + case P('R','m'): /* Get ROA max prefix length */ + ONEARG; + if (v1.type != T_NET || !net_is_roa(v1.val.net)) + runtime( "ROA expected" ); + + res.type = T_INT; + res.val.i = (v1.val.net->type == NET_ROA4) ? + ((net_addr_roa4 *) v1.val.net)->max_pxlen : + ((net_addr_roa6 *) v1.val.net)->max_pxlen; + break; case P('R','a'): /* Get ROA ASN */ ONEARG; if (v1.type != T_NET || !net_is_roa(v1.val.net))