1999-01-15 16:49:17 +00:00
|
|
|
/*
|
|
|
|
* Filters: utility functions
|
|
|
|
*
|
|
|
|
* Copyright 1998 Pavel Machek <pavel@ucw.cz>
|
2017-10-19 10:39:44 +00:00
|
|
|
* 2017 Jan 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"
|
2018-08-13 09:41:27 +00:00
|
|
|
#include "conf/parser.h"
|
1999-01-15 16:49:17 +00:00
|
|
|
#include "filter/filter.h"
|
2018-08-13 09:41:27 +00:00
|
|
|
#include "filter/f-util.h"
|
1999-01-15 16:49:17 +00:00
|
|
|
|
2000-04-20 10:25:51 +00:00
|
|
|
#define P(a,b) ((a<<8) | b)
|
|
|
|
|
1999-03-08 20:30:06 +00:00
|
|
|
struct f_inst *
|
2018-08-13 09:41:27 +00:00
|
|
|
f_new_inst(struct cf_context *ctx, enum f_instruction_code fi_code)
|
1999-03-02 19:49:28 +00:00
|
|
|
{
|
1999-03-08 20:30:06 +00:00
|
|
|
struct f_inst * ret;
|
2017-10-19 10:39:44 +00:00
|
|
|
ret = cfg_allocz(sizeof(struct f_inst));
|
|
|
|
ret->fi_code = fi_code;
|
2018-08-13 09:41:27 +00:00
|
|
|
ret->lineno = ctx->order->state->lino;
|
1999-03-02 19:49:28 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2000-03-01 11:32:23 +00:00
|
|
|
struct f_inst *
|
2018-08-13 09:41:27 +00:00
|
|
|
f_new_inst_da(struct cf_context *ctx, enum f_instruction_code fi_code, struct f_dynamic_attr da)
|
2000-03-01 11:32:23 +00:00
|
|
|
{
|
2018-08-13 09:41:27 +00:00
|
|
|
struct f_inst *ret = f_new_inst(ctx, fi_code);
|
2018-03-13 15:51:04 +00:00
|
|
|
ret->aux = (da.f_type << 8) | da.type;
|
2017-10-19 10:39:44 +00:00
|
|
|
ret->a2.i = da.ea_code;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct f_inst *
|
2018-08-13 09:41:27 +00:00
|
|
|
f_new_inst_sa(struct cf_context *ctx, enum f_instruction_code fi_code, struct f_static_attr sa)
|
2017-10-19 10:39:44 +00:00
|
|
|
{
|
2018-08-13 09:41:27 +00:00
|
|
|
struct f_inst *ret = f_new_inst(ctx, fi_code);
|
2017-10-19 10:39:44 +00:00
|
|
|
ret->aux = sa.f_type;
|
|
|
|
ret->a2.i = sa.sa_code;
|
|
|
|
ret->a1.i = sa.readonly;
|
|
|
|
return ret;
|
2000-03-01 11:32:23 +00:00
|
|
|
}
|
|
|
|
|
2000-04-20 10:25:51 +00:00
|
|
|
/*
|
|
|
|
* Generate set_dynamic( operation( get_dynamic(), argument ) )
|
|
|
|
*/
|
|
|
|
struct f_inst *
|
2018-08-13 09:41:27 +00:00
|
|
|
f_generate_complex(struct cf_context *ctx, int operation, int operation_aux, struct f_dynamic_attr da, struct f_inst *argument)
|
2000-04-20 10:25:51 +00:00
|
|
|
{
|
2018-08-13 09:41:27 +00:00
|
|
|
struct f_inst *set_dyn = f_new_inst_da(ctx, FI_EA_SET, da),
|
|
|
|
*oper = f_new_inst(ctx, operation),
|
|
|
|
*get_dyn = f_new_inst_da(ctx, FI_EA_GET, da);
|
2000-04-20 10:25:51 +00:00
|
|
|
|
|
|
|
oper->aux = operation_aux;
|
|
|
|
oper->a1.p = get_dyn;
|
|
|
|
oper->a2.p = argument;
|
2017-10-19 10:39:44 +00:00
|
|
|
|
2000-04-20 10:25:51 +00:00
|
|
|
set_dyn->a1.p = oper;
|
|
|
|
return set_dyn;
|
|
|
|
}
|
|
|
|
|
2012-03-18 16:32:30 +00:00
|
|
|
struct f_inst *
|
2018-08-13 09:41:27 +00:00
|
|
|
f_generate_roa_check(struct cf_context *ctx, struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn)
|
2012-03-18 16:32:30 +00:00
|
|
|
{
|
|
|
|
struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check));
|
2017-10-19 10:39:44 +00:00
|
|
|
ret->i.fi_code = FI_ROA_CHECK;
|
2018-08-13 09:41:27 +00:00
|
|
|
ret->i.lineno = ctx->order->state->lino;
|
2012-03-18 16:32:30 +00:00
|
|
|
ret->i.arg1 = prefix;
|
|
|
|
ret->i.arg2 = asn;
|
|
|
|
/* prefix == NULL <-> asn == NULL */
|
|
|
|
|
2016-01-20 14:38:37 +00:00
|
|
|
if (table->addr_type != NET_ROA4 && table->addr_type != NET_ROA6)
|
2018-08-13 09:41:27 +00:00
|
|
|
cf_error(ctx, "%s is not a ROA table", table->name);
|
2016-01-20 14:38:37 +00:00
|
|
|
ret->rtc = table;
|
2012-03-18 16:32:30 +00:00
|
|
|
|
|
|
|
return &ret->i;
|
|
|
|
}
|
|
|
|
|
2018-04-30 10:49:22 +00:00
|
|
|
static const char * const f_instruction_name_str[] = {
|
|
|
|
#define F(c,a,b) \
|
|
|
|
[c] = #c,
|
|
|
|
FI__LIST
|
|
|
|
#undef F
|
|
|
|
};
|
|
|
|
|
|
|
|
const char *
|
|
|
|
f_instruction_name(enum f_instruction_code fi)
|
|
|
|
{
|
|
|
|
if (fi < FI__MAX)
|
|
|
|
return f_instruction_name_str[fi];
|
|
|
|
else
|
|
|
|
bug("Got unknown instruction code: %d", fi);
|
|
|
|
}
|
|
|
|
|
1999-04-05 20:10:31 +00:00
|
|
|
char *
|
|
|
|
filter_name(struct filter *filter)
|
|
|
|
{
|
|
|
|
if (!filter)
|
|
|
|
return "ACCEPT";
|
|
|
|
else if (filter == FILTER_REJECT)
|
|
|
|
return "REJECT";
|
2012-03-15 11:50:49 +00:00
|
|
|
else if (!filter->name)
|
|
|
|
return "(unnamed)";
|
1999-04-05 20:10:31 +00:00
|
|
|
else
|
|
|
|
return filter->name;
|
|
|
|
}
|