0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-12-22 09:41:54 +00:00

Filters added. They are unable to do anything interesting for now

(with exception of printing integers to screen), but they exist.
This commit is contained in:
Pavel Machek 1999-01-15 14:41:51 +00:00
parent 41183888ee
commit 72380a3447
4 changed files with 22 additions and 13 deletions

View File

@ -1,10 +1,10 @@
source=cf-parse.tab.c cf-lex.c source=cf-parse.tab.c cf-lex.c f-util.c
root-rel=../ root-rel=../
include ../Rules include ../Rules
conf-src=$(srcdir)/conf conf-src=$(srcdir)/conf
conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths)) conf-fragments=$(conf-src)/confbase.Y @CONFS@ $(addsuffix /config.Y,$(static-dir-paths)) $(conf-src)/filter.Y
ifdef DEBUG ifdef DEBUG
BISON_DEBUG=-t BISON_DEBUG=-t

View File

@ -245,6 +245,7 @@ cf_allocate(void)
cfg_mem = lp_new(cfg_pool, 1024); cfg_mem = lp_new(cfg_pool, 1024);
} }
#if 1
char * char *
cfg_strdup(char *c) cfg_strdup(char *c)
{ {
@ -253,4 +254,5 @@ cfg_strdup(char *c)
memcpy(z, c, l); memcpy(z, c, l);
return z; return z;
} }
#endif

View File

@ -36,6 +36,10 @@ struct symbol {
#define SYM_VOID 0 #define SYM_VOID 0
#define SYM_PROTO 1 #define SYM_PROTO 1
#define SYM_NUMBER 2 #define SYM_NUMBER 2
#define SYM_STAT 3 /* statement */
#define SYM_VARIABLE_INT 4
#define SYM_FUNCTION 5
#define SYM_FILTER 6
void cf_lex_init_tables(void); void cf_lex_init_tables(void);
int cf_lex(void); int cf_lex(void);

View File

@ -16,6 +16,7 @@ CF_HDR
#include "nest/protocol.h" #include "nest/protocol.h"
#include "nest/iface.h" #include "nest/iface.h"
#include "nest/route.h" #include "nest/route.h"
#include "conf/filter.h"
CF_DECLS CF_DECLS
@ -24,6 +25,7 @@ CF_DECLS
ip_addr a; ip_addr a;
struct symbol *s; struct symbol *s;
char *t; char *t;
struct f_instruction *x;
} }
%token END %token END
@ -32,7 +34,8 @@ CF_DECLS
%token <s> SYM %token <s> SYM
%token <t> TEXT %token <t> TEXT
%type <i> expr bool pxlen %type <i> cexpr bool pxlen
%type <x> expr
%left '+' '-' %left '+' '-'
%left '*' '/' '%' %left '*' '/' '%'
@ -55,22 +58,22 @@ conf_entries:
CF_ADDTO(conf, /* EMPTY */) CF_ADDTO(conf, /* EMPTY */)
/* Expressions */ /* Constant expressions */
expr: cexpr:
NUM NUM
| expr '+' expr { $$ = $1 + $3; } | cexpr '+' cexpr { $$ = $1 + $3; }
| expr '-' expr { $$ = $1 - $3; } | cexpr '-' cexpr { $$ = $1 - $3; }
| expr '*' expr { $$ = $1 * $3; } | cexpr '*' cexpr { $$ = $1 * $3; }
| expr '/' expr { if ($3) $$ = $1 / $3; else cf_error("Division by zero"); } | cexpr '/' cexpr { if ($3) $$ = $1 / $3; else cf_error("Division by zero"); }
| expr '%' expr { if ($3) $$ = $1 % $3; else cf_error("Division by zero"); } | cexpr '%' cexpr { if ($3) $$ = $1 % $3; else cf_error("Division by zero"); }
| '(' expr ')' { $$ = $2; } | '(' cexpr ')' { $$ = $2; }
| SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; } | SYM { if ($1->class != SYM_NUMBER) cf_error("Number expected"); else $$ = $1->aux; }
; ;
CF_ADDTO(conf, definition) CF_ADDTO(conf, definition)
definition: definition:
DEFINE SYM '=' expr { DEFINE SYM '=' cexpr {
if ($2->class != SYM_VOID) cf_error("Symbol already defined"); if ($2->class != SYM_VOID) cf_error("Symbol already defined");
$2->class = SYM_NUMBER; $2->class = SYM_NUMBER;
$2->aux = $4; $2->aux = $4;
@ -80,7 +83,7 @@ definition:
/* Switches */ /* Switches */
bool: bool:
expr {$$ = !!$1; } cexpr {$$ = !!$1; }
| ON { $$ = 1; } | ON { $$ = 1; }
| YES { $$ = 1; } | YES { $$ = 1; }
| OFF { $$ = 0; } | OFF { $$ = 0; }