mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-11-08 12:18:42 +00:00
A couple of filter tweaks:
o Introduced struct filter which serves as an external reference to filter. Using struct symbol for this is unwise since it doesn't allow extra information attached to the filter and it also forces all filters to be named. o Implemented config rule 'filter' which matches either named filter or an embedded unnamed filter (`{ <filter> }'). o Fixed totally bogus comment at the top of filter.h. o Added a missing prototype for f_run() to filter.h.
This commit is contained in:
parent
c612a3be31
commit
e0f2e42f4f
@ -25,7 +25,8 @@ CF_DECLS
|
|||||||
ip_addr a;
|
ip_addr a;
|
||||||
struct symbol *s;
|
struct symbol *s;
|
||||||
char *t;
|
char *t;
|
||||||
struct f_inst *x;
|
struct f_inst *x;
|
||||||
|
struct filter *f;
|
||||||
}
|
}
|
||||||
|
|
||||||
%token END
|
%token END
|
||||||
|
@ -9,7 +9,6 @@
|
|||||||
CF_HDR
|
CF_HDR
|
||||||
|
|
||||||
#include "nest/bird.h"
|
#include "nest/bird.h"
|
||||||
#include "filter/filter.h"
|
|
||||||
#include "lib/resource.h"
|
#include "lib/resource.h"
|
||||||
#include "lib/socket.h"
|
#include "lib/socket.h"
|
||||||
#include "lib/timer.h"
|
#include "lib/timer.h"
|
||||||
@ -25,6 +24,7 @@ CF_KEYWORDS(FUNCTION, FILTER, PRINTDEBUG, INT, PRINT, CONST, VAR, PUTS, IF,
|
|||||||
%type <x> term
|
%type <x> term
|
||||||
%type <x> block
|
%type <x> block
|
||||||
%type <x> cmds
|
%type <x> cmds
|
||||||
|
%type <f> filter filter_body
|
||||||
|
|
||||||
CF_GRAMMAR
|
CF_GRAMMAR
|
||||||
|
|
||||||
@ -41,16 +41,34 @@ function:
|
|||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
CF_ADDTO(conf, filter)
|
CF_ADDTO(conf, filter_def)
|
||||||
filter:
|
filter_def:
|
||||||
FILTER SYM '{' cmds '}' {
|
FILTER SYM filter_body {
|
||||||
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
if ($2->class != SYM_VOID) cf_error("Symbol already defined" );
|
||||||
$2->class = SYM_FILTER;
|
$2->class = SYM_FILTER;
|
||||||
$2->def = $4;
|
$2->def = $3;
|
||||||
|
$3->name = $2->name;
|
||||||
printf( "We have new filter defined (%s)\n", $2->name )
|
printf( "We have new filter defined (%s)\n", $2->name )
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
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
|
||||||
|
;
|
||||||
|
|
||||||
/* Programs */
|
/* Programs */
|
||||||
|
|
||||||
cmds:
|
cmds:
|
||||||
|
@ -146,13 +146,13 @@ f_new_inst(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
f_run(struct symbol *filter, struct rte *rtein, struct rte **rteout)
|
f_run(struct filter *filter, struct rte *rtein, struct rte **rteout)
|
||||||
{
|
{
|
||||||
struct f_inst *inst;
|
struct f_inst *inst;
|
||||||
struct f_val res;
|
struct f_val res;
|
||||||
debug( "Running filter `%s'...", filter->name );
|
debug( "Running filter `%s'...", filter->name );
|
||||||
|
|
||||||
inst = filter->def;
|
inst = filter->root;
|
||||||
res = interpret(inst);
|
res = interpret(inst);
|
||||||
if (res.type != T_RETURN)
|
if (res.type != T_RETURN)
|
||||||
return F_ERROR;
|
return F_ERROR;
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* BIRD Internet Routing Daemon -- Configuration File Handling
|
* BIRD Internet Routing Daemon -- Filters
|
||||||
*
|
*
|
||||||
* (c) 1998 Martin Mares <mj@ucw.cz>
|
* (c) 1999 Pavel Machek <pavel@ucw.cz>
|
||||||
*
|
*
|
||||||
* Can be freely distributed and used under the terms of the GNU GPL.
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
||||||
*/
|
*/
|
||||||
@ -24,9 +24,16 @@ struct f_val {
|
|||||||
} val;
|
} val;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct filter {
|
||||||
|
char *name;
|
||||||
|
struct f_inst *root;
|
||||||
|
};
|
||||||
|
|
||||||
void filters_postconfig(void);
|
void filters_postconfig(void);
|
||||||
struct f_inst *f_new_inst(void);
|
struct f_inst *f_new_inst(void);
|
||||||
|
|
||||||
|
int f_run(struct filter *filter, struct rte *rtein, struct rte **rteout);
|
||||||
|
|
||||||
#define F_ACCEPT 1
|
#define F_ACCEPT 1
|
||||||
#define F_REJECT 2
|
#define F_REJECT 2
|
||||||
#define F_MODIFY 3
|
#define F_MODIFY 3
|
||||||
@ -39,5 +46,4 @@ struct f_inst *f_new_inst(void);
|
|||||||
#define T_PX 11 /* prefix */
|
#define T_PX 11 /* prefix */
|
||||||
#define T_INTLIST 12
|
#define T_INTLIST 12
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user