1999-01-16 00:49:17 +08:00
|
|
|
/*
|
|
|
|
* Filters: utility functions
|
|
|
|
*
|
|
|
|
* Copyright 1998 Pavel Machek <pavel@ucw.cz>
|
|
|
|
*
|
|
|
|
* Can be freely distributed and used under the terms of the GNU GPL.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "nest/bird.h"
|
|
|
|
#include "conf/conf.h"
|
|
|
|
#include "filter/filter.h"
|
|
|
|
|
2000-04-20 18:25:51 +08:00
|
|
|
#define P(a,b) ((a<<8) | b)
|
|
|
|
|
1999-03-09 04:30:06 +08:00
|
|
|
struct f_inst *
|
1999-03-03 03:49:28 +08:00
|
|
|
f_new_inst(void)
|
|
|
|
{
|
1999-03-09 04:30:06 +08:00
|
|
|
struct f_inst * ret;
|
|
|
|
ret = cfg_alloc(sizeof(struct f_inst));
|
1999-11-18 22:01:36 +08:00
|
|
|
ret->code = ret->aux = 0;
|
1999-03-03 03:49:28 +08:00
|
|
|
ret->arg1 = ret->arg2 = ret->next = NULL;
|
2000-05-17 02:50:51 +08:00
|
|
|
ret->lineno = conf_lino;
|
1999-03-03 03:49:28 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-03-01 19:32:23 +08:00
|
|
|
struct f_inst *
|
2000-04-12 22:02:04 +08:00
|
|
|
f_new_dynamic_attr(int type, int f_type, int code)
|
2000-03-01 19:32:23 +08:00
|
|
|
{
|
|
|
|
struct f_inst *f = f_new_inst();
|
2000-04-17 22:12:02 +08:00
|
|
|
f->aux = type;
|
2000-03-01 19:32:23 +08:00
|
|
|
f->a2.i = code;
|
|
|
|
return f;
|
|
|
|
}
|
|
|
|
|
2000-04-20 18:25:51 +08:00
|
|
|
/*
|
|
|
|
* Generate set_dynamic( operation( get_dynamic(), argument ) )
|
|
|
|
*/
|
|
|
|
struct f_inst *
|
|
|
|
f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument)
|
|
|
|
{
|
|
|
|
struct f_inst *set_dyn = f_new_inst(),
|
|
|
|
*oper = f_new_inst(),
|
|
|
|
*get_dyn = dyn;
|
|
|
|
|
|
|
|
*set_dyn = *get_dyn;
|
|
|
|
get_dyn->code = P('e','a');
|
|
|
|
oper->code = operation;
|
|
|
|
oper->aux = operation_aux;
|
|
|
|
oper->a1.p = get_dyn;
|
|
|
|
oper->a2.p = argument;
|
|
|
|
set_dyn->code = P('e','S');
|
|
|
|
set_dyn->a1.p = oper;
|
|
|
|
return set_dyn;
|
|
|
|
}
|
|
|
|
|
1999-04-06 04:10:31 +08:00
|
|
|
char *
|
|
|
|
filter_name(struct filter *filter)
|
|
|
|
{
|
|
|
|
if (!filter)
|
|
|
|
return "ACCEPT";
|
|
|
|
else if (filter == FILTER_REJECT)
|
|
|
|
return "REJECT";
|
|
|
|
else
|
|
|
|
return filter->name;
|
|
|
|
}
|