1999-01-16 00:49:17 +08:00
|
|
|
/*
|
|
|
|
* BIRD - filters
|
|
|
|
*
|
|
|
|
* Copyright 1998 Pavel Machek
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CF_HDR
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "lib/resource.h"
|
|
|
|
#include "lib/socket.h"
|
|
|
|
#include "lib/timer.h"
|
|
|
|
#include "nest/protocol.h"
|
|
|
|
#include "nest/iface.h"
|
|
|
|
#include "nest/route.h"
|
|
|
|
|
|
|
|
CF_DECLS
|
|
|
|
|
1999-03-17 18:19:07 +08:00
|
|
|
CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT, CONST, VAR, PUTS, IF,
|
|
|
|
ACCEPT, REJECT, ERROR, QUITBIRD)
|
1999-01-16 00:49:17 +08:00
|
|
|
|
1999-01-16 02:04:28 +08:00
|
|
|
%type <x> term
|
1999-03-09 22:45:27 +08:00
|
|
|
%type <x> block
|
1999-03-03 03:49:28 +08:00
|
|
|
%type <x> cmds
|
1999-03-17 22:29:39 +08:00
|
|
|
%type <f> filter filter_body
|
1999-01-16 00:49:17 +08:00
|
|
|
|
|
|
|
CF_GRAMMAR
|
|
|
|
|
|
|
|
CF_ADDTO(conf, function)
|
|
|
|
function:
|
1999-03-03 03:49:28 +08:00
|
|
|
FUNCTION SYM '(' ')' '{' cmds '}' {
|
1999-03-17 18:19:07 +08:00
|
|
|
extern struct f_inst *autoexec_func;
|
1999-01-16 00:49:17 +08:00
|
|
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
|
|
|
$2->class = SYM_FUNCTION;
|
1999-03-03 03:49:28 +08:00
|
|
|
$2->def = $6;
|
1999-03-17 18:19:07 +08:00
|
|
|
if (!strcasecmp($2->name, "autoexec"))
|
|
|
|
autoexec_func = $6;
|
1999-01-16 00:49:17 +08:00
|
|
|
printf("Hmm, we've got one function here\n");
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1999-03-17 22:29:39 +08:00
|
|
|
CF_ADDTO(conf, filter_def)
|
|
|
|
filter_def:
|
|
|
|
FILTER SYM filter_body {
|
1999-01-16 00:49:17 +08:00
|
|
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
|
|
|
$2->class = SYM_FILTER;
|
1999-03-17 22:29:39 +08:00
|
|
|
$2->def = $3;
|
|
|
|
$3->name = $2->name;
|
1999-01-16 00:49:17 +08:00
|
|
|
printf( "We have new filter defined (%s)\n", $2->name )
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1999-03-17 22:29:39 +08:00
|
|
|
filter_body:
|
|
|
|
'{' cmds '}' {
|
|
|
|
struct filter *f = cfg_alloc(sizeof(struct filter));
|
|
|
|
f->name = NULL;
|
|
|
|
f->root = $2;
|
|
|
|
$$ = f;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
filter:
|
|
|
|
SYM {
|
|
|
|
if ($1->class != SYM_FILTER) cf_error("No such filter");
|
|
|
|
$$ = $1->def;
|
|
|
|
}
|
|
|
|
| filter_body
|
|
|
|
;
|
|
|
|
|
1999-01-16 00:49:17 +08:00
|
|
|
/* Programs */
|
|
|
|
|
1999-03-03 03:49:28 +08:00
|
|
|
cmds:
|
|
|
|
term {
|
|
|
|
if ($1) {
|
|
|
|
$1->next = NULL;
|
|
|
|
$$ = $1;
|
|
|
|
} else $$ = NULL;
|
|
|
|
}
|
|
|
|
| term ';' cmds {
|
|
|
|
if ($1) {
|
|
|
|
$1->next = $3;
|
|
|
|
$$ = $1;
|
|
|
|
} else $$ = $3;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1999-03-09 22:45:27 +08:00
|
|
|
block:
|
|
|
|
term ';' {
|
|
|
|
$$=$1;
|
|
|
|
}
|
|
|
|
| '{' cmds '}' {
|
|
|
|
$$=$2;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
1999-03-03 03:49:28 +08:00
|
|
|
term:
|
|
|
|
/* EMPTY */ {
|
|
|
|
$$ = NULL;
|
1999-01-16 00:49:17 +08:00
|
|
|
}
|
1999-03-09 04:30:06 +08:00
|
|
|
| term '+' term {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = '+';
|
|
|
|
$$->arg1 = $1;
|
|
|
|
$$->arg2 = $3;
|
|
|
|
}
|
1999-03-09 22:45:27 +08:00
|
|
|
| IF '(' term ')' block {
|
1999-03-09 04:30:06 +08:00
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = '?';
|
|
|
|
$$->arg1 = $3;
|
|
|
|
$$->arg2 = $5;
|
|
|
|
}
|
1999-02-03 20:28:16 +08:00
|
|
|
| INT SYM {
|
1999-01-16 00:49:17 +08:00
|
|
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined, can not use as variable\n" );
|
|
|
|
$2->class = SYM_VARIABLE_INT;
|
|
|
|
printf( "New variable\n" );
|
|
|
|
$$ = NULL;
|
|
|
|
}
|
1999-03-09 22:45:27 +08:00
|
|
|
| SYM {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
switch ($1->class) {
|
|
|
|
case SYM_VARIABLE_INT:
|
|
|
|
$$->code = 'i';
|
|
|
|
$$->arg1 = &($1->aux);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cf_error("Can not use this class of symbol as variable" );
|
|
|
|
}
|
|
|
|
}
|
1999-03-09 04:30:06 +08:00
|
|
|
| VAR '(' SYM ')' {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
switch ($3->class) {
|
|
|
|
case SYM_VARIABLE_INT:
|
|
|
|
$$->code = 'i';
|
|
|
|
$$->arg1 = &($3->aux);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cf_error("Can not use this class of symbol as variable" );
|
|
|
|
}
|
|
|
|
}
|
1999-03-09 22:45:27 +08:00
|
|
|
| NUM {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = 'c';
|
|
|
|
$$->arg1 = $1
|
|
|
|
}
|
1999-03-09 04:30:06 +08:00
|
|
|
| CONST '(' expr ')' {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = 'c';
|
|
|
|
$$->arg1 = $3;
|
|
|
|
}
|
|
|
|
| SYM '=' term {
|
1999-03-03 03:49:28 +08:00
|
|
|
$$ = f_new_inst();
|
1999-01-16 00:49:17 +08:00
|
|
|
printf( "Ook, we'll set value\n" );
|
|
|
|
if ($1->class != SYM_VARIABLE_INT)
|
|
|
|
cf_error( "You may only set variables\n" );
|
|
|
|
$$->code = '=';
|
|
|
|
$$->arg1 = $1;
|
|
|
|
$$->arg2 = $3;
|
|
|
|
}
|
1999-03-09 04:30:06 +08:00
|
|
|
| PRINT '(' term ')' {
|
1999-03-03 03:49:28 +08:00
|
|
|
$$ = f_new_inst();
|
1999-01-16 00:49:17 +08:00
|
|
|
printf( "Ook, we'll print something\n" );
|
|
|
|
$$->code = 'p';
|
|
|
|
$$->arg1 = $3;
|
|
|
|
$$->arg2 = NULL;
|
|
|
|
}
|
1999-03-09 04:30:06 +08:00
|
|
|
| PUTS '(' TEXT ')' {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = 'd';
|
|
|
|
$$->arg1 = $3;
|
|
|
|
}
|
1999-03-17 18:19:07 +08:00
|
|
|
| QUITBIRD {
|
1999-03-09 04:30:06 +08:00
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = '!';
|
1999-03-17 18:19:07 +08:00
|
|
|
(int) $$->arg1 = F_QUITBIRD;
|
|
|
|
}
|
|
|
|
| ACCEPT {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = '!';
|
|
|
|
(int) $$->arg1 = F_ACCEPT;
|
|
|
|
}
|
|
|
|
| REJECT {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = '!';
|
|
|
|
(int) $$->arg1 = F_REJECT;
|
|
|
|
}
|
|
|
|
| ERROR {
|
|
|
|
$$ = f_new_inst();
|
|
|
|
$$->code = '!';
|
|
|
|
(int) $$->arg1 = F_ERROR;
|
1999-03-09 04:30:06 +08:00
|
|
|
}
|
1999-01-16 00:49:17 +08:00
|
|
|
| PRINTDEBUG {
|
1999-03-03 03:49:28 +08:00
|
|
|
$$ = f_new_inst();
|
1999-01-16 00:49:17 +08:00
|
|
|
$$->code = 'D';
|
|
|
|
$$->arg1 = $$->arg2 = NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
|
|
|
|
CF_END
|