1999-01-15 16:49:17 +00:00
|
|
|
/*
|
|
|
|
* Filters: utility functions
|
|
|
|
*
|
|
|
|
* Copyright 1998 Pavel Machek <pavel@ucw.cz>
|
2022-03-19 15:23:42 +00:00
|
|
|
* 2017 Maria Matejka <mq@ucw.cz>
|
1999-01-15 16:49:17 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2019-02-07 20:25:38 +00:00
|
|
|
#include "filter/f-inst.h"
|
2018-11-21 19:37:11 +00:00
|
|
|
#include "lib/idm.h"
|
|
|
|
#include "nest/protocol.h"
|
2022-03-31 17:09:38 +00:00
|
|
|
#include "nest/rt.h"
|
1999-01-15 16:49:17 +00:00
|
|
|
|
2000-04-20 10:25:51 +00:00
|
|
|
#define P(a,b) ((a<<8) | b)
|
|
|
|
|
2019-02-15 12:53:17 +00:00
|
|
|
const char *
|
|
|
|
filter_name(const struct filter *filter)
|
1999-04-05 20:10:31 +00:00
|
|
|
{
|
|
|
|
if (!filter)
|
|
|
|
return "ACCEPT";
|
|
|
|
else if (filter == FILTER_REJECT)
|
|
|
|
return "REJECT";
|
2019-02-26 15:44:24 +00:00
|
|
|
else if (!filter->sym)
|
2012-03-15 11:50:49 +00:00
|
|
|
return "(unnamed)";
|
1999-04-05 20:10:31 +00:00
|
|
|
else
|
2019-02-26 15:44:24 +00:00
|
|
|
return filter->sym->name;
|
1999-04-05 20:10:31 +00:00
|
|
|
}
|
2018-11-21 19:37:11 +00:00
|
|
|
|
2019-06-28 09:08:48 +00:00
|
|
|
struct filter *f_new_where(struct f_inst *where)
|
2019-01-21 08:17:54 +00:00
|
|
|
{
|
2019-09-10 11:45:18 +00:00
|
|
|
struct f_inst *cond = f_new_inst(FI_CONDITION, where,
|
|
|
|
f_new_inst(FI_DIE, F_ACCEPT),
|
|
|
|
f_new_inst(FI_DIE, F_REJECT));
|
2019-01-21 08:17:54 +00:00
|
|
|
|
2019-02-26 15:44:24 +00:00
|
|
|
struct filter *f = cfg_allocz(sizeof(struct filter));
|
2019-09-10 11:45:18 +00:00
|
|
|
f->root = f_linearize(cond);
|
2019-01-21 08:17:54 +00:00
|
|
|
return f;
|
|
|
|
}
|