2 * Filters: utility functions
4 * Copyright 1998 Pavel Machek <pavel@ucw.cz>
5 * 2017 Jan Maria Matejka <mq@ucw.cz>
7 * Can be freely distributed and used under the terms of the GNU GPL.
10 #include "nest/bird.h"
11 #include "conf/conf.h"
12 #include "filter/filter.h"
14 #define P(a,b) ((a<<8) | b)
17 f_new_inst(enum f_instruction_code fi_code
)
20 ret
= cfg_allocz(sizeof(struct f_inst
));
21 ret
->fi_code
= fi_code
;
22 ret
->lineno
= ifs
->lino
;
27 f_new_inst_da(enum f_instruction_code fi_code
, struct f_dynamic_attr da
)
29 struct f_inst
*ret
= f_new_inst(fi_code
);
30 ret
->aux
= (da
.f_type
<< 8) | da
.type
;
31 ret
->a2
.i
= da
.ea_code
;
36 f_new_inst_sa(enum f_instruction_code fi_code
, struct f_static_attr sa
)
38 struct f_inst
*ret
= f_new_inst(fi_code
);
40 ret
->a2
.i
= sa
.sa_code
;
41 ret
->a1
.i
= sa
.readonly
;
46 * Generate set_dynamic( operation( get_dynamic(), argument ) )
49 f_generate_complex(int operation
, int operation_aux
, struct f_dynamic_attr da
, struct f_inst
*argument
)
51 struct f_inst
*set_dyn
= f_new_inst_da(FI_EA_SET
, da
),
52 *oper
= f_new_inst(operation
),
53 *get_dyn
= f_new_inst_da(FI_EA_GET
, da
);
55 oper
->aux
= operation_aux
;
57 oper
->a2
.p
= argument
;
64 f_generate_roa_check(struct rtable_config
*table
, struct f_inst
*prefix
, struct f_inst
*asn
)
66 struct f_inst_roa_check
*ret
= cfg_allocz(sizeof(struct f_inst_roa_check
));
67 ret
->i
.fi_code
= FI_ROA_CHECK
;
68 ret
->i
.lineno
= ifs
->lino
;
71 /* prefix == NULL <-> asn == NULL */
73 if (table
->addr_type
!= NET_ROA4
&& table
->addr_type
!= NET_ROA6
)
74 cf_error("%s is not a ROA table", table
->name
);
81 filter_name(struct filter
*filter
)
85 else if (filter
== FILTER_REJECT
)
87 else if (!filter
->name
)