summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorOndrej Zajicek <santiago@crfreenet.org>2013-07-25 22:33:57 +0200
committerOndrej Zajicek <santiago@crfreenet.org>2013-07-25 22:33:57 +0200
commit1103b32e830fbf98d9b3e32c0425b9a589773bf8 (patch)
tree9d3577cf205e74002ea43e7754f3391cc1e4992d /filter
parentac5745134847c044b21c311e5ab11d92d05bacc1 (diff)
Allows to define constants of all filter types.
Diffstat (limited to 'filter')
-rw-r--r--filter/config.Y47
-rw-r--r--filter/test.conf19
2 files changed, 27 insertions, 39 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 0eeb2ce1..2ca03463 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -193,7 +193,14 @@ f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv)
else if (tk->code == 'C') {
c1 = 1;
struct f_val *val = tk->a1.p;
- if (val->type == T_IP) {
+
+ if (val->type == T_INT) {
+ ipv4_used = 0; key = val->val.i;
+ }
+ else if (val->type == T_QUAD) {
+ ipv4_used = 1; key = val->val.i;
+ }
+ else if (val->type == T_IP) {
ipv4_used = 1; key = ipa_to_u32(val->val.px.ip);
}
else
@@ -661,37 +668,15 @@ function_call:
symbol:
SYM {
$$ = f_new_inst();
- switch ($1->class) {
- case SYM_NUMBER:
- $$ = f_new_inst();
- $$->code = 'c';
- $$->aux = T_INT;
- $$->a2.i = $1->aux;
- break;
- case SYM_IPA:
- { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; val->type = T_IP; val->val.px.ip = * (ip_addr *) ($1->def); }
- break;
- case SYM_VARIABLE | T_BOOL:
- case SYM_VARIABLE | T_INT:
- case SYM_VARIABLE | T_PAIR:
- case SYM_VARIABLE | T_QUAD:
- case SYM_VARIABLE | T_EC:
- case SYM_VARIABLE | T_STRING:
- case SYM_VARIABLE | T_IP:
- case SYM_VARIABLE | T_PREFIX:
- case SYM_VARIABLE | T_PREFIX_SET:
- case SYM_VARIABLE | T_SET:
- case SYM_VARIABLE | T_PATH:
- case SYM_VARIABLE | T_PATH_MASK:
- case SYM_VARIABLE | T_CLIST:
- case SYM_VARIABLE | T_ECLIST:
- $$->code = 'V';
- $$->a1.p = $1->def;
- $$->a2.p = $1->name;
- break;
- default:
- cf_error("%s: variable expected.", $1->name );
+
+ switch ($1->class & 0xff00) {
+ case SYM_CONSTANT: $$->code = 'C'; break;
+ case SYM_VARIABLE: $$->code = 'V'; break;
+ default: cf_error("%s: variable expected.", $1->name);
}
+
+ $$->a1.p = $1->def;
+ $$->a2.p = $1->name;
}
static_attr:
diff --git a/filter/test.conf b/filter/test.conf
index 3b29232a..4f40abff 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -240,6 +240,15 @@ int b;
print "Defined: ", a, " ", b, " ", defined(b);
}
+define is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
+define is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
+define is3 = [5, 17, 2, 11, 8, 15, 3, 19];
+
+define pxs2 = [ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ];
+
+define ecs2 = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
+
+
function __startup()
int i;
bool b;
@@ -249,9 +258,6 @@ pair pp;
quad qq;
ec cc;
int set is;
-int set is1;
-int set is2;
-int set is3;
pair set ps;
ec set ecs;
prefix set pxs;
@@ -279,11 +285,6 @@ string s;
print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/9 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false;
- is1 = [ 1, 5, 8, 11, 15, 17, 19];
-
- is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
- is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
- is3 = [5, 17, 2, 11, 8, 15, 3, 19];
print " must be true: ", 1 ~ is1, " ", 3 ~ is1, " ", 5 ~ is1;
print " must be true: ", (one+2) ~ is1, " ", 2 ~ is2, " ", 2 ~ is3;
@@ -333,6 +334,7 @@ string s;
ecs = [(rt, ten, (one+onef(0))*10), (ro, 100000, 100..200), (rt, 12345, *)];
print "EC set: ", ecs;
+ print "EC set: ", ecs2;
print "Testing EC set, true: ", (rt, 10, 20) ~ ecs, " ", (ro, 100000, 100) ~ ecs, " ", (ro, 100000, 200) ~ ecs,
" ", (rt, 12345, 0) ~ ecs, " ", cc ~ ecs, " ", (rt, 12345, 4000000) ~ ecs;
print "Testing EC set, false: ", (ro, 10, 20) ~ ecs, " ", (rt, 10, 21) ~ ecs, " ", (ro, 100000, 99) ~ ecs,
@@ -354,6 +356,7 @@ string s;
print " must be false: ", 1.1.0.0/16 ~ pxs, ",", 1.3.0.0/16 ~ pxs, ",", 1.2.0.0/15 ~ pxs, ",", 1.2.0.0/17 ~ pxs, ",",
1.2.0.0/32 ~ pxs, ",", 1.4.0.0/15 ~ pxs;
+ test_pxset(pxs2);
test_pxset([ 10.0.0.0/16{8,12}, 20.0.0.0/16{24,28} ]);
print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];