]>
Commit | Line | Data |
---|---|---|
b9d70dc8 PM |
1 | /* |
2 | * Filters: utility functions | |
3 | * | |
4 | * Copyright 1998 Pavel Machek <pavel@ucw.cz> | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
b9d70dc8 | 9 | #include "nest/bird.h" |
b9d70dc8 PM |
10 | #include "conf/conf.h" |
11 | #include "filter/filter.h" | |
12 | ||
7d6eebae PM |
13 | #define P(a,b) ((a<<8) | b) |
14 | ||
b7005824 | 15 | struct f_inst * |
84c7e194 PM |
16 | f_new_inst(void) |
17 | { | |
b7005824 PM |
18 | struct f_inst * ret; |
19 | ret = cfg_alloc(sizeof(struct f_inst)); | |
c7b43f33 | 20 | ret->code = ret->aux = 0; |
84c7e194 | 21 | ret->arg1 = ret->arg2 = ret->next = NULL; |
4be266a9 | 22 | ret->lineno = ifs->lino; |
84c7e194 PM |
23 | return ret; |
24 | } | |
25 | ||
db1326aa | 26 | struct f_inst * |
6ecd2060 | 27 | f_new_dynamic_attr(int type, int f_type UNUSED, int code) |
db1326aa | 28 | { |
6ecd2060 | 29 | /* FIXME: Remove the f_type parameter? */ |
db1326aa | 30 | struct f_inst *f = f_new_inst(); |
0150e521 | 31 | f->aux = type; |
db1326aa MM |
32 | f->a2.i = code; |
33 | return f; | |
34 | } | |
35 | ||
7d6eebae PM |
36 | /* |
37 | * Generate set_dynamic( operation( get_dynamic(), argument ) ) | |
38 | */ | |
39 | struct f_inst * | |
40 | f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument) | |
41 | { | |
42 | struct f_inst *set_dyn = f_new_inst(), | |
43 | *oper = f_new_inst(), | |
44 | *get_dyn = dyn; | |
45 | ||
46 | *set_dyn = *get_dyn; | |
47 | get_dyn->code = P('e','a'); | |
48 | oper->code = operation; | |
49 | oper->aux = operation_aux; | |
50 | oper->a1.p = get_dyn; | |
51 | oper->a2.p = argument; | |
52 | set_dyn->code = P('e','S'); | |
53 | set_dyn->a1.p = oper; | |
54 | return set_dyn; | |
55 | } | |
56 | ||
af582c48 | 57 | struct f_inst * |
0264ccf6 | 58 | f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn) |
af582c48 OZ |
59 | { |
60 | struct f_inst_roa_check *ret = cfg_allocz(sizeof(struct f_inst_roa_check)); | |
61 | ret->i.code = P('R','C'); | |
4be266a9 | 62 | ret->i.lineno = ifs->lino; |
af582c48 OZ |
63 | ret->i.arg1 = prefix; |
64 | ret->i.arg2 = asn; | |
65 | /* prefix == NULL <-> asn == NULL */ | |
66 | ||
0264ccf6 PT |
67 | if (table->addr_type != NET_ROA4 && table->addr_type != NET_ROA6) |
68 | cf_error("%s is not a ROA table", table->name); | |
69 | ret->rtc = table; | |
af582c48 OZ |
70 | |
71 | return &ret->i; | |
72 | } | |
73 | ||
63a381db MM |
74 | char * |
75 | filter_name(struct filter *filter) | |
76 | { | |
77 | if (!filter) | |
78 | return "ACCEPT"; | |
79 | else if (filter == FILTER_REJECT) | |
80 | return "REJECT"; | |
8796a8a5 OZ |
81 | else if (!filter->name) |
82 | return "(unnamed)"; | |
63a381db MM |
83 | else |
84 | return filter->name; | |
85 | } |