diff options
Diffstat (limited to 'filter')
-rw-r--r-- | filter/config.Y | 9 | ||||
-rw-r--r-- | filter/filter.c | 73 | ||||
-rw-r--r-- | filter/test.conf | 14 |
3 files changed, 54 insertions, 42 deletions
diff --git a/filter/config.Y b/filter/config.Y index fcbee71..1af5649 100644 --- a/filter/config.Y +++ b/filter/config.Y @@ -172,7 +172,14 @@ function_params: function_body: decls '{' cmds '}' { - $$ = $3; + if ($1) { + /* Prepend instruction to clear local variables */ + $$ = f_new_inst(); + $$->code = P('c','v'); + $$->a1.p = $1; + $$->next = $3; + } else + $$ = $3; } ; diff --git a/filter/filter.c b/filter/filter.c index ec155ee..de7a97b 100644 --- a/filter/filter.c +++ b/filter/filter.c @@ -473,27 +473,10 @@ interpret(struct f_inst *what) case 's': ARG(v2, a2.p); sym = what->a1.p; - switch (res.type = v2.type) { - case T_VOID: runtime( "Can't assign void values" ); - case T_ENUM: - case T_BOOL: - case T_INT: - case T_PAIR: - case T_STRING: - case T_IP: - case T_PREFIX: - case T_PREFIX_SET: - case T_SET: - case T_PATH: - case T_PATH_MASK: - case T_CLIST: - if (sym->class != (SYM_VARIABLE | v2.type)) - runtime( "Assigning to variable of incompatible type" ); - * (struct f_val *) sym->def = v2; - break; - default: - bug( "Set to invalid type" ); - } + if ((sym->class != (SYM_VARIABLE | v2.type)) && + (v2.type != T_VOID)) + runtime( "Assigning to variable of incompatible type" ); + * (struct f_val *) sym->def = v2; break; /* some constants have value in a2, some in *a1.p, strange. */ @@ -605,42 +588,39 @@ interpret(struct f_inst *what) e = ea_find( (*f_tmp_attrs), what->a2.i ); if ((!e) && (f_flags & FF_FORCE_TMPATTR)) e = ea_find( (*f_rte)->attrs->eattrs, what->a2.i ); - + + if (!e) { + /* Undefined value */ + res.type = T_VOID; + break; + } + switch (what->aux & EAF_TYPE_MASK) { case EAF_TYPE_INT: - if (!e) { - res.type = T_VOID; - break; - } + case EAF_TYPE_ROUTER_ID: res.type = T_INT; res.val.i = e->u.data; break; + case EAF_TYPE_OPAQUE: + res.type = T_ENUM_EMPTY; + res.val.i = 0; + break; case EAF_TYPE_IP_ADDRESS: - if (!e) { - res.type = T_VOID; - break; - } res.type = T_IP; struct adata * ad = e->u.ptr; res.val.px.ip = * (ip_addr *) ad->data; break; case EAF_TYPE_AS_PATH: - if (!e) { - res.type = T_VOID; - break; - } res.type = T_PATH; res.val.ad = e->u.ptr; break; case EAF_TYPE_INT_SET: - if (!e) { - res.type = T_CLIST; - res.val.ad = adata_empty(f_pool); - break; - } res.type = T_CLIST; res.val.ad = e->u.ptr; break; + case EAF_TYPE_UNDEF: + res.type = T_VOID; + break; default: bug("Unknown type in e,a"); } @@ -659,10 +639,14 @@ interpret(struct f_inst *what) l->attrs[0].type = what->aux | EAF_ORIGINATED; switch (what->aux & EAF_TYPE_MASK) { case EAF_TYPE_INT: + case EAF_TYPE_ROUTER_ID: if (v1.type != T_INT) runtime( "Setting int attribute to non-int value" ); l->attrs[0].u.data = v1.val.i; break; + case EAF_TYPE_OPAQUE: + runtime( "Setting opaque attribute is not allowed" ); + break; case EAF_TYPE_IP_ADDRESS: if (v1.type != T_IP) runtime( "Setting ip attribute to non-ip value" ); @@ -765,6 +749,10 @@ interpret(struct f_inst *what) return res; res.type &= ~T_RETURN; break; + case P('c','v'): /* Clear local variables */ + for (sym = what->a1.p; sym != NULL; sym = sym->aux2) + ((struct f_val *) sym->def)->type = T_VOID; + break; case P('S','W'): ONEARG; { @@ -814,7 +802,11 @@ interpret(struct f_inst *what) case P('C','a'): /* Community list add or delete */ TWOARGS; - if (v1.type != T_CLIST) + + /* Replace undefined value with empty community list */ + if (v1.type == T_VOID) + v1.val.ad = adata_empty(f_pool); + else if (v1.type != T_CLIST) runtime("Can't add/delete to non-clist"); if (v2.type != T_PAIR) runtime("Can't add/delete non-pair"); @@ -943,6 +935,7 @@ i_same(struct f_inst *f1, struct f_inst *f2) return 0; f2->a2.p = f1->a2.p; break; + case P('c','v'): break; /* internal instruction */ case P('S','W'): ONEARG; if (!same_tree(f1->a2.p, f2->a2.p)) return 0; break; case P('i','M'): TWOARGS; break; case P('A','p'): TWOARGS; break; diff --git a/filter/test.conf b/filter/test.conf index 395699b..8eeb5c3 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -75,7 +75,7 @@ clist l; p2 = prepend( p2, 1 ); print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1; - l = - empty -; +# l = - empty -; l = add( l, (1,2) ); l = add( l, (2,3) ); print "Community list (1,2) (2,3) ", l; @@ -124,6 +124,14 @@ function test_pxset(prefix set pxs) 11.0.0.0/10 ~ pxs, ",", 20.1.0.0/26 ~ pxs; } +function test_undef(int a) +int b; +{ + if a = 3 + then b = 4; + print "Defined: ", a, " ", b, " ", defined(b); +} + function __startup() int i; bool b; @@ -218,6 +226,10 @@ string s; print "1.2.3.4 = ", onetwo; + test_undef(2); + test_undef(3); + test_undef(2); + print "done"; quitbird; # print "*** FAIL: this is unreachable"; |