mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Split inst->code into inst->code and inst->aux. Both are only 16 bit,
so aux is suitable for storing type but not much more.
This commit is contained in:
parent
da40b6f753
commit
c7b43f33ae
@ -10,6 +10,7 @@
|
|||||||
FIXME: create community lists
|
FIXME: create community lists
|
||||||
FIXME: write access to dynamic attributes.
|
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: '! =' 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:
|
constant:
|
||||||
CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $3; }
|
CONST '(' expr ')' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $3; }
|
||||||
| NUM { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_INT; $$->a2.i = $1; }
|
| NUM { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_INT; $$->a2.i = $1; }
|
||||||
| TRUE { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_BOOL; $$->a2.i = 1; }
|
| TRUE { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 1; }
|
||||||
| FALSE { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_BOOL; $$->a2.i = 0; }
|
| FALSE { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 0; }
|
||||||
| TEXT { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_STRING; $$->a2.p = $1; }
|
| TEXT { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_STRING; $$->a2.p = $1; }
|
||||||
| pair { $$ = f_new_inst(); $$->code = 'c'; $$->a1.i = T_PAIR; $$->a2.i = $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; }
|
| 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; }
|
| 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" ); }
|
| '[' 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'; $$->a1.i = $1 >> 16; $$->a2.i = $1 & 0xffff; }
|
| ENUM { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
|
||||||
;
|
;
|
||||||
|
|
||||||
any_dynamic:
|
any_dynamic:
|
||||||
RIP_METRIC { $$ = f_new_inst(); $$->a1.i = T_INT; $$->a2.i = EA_RIP_METRIC;}
|
RIP_METRIC { $$ = f_new_inst(); $$->aux = T_INT; $$->a2.i = EA_RIP_METRIC;}
|
||||||
| RIP_TAG { $$ = f_new_inst(); $$->a1.i = T_INT; $$->a2.i = EA_RIP_TAG; }
|
| RIP_TAG { $$ = f_new_inst(); $$->aux = T_INT; $$->a2.i = EA_RIP_TAG; }
|
||||||
;
|
;
|
||||||
|
|
||||||
|
|
||||||
@ -283,8 +284,8 @@ term:
|
|||||||
|
|
||||||
| RTA '.' any_dynamic { $$ = $3; $$->code = 'ea'; }
|
| RTA '.' any_dynamic { $$ = $3; $$->code = 'ea'; }
|
||||||
|
|
||||||
| term '.' IP { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->a2.i = T_IP; }
|
| term '.' IP { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->aux = T_IP; }
|
||||||
| term '.' LEN { $$ = f_new_inst(); $$->code = 'cp'; $$->a1.p = $1; $$->a2.i = T_INT; }
|
| 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; }
|
| term '.' MASK '(' term ')' { $$ = f_new_inst(); $$->code = 'iM'; $$->a1.p = $1; $$->a2.p = $5; }
|
||||||
;
|
;
|
||||||
|
|
||||||
@ -356,6 +357,11 @@ cmd:
|
|||||||
$$->a1.p = $1;
|
$$->a1.p = $1;
|
||||||
$$->a2.p = $3;
|
$$->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; }
|
| break_command print_list ';' { $$ = f_new_inst(); $$->code = 'p,'; $$->a1.p = $2; $$->a2.i = $1; }
|
||||||
| SYM '(' var_list ')' ';' {
|
| SYM '(' var_list ')' ';' {
|
||||||
struct symbol *sym;
|
struct symbol *sym;
|
||||||
|
@ -27,7 +27,7 @@ f_new_inst(void)
|
|||||||
{
|
{
|
||||||
struct f_inst * ret;
|
struct f_inst * ret;
|
||||||
ret = cfg_alloc(sizeof(struct f_inst));
|
ret = cfg_alloc(sizeof(struct f_inst));
|
||||||
ret->code = 0;
|
ret->code = ret->aux = 0;
|
||||||
ret->arg1 = ret->arg2 = ret->next = NULL;
|
ret->arg1 = ret->arg2 = ret->next = NULL;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,7 @@ interpret(struct f_inst *what)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c': /* integer (or simple type) constant */
|
case 'c': /* integer (or simple type) constant */
|
||||||
res.type = what->a1.i;
|
res.type = what->aux;
|
||||||
res.val.i = what->a2.i;
|
res.val.i = what->a2.i;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
@ -284,7 +284,7 @@ interpret(struct f_inst *what)
|
|||||||
case F_ACCEPT:
|
case F_ACCEPT:
|
||||||
/* Should take care about turning ACCEPT into MODIFY */
|
/* Should take care about turning ACCEPT into MODIFY */
|
||||||
case F_ERROR:
|
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.type = T_RETURN;
|
||||||
res.val.i = what->a1.i;
|
res.val.i = what->a1.i;
|
||||||
break;
|
break;
|
||||||
@ -298,11 +298,14 @@ interpret(struct f_inst *what)
|
|||||||
case 'a': /* rta access */
|
case 'a': /* rta access */
|
||||||
{
|
{
|
||||||
struct rta *rta = (*f_rte)->attrs;
|
struct rta *rta = (*f_rte)->attrs;
|
||||||
res.type = what->a1.i;
|
res.type = what->aux;
|
||||||
switch(res.type) {
|
switch(res.type) {
|
||||||
case T_IP:
|
case T_IP:
|
||||||
res.val.px.ip = * (ip_addr *) ((char *) rta + what->a2.i);
|
res.val.px.ip = * (ip_addr *) ((char *) rta + what->a2.i);
|
||||||
break;
|
break;
|
||||||
|
case T_ENUM:
|
||||||
|
res.val.i = * ((char *) rta + what->a2.i);
|
||||||
|
break;
|
||||||
case T_PREFIX: /* Warning: this works only for prefix of network */
|
case T_PREFIX: /* Warning: this works only for prefix of network */
|
||||||
{
|
{
|
||||||
res.val.px.ip = (*f_rte)->net->n.prefix;
|
res.val.px.ip = (*f_rte)->net->n.prefix;
|
||||||
@ -321,7 +324,7 @@ interpret(struct f_inst *what)
|
|||||||
res.type = T_VOID;
|
res.type = T_VOID;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
res.type = what->a1.i;
|
res.type = what->aux;
|
||||||
switch (what->a1.i) {
|
switch (what->a1.i) {
|
||||||
case T_INT:
|
case T_INT:
|
||||||
res.val.i = e->u.data;
|
res.val.i = e->u.data;
|
||||||
@ -333,7 +336,7 @@ interpret(struct f_inst *what)
|
|||||||
ONEARG;
|
ONEARG;
|
||||||
if (v1.type != T_PREFIX)
|
if (v1.type != T_PREFIX)
|
||||||
runtime( "Can not convert non-prefix this way" );
|
runtime( "Can not convert non-prefix this way" );
|
||||||
res.type = what->a2.i;
|
res.type = what->aux;
|
||||||
switch(res.type) {
|
switch(res.type) {
|
||||||
case T_INT: res.val.i = v1.val.px.len; break;
|
case T_INT: res.val.i = v1.val.px.len; break;
|
||||||
case T_IP: res.val.px.ip = v1.val.px.ip; break;
|
case T_IP: res.val.px.ip = v1.val.px.ip; break;
|
||||||
|
@ -14,7 +14,8 @@
|
|||||||
|
|
||||||
struct f_inst { /* Instruction */
|
struct f_inst { /* Instruction */
|
||||||
struct f_inst *next; /* Structure is 16 bytes, anyway */
|
struct f_inst *next; /* Structure is 16 bytes, anyway */
|
||||||
int code;
|
u16 code;
|
||||||
|
u16 aux;
|
||||||
union {
|
union {
|
||||||
int i;
|
int i;
|
||||||
void *p;
|
void *p;
|
||||||
@ -85,8 +86,9 @@ void val_print(struct f_val v);
|
|||||||
#define T_MASK 0xff
|
#define T_MASK 0xff
|
||||||
|
|
||||||
/* Internal types */
|
/* Internal types */
|
||||||
#define T_VOID 0
|
/* Do not use type of zero, that way we'll see errors easier. */
|
||||||
#define T_RETURN 1
|
#define T_VOID 1
|
||||||
|
#define T_RETURN 2
|
||||||
|
|
||||||
/* User visible types, which fit in int */
|
/* User visible types, which fit in int */
|
||||||
#define T_INT 0x10
|
#define T_INT 0x10
|
||||||
|
@ -66,12 +66,13 @@ ip p;
|
|||||||
filter testf
|
filter testf
|
||||||
int j;
|
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;
|
print "This route was from " rta.from;
|
||||||
j = 7;
|
j = 7;
|
||||||
j = 17;
|
j = 17;
|
||||||
if rta.rip_metric > 15 then
|
if rta.rip_metric > 15 then {
|
||||||
print "RIP Metric is more than infinity";
|
reject "RIP Metric is more than infinity";
|
||||||
|
}
|
||||||
|
|
||||||
accept;
|
accept "ok I take that";
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user