summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2014-10-14 17:23:34 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2014-10-14 17:23:34 +0200
commit78342404ff573e85e396f0611014b90cea9b4c0a (patch)
tree39fd70db506dc05d83528b7afab258b07b8ac482 /filter
parent178a197afb77770d8a90765e39065679936a45d1 (diff)
parentcfdea7b85f6c520cc5a62eb907d2190db14c9900 (diff)
Merge remote-tracking branch 'origin/master' into soft-int
Diffstat (limited to 'filter')
-rw-r--r--filter/config.Y28
-rw-r--r--filter/filter.c4
-rw-r--r--filter/test.conf13
3 files changed, 37 insertions, 8 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 04acfbab..e50e75ca 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -25,6 +25,23 @@ static inline u32 pair_b(u32 p) { return p & 0xFFFF; }
* to the last item in a list (right ptr). For convenience, even items
* are handled as one-item lists. Lists are merged by f_merge_items().
*/
+static int
+f_valid_set_type(int type)
+{
+ switch (type)
+ {
+ case T_INT:
+ case T_PAIR:
+ case T_QUAD:
+ case T_ENUM:
+ case T_IP:
+ case T_EC:
+ return 1;
+
+ default:
+ return 0;
+ }
+}
static inline struct f_tree *
f_new_item(struct f_val from, struct f_val to)
@@ -473,10 +490,19 @@ fipa:
*/
set_atom:
- expr { $$.type = T_INT; $$.val.i = $1; }
+ NUM { $$.type = T_INT; $$.val.i = $1; }
| RTRID { $$.type = T_QUAD; $$.val.i = $1; }
| fipa { $$ = $1; }
| ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
+ | '(' term ')' {
+ $$ = f_eval($2, cfg_mem);
+ if (!f_valid_set_type($$.type)) cf_error("Set-incompatible type");
+ }
+ | SYM {
+ if (!cf_symbol_is_constant($1)) cf_error("%s: constant expected", $1->name);
+ if (!f_valid_set_type(SYM_TYPE($1))) cf_error("%s: set-incompatible type", $1->name);
+ $$ = *(struct f_val *)($1->def);
+ }
;
switch_atom:
diff --git a/filter/filter.c b/filter/filter.c
index 88763302..63c2cd86 100644
--- a/filter/filter.c
+++ b/filter/filter.c
@@ -493,7 +493,7 @@ f_rta_cow(void)
}
}
-static struct rate_limit rl_runtime_err;
+static struct tbf rl_runtime_err = TBF_DEFAULT_LOG_LIMITS;
#define runtime(x) do { \
log_rl(&rl_runtime_err, L_ERR "filters, line %d: %s", what->lineno, x); \
@@ -1492,7 +1492,7 @@ f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struc
if (res.type != T_RETURN) {
- log( L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name);
+ log_rl(&rl_runtime_err, L_ERR "Filter %s did not return accept nor reject. Make up your mind", filter->name);
return F_ERROR;
}
DBG( "done (%u)\n", res.val.i );
diff --git a/filter/test.conf b/filter/test.conf
index ae8a95a6..a99d0a51 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -13,6 +13,9 @@ define '1a-a1' = (20+10);
define one = 1;
define ten = 10;
+define p23 = (2, 3);
+define ip1222 = 1.2.2.2;
+
function onef(int a)
{
return 1;
@@ -78,7 +81,7 @@ function test_roa()
" ", roa_check(rl, 10.130.130.0/24, 3000) = ROA_VALID;
}
-function paths()
+function path_test()
bgpmask pm1;
bgpmask pm2;
bgppath p2;
@@ -98,7 +101,7 @@ eclist el2;
print "Should be true: ", p2 ~ pm1, " ", p2 ~ pm2, " ", 3 ~ p2, " ", p2 ~ [2, 10..20], " ", p2 ~ [4, 10..20];
print "4 = ", p2.len;
p2 = prepend( p2, 5 );
- print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2, " ", 10 ~ p2, " ", p2 ~ [8, 10..20],;
+ print "Should be false: ", p2 ~ pm1, " ", p2 ~ pm2, " ", 10 ~ p2, " ", p2 ~ [8, ten..(2*ten)];
print "Should be true: ", p2 ~ / ? 4 3 2 1 /, " ", p2, " ", / ? 4 3 2 1 /;
print "Should be true: ", p2 ~ [= * 4 3 * 1 =], " ", p2, " ", [= * 4 3 * 1 =];
print "Should be true: ", p2 ~ [= (3+2) (2*2) 3 2 1 =], " ", p2 ~ mkpath(5, 4);
@@ -124,7 +127,7 @@ eclist el2;
print "Should be always true: ", l ~ [(*,*)];
l = add( l, (2,one+2) );
print "Community list (1,2) (2,3) ", l;
- print "Should be true: ", (2,3) ~ l, " ", l ~ [(1,*)], " ", l ~ [(2,3)]," ", l ~ [(2,2..3)], " ", l ~ [(1,1..2)], " ", l ~ [(1,1)..(1,2)];
+ print "Should be true: ", (2,3) ~ l, " ", l ~ [(1,*)], " ", l ~ [p23]," ", l ~ [(2,2..3)], " ", l ~ [(1,1..2)], " ", l ~ [(1,1)..(1,2)];
l = add( l, (2,5) );
l = add( l, (5,one) );
l = add( l, (6,one) );
@@ -361,7 +364,7 @@ string st;
if ( b = true ) then print "Testing bool comparison b = true: ", b;
else { print "*** FAIL: TRUE test failed" ; quitbird; }
- ips = [ 1.1.1.0 .. 1.1.1.255, 1.2.2.2];
+ ips = [ 1.1.1.0 .. 1.1.1.255, ip1222];
print "Testing IP sets: ";
print ips;
print " must be true: ", 1.1.1.0 ~ ips, ",", 1.1.1.100 ~ ips, ",", 1.2.2.2 ~ ips;
@@ -389,7 +392,7 @@ string st;
i = fifteen();
print "Testing function calls: 15 = ", i;
- paths();
+ path_test();
print "1.2.3.4 = ", onetwo;