summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--filter/config.Y30
-rw-r--r--filter/f-util.c2
-rw-r--r--filter/filter.c13
-rw-r--r--filter/filter.h8
-rw-r--r--filter/test.conf9
5 files changed, 37 insertions, 25 deletions
diff --git a/filter/config.Y b/filter/config.Y
index 540a85d..0a14856 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -10,6 +10,7 @@
FIXME: create community lists
FIXME: write access to dynamic attributes.
FIXME: '! =' should not be permitted. Ze `!=' by nemelo byt totez jako `! =' Nadefinujes si pres %token novy token a do cf-lex.l pridas nove pravidlo, ktere jej rozpoznava. Napriklad != return NEQ;
+ FIXME: write access to static attribute: Z rte ma byt read/write: pref, attrs (neprimo).
*/
@@ -229,21 +230,21 @@ switch_body: /* EMPTY */ { $$ = NULL; }
;
constant:
- CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $3; }
- | NUM { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $1; }
- | TRUE { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_BOOL; $$->a2.i = 1; }
- | FALSE { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_BOOL; $$->a2.i = 0; }
- | TEXT { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_STRING; $$->a2.p = $1; }
- | pair { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_PAIR; $$->a2.i = $1; }
+ CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $3; }
+ | NUM { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $1; }
+ | TRUE { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 1; }
+ | FALSE { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 0; }
+ | TEXT { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_STRING; $$->a2.p = $1; }
+ | pair { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_PAIR; $$->a2.i = $1; }
| ipa { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
| prefix_s {NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
- | '[' set_items ']' { printf( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_SET; $$->a2.p = build_tree($2); printf( "ook\n" ); }
- | ENUM { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = $1 >> 16; $$->a2.i = $1 & 0xffff; }
+ | '[' set_items ']' { printf( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_SET; $$->a2.p = build_tree($2); printf( "ook\n" ); }
+ | ENUM { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
;
any_dynamic:
- RIP_METRIC { $$ = f_new_inst(); $$->a1.i = T_INT; $$->a2.i = EA_RIP_METRIC;}
- | RIP_TAG { $$ = f_new_inst(); $$->a1.i = T_INT; $$->a2.i = EA_RIP_TAG; }
+ RIP_METRIC { $$ = f_new_inst(); $$->aux = T_INT; $$->a2.i = EA_RIP_METRIC;}
+ | RIP_TAG { $$ = f_new_inst(); $$->aux = T_INT; $$->a2.i = EA_RIP_TAG; }
;
@@ -283,8 +284,8 @@ term:
| RTA '.' any_dynamic { $$ = $3; $$->code = 'ea'; }
- | term '.' IP { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->a2.i = T_IP; }
- | term '.' LEN { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->a2.i = T_INT; }
+ | term '.' IP { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->aux = T_IP; }
+ | term '.' LEN { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->aux = T_INT; }
| term '.' MASK '(' term ')' { $$ = f_new_inst(); $$->code = 'iM'; $$->a1.p = $1; $$->a2.p = $5; }
;
@@ -356,6 +357,11 @@ cmd:
$$->a1.p = $1;
$$->a2.p = $3;
}
+ | RTA '.' any_dynamic '=' term ';' {
+ $$ = $3;
+ $$->code = 'eS';
+
+ }
| break_command print_list ';' { $$ = f_new_inst(); $$->code = 'p,'; $$->a1.p = $2; $$->a2.i = $1; }
| SYM '(' var_list ')' ';' {
struct symbol *sym;
diff --git a/filter/f-util.c b/filter/f-util.c
index 40805f8..b070d95 100644
--- a/filter/f-util.c
+++ b/filter/f-util.c
@@ -27,7 +27,7 @@ f_new_inst(void)
{
struct f_inst * ret;
ret = cfg_alloc(sizeof(struct f_inst));
- ret->code = 0;
+ ret->code = ret->aux = 0;
ret->arg1 = ret->arg2 = ret->next = NULL;
return ret;
}
diff --git a/filter/filter.c b/filter/filter.c
index a26b9e6..458b876 100644
--- a/filter/filter.c
+++ b/filter/filter.c
@@ -250,7 +250,7 @@ interpret(struct f_inst *what)
break;
case 'c': /* integer (or simple type) constant */
- res.type = what->a1.i;
+ res.type = what->aux;
res.val.i = what->a2.i;
break;
case 'C':
@@ -284,7 +284,7 @@ interpret(struct f_inst *what)
case F_ACCEPT:
/* Should take care about turning ACCEPT into MODIFY */
case F_ERROR:
- case F_REJECT:
+ case F_REJECT: /* FIXME (noncritical) Should print compele route along with reason to reject route */
res.type = T_RETURN;
res.val.i = what->a1.i;
break;
@@ -298,11 +298,14 @@ interpret(struct f_inst *what)
case 'a': /* rta access */
{
struct rta *rta = (*f_rte)->attrs;
- res.type = what->a1.i;
+ res.type = what->aux;
switch(res.type) {
case T_IP:
res.val.px.ip = * (ip_addr *) ((char *) rta + what->a2.i);
break;
+ case T_ENUM:
+ res.val.i = * ((char *) rta + what->a2.i);
+ break;
case T_PREFIX: /* Warning: this works only for prefix of network */
{
res.val.px.ip = (*f_rte)->net->n.prefix;
@@ -321,7 +324,7 @@ interpret(struct f_inst *what)
res.type = T_VOID;
break;
}
- res.type = what->a1.i;
+ res.type = what->aux;
switch (what->a1.i) {
case T_INT:
res.val.i = e->u.data;
@@ -333,7 +336,7 @@ interpret(struct f_inst *what)
ONEARG;
if (v1.type != T_PREFIX)
runtime( "Can not convert non-prefix this way" );
- res.type = what->a2.i;
+ res.type = what->aux;
switch(res.type) {
case T_INT: res.val.i = v1.val.px.len; break;
case T_IP: res.val.px.ip = v1.val.px.ip; break;
diff --git a/filter/filter.h b/filter/filter.h
index 189b226..a62cb24 100644
--- a/filter/filter.h
+++ b/filter/filter.h
@@ -14,7 +14,8 @@
struct f_inst { /* Instruction */
struct f_inst *next; /* Structure is 16 bytes, anyway */
- int code;
+ u16 code;
+ u16 aux;
union {
int i;
void *p;
@@ -85,8 +86,9 @@ void val_print(struct f_val v);
#define T_MASK 0xff
/* Internal types */
-#define T_VOID 0
-#define T_RETURN 1
+/* Do not use type of zero, that way we'll see errors easier. */
+#define T_VOID 1
+#define T_RETURN 2
/* User visible types, which fit in int */
#define T_INT 0x10
diff --git a/filter/test.conf b/filter/test.conf
index 97aaf8f..837c423 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -66,12 +66,13 @@ ip p;
filter testf
int j;
{
- print "Heya, filtering route to " rta.net.ip " prefixlen " rta.net.len;
+ print "Heya, filtering route to " rta.net.ip " prefixlen " rta.net.len " source " rta.source;
print "This route was from " rta.from;
j = 7;
j = 17;
- if rta.rip_metric > 15 then
- print "RIP Metric is more than infinity";
+ if rta.rip_metric > 15 then {
+ reject "RIP Metric is more than infinity";
+ }
- accept;
+ accept "ok I take that";
}