]>
Commit | Line | Data |
---|---|---|
b9d70dc8 | 1 | /* |
e0f2e42f | 2 | * BIRD Internet Routing Daemon -- Filters |
b9d70dc8 | 3 | * |
e0f2e42f | 4 | * (c) 1999 Pavel Machek <pavel@ucw.cz> |
b9d70dc8 PM |
5 | * |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #ifndef _BIRD_FILT_H_ | |
10 | #define _BIRD_FILT_H_ | |
11 | ||
12 | #include "lib/resource.h" | |
23b1539b | 13 | #include "lib/ip.h" |
4847a894 | 14 | #include "nest/route.h" |
159fa4ce | 15 | #include "nest/attrs.h" |
b9d70dc8 | 16 | |
b7005824 PM |
17 | struct f_inst { /* Instruction */ |
18 | struct f_inst *next; /* Structure is 16 bytes, anyway */ | |
c7b43f33 PM |
19 | u16 code; |
20 | u16 aux; | |
2db3b288 PM |
21 | union { |
22 | int i; | |
23 | void *p; | |
24 | } a1; | |
25 | union { | |
26 | int i; | |
27 | void *p; | |
28 | } a2; | |
a96a979d | 29 | int lineno; |
b9d70dc8 PM |
30 | }; |
31 | ||
2db3b288 PM |
32 | #define arg1 a1.p |
33 | #define arg2 a2.p | |
34 | ||
af582c48 OZ |
35 | /* Not enough fields in f_inst for three args used by roa_check() */ |
36 | struct f_inst_roa_check { | |
37 | struct f_inst i; | |
38 | struct roa_table_config *rtc; | |
39 | }; | |
40 | ||
b1c9d871 | 41 | struct f_prefix { |
04632fd7 | 42 | net_addr net; |
5e173e9f | 43 | u8 lo, hi; |
23b1539b PM |
44 | }; |
45 | ||
b7005824 PM |
46 | struct f_val { |
47 | int type; | |
48 | union { | |
52e030e1 | 49 | uint i; |
42a0c054 | 50 | u64 ec; |
5e173e9f JMM |
51 | ip_addr ip; |
52 | const net_addr *net; | |
23b1539b | 53 | char *s; |
38506f71 | 54 | struct f_tree *t; |
b1a597e0 | 55 | struct f_trie *ti; |
10a53608 PM |
56 | struct adata *ad; |
57 | struct f_path_mask *path_mask; | |
b7005824 PM |
58 | } val; |
59 | }; | |
60 | ||
e0f2e42f MM |
61 | struct filter { |
62 | char *name; | |
63 | struct f_inst *root; | |
64 | }; | |
65 | ||
b7005824 | 66 | struct f_inst *f_new_inst(void); |
a2d15746 | 67 | struct f_inst *f_new_dynamic_attr(int type, int f_type, int code); /* Type as core knows it, type as filters know it, and code of dynamic attribute */ |
38506f71 | 68 | struct f_tree *f_new_tree(void); |
ad9074e9 | 69 | struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument); |
9656dce7 | 70 | // struct f_inst *f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn); |
af582c48 | 71 | |
38506f71 PM |
72 | |
73 | struct f_tree *build_tree(struct f_tree *); | |
74 | struct f_tree *find_tree(struct f_tree *t, struct f_val val); | |
9a4037d4 | 75 | int same_tree(struct f_tree *t1, struct f_tree *t2); |
0e175f9f | 76 | void tree_format(struct f_tree *t, buffer *buf); |
84c7e194 | 77 | |
51762a45 | 78 | struct f_trie *f_new_trie(linpool *lp, uint node_size); |
0bf95f99 | 79 | void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h); |
5e173e9f | 80 | int trie_match_net(struct f_trie *t, const net_addr *n); |
b1a597e0 | 81 | int trie_same(struct f_trie *t1, struct f_trie *t2); |
0e175f9f | 82 | void trie_format(struct f_trie *t, buffer *buf); |
b1a597e0 | 83 | |
9a706f32 MM |
84 | struct ea_list; |
85 | struct rte; | |
86 | ||
0a06a9b8 | 87 | int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags); |
1321e12a | 88 | struct f_val f_eval_rte(struct f_inst *expr, struct rte **rte, struct linpool *tmp_pool); |
508d9360 | 89 | struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool); |
52e030e1 | 90 | uint f_eval_int(struct f_inst *expr); |
05198c12 OZ |
91 | u32 f_eval_asn(struct f_inst *expr); |
92 | ||
63a381db | 93 | char *filter_name(struct filter *filter); |
30a6108c | 94 | int filter_same(struct filter *new, struct filter *old); |
e0f2e42f | 95 | |
9a4037d4 PM |
96 | int i_same(struct f_inst *f1, struct f_inst *f2); |
97 | ||
38506f71 | 98 | int val_compare(struct f_val v1, struct f_val v2); |
28a10f84 | 99 | int val_same(struct f_val v1, struct f_val v2); |
23b1539b | 100 | |
0e175f9f OZ |
101 | void val_format(struct f_val v, buffer *buf); |
102 | ||
508d9360 | 103 | |
23b1539b | 104 | #define F_NOP 0 |
d3dd620b PM |
105 | #define F_NONL 1 |
106 | #define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */ | |
d46ffc97 MM |
107 | #define F_REJECT 3 |
108 | #define F_ERROR 4 | |
109 | #define F_QUITBIRD 5 | |
ca3d562b | 110 | |
63a381db MM |
111 | #define FILTER_ACCEPT NULL |
112 | #define FILTER_REJECT ((void *) 1) | |
113 | ||
ba921648 PM |
114 | /* Type numbers must be in 0..0xff range */ |
115 | #define T_MASK 0xff | |
116 | ||
117 | /* Internal types */ | |
c7b43f33 PM |
118 | /* Do not use type of zero, that way we'll see errors easier. */ |
119 | #define T_VOID 1 | |
ba921648 PM |
120 | |
121 | /* User visible types, which fit in int */ | |
122 | #define T_INT 0x10 | |
123 | #define T_BOOL 0x11 | |
7a86a8b0 | 124 | #define T_PAIR 0x12 /* Notice that pair is stored as integer: first << 16 | second */ |
126683fe | 125 | #define T_QUAD 0x13 |
f4536657 | 126 | |
2d496d20 | 127 | /* Put enumerational types in 0x30..0x3f range */ |
f4536657 | 128 | #define T_ENUM_LO 0x30 |
2d496d20 | 129 | #define T_ENUM_HI 0x3f |
f4536657 | 130 | |
cb8034f4 | 131 | #define T_ENUM_RTS 0x30 |
471bd6c3 | 132 | #define T_ENUM_BGP_ORIGIN 0x31 |
26c09e1d PM |
133 | #define T_ENUM_SCOPE 0x32 |
134 | #define T_ENUM_RTC 0x33 | |
135 | #define T_ENUM_RTD 0x34 | |
cb1bd816 | 136 | #define T_ENUM_ROA 0x35 |
471bd6c3 | 137 | /* new enums go here */ |
3bbc4ad6 | 138 | #define T_ENUM_EMPTY 0x3f /* Special hack for atomic_aggr */ |
cb8034f4 | 139 | |
f4536657 | 140 | #define T_ENUM T_ENUM_LO ... T_ENUM_HI |
ba921648 PM |
141 | |
142 | /* Bigger ones */ | |
143 | #define T_IP 0x20 | |
5e173e9f | 144 | #define T_NET 0x21 |
ba921648 | 145 | #define T_STRING 0x22 |
dcab7890 | 146 | #define T_PATH_MASK 0x23 /* mask for BGP path */ |
10a53608 PM |
147 | #define T_PATH 0x24 /* BGP path */ |
148 | #define T_CLIST 0x25 /* Community list */ | |
42a0c054 OZ |
149 | #define T_ECLIST 0x26 /* Extended community list */ |
150 | #define T_EC 0x27 /* Extended community value, u64 */ | |
ba921648 | 151 | |
2d496d20 | 152 | #define T_RETURN 0x40 |
ba921648 | 153 | #define T_SET 0x80 |
b1a597e0 | 154 | #define T_PREFIX_SET 0x81 |
d36d838d | 155 | |
a5fc5958 | 156 | |
5e173e9f JMM |
157 | #define SA_FROM 1 |
158 | #define SA_GW 2 | |
159 | #define SA_NET 3 | |
160 | #define SA_PROTO 4 | |
161 | #define SA_SOURCE 5 | |
162 | #define SA_SCOPE 6 | |
a5fc5958 OZ |
163 | #define SA_CAST 7 |
164 | #define SA_DEST 8 | |
165 | #define SA_IFNAME 9 | |
166 | #define SA_IFINDEX 10 | |
167 | ||
168 | ||
38506f71 PM |
169 | struct f_tree { |
170 | struct f_tree *left, *right; | |
171 | struct f_val from, to; | |
172 | void *data; | |
173 | }; | |
174 | ||
b1a597e0 OZ |
175 | struct f_trie_node |
176 | { | |
177 | ip_addr addr, mask, accept; | |
178 | int plen; | |
179 | struct f_trie_node *c[2]; | |
180 | }; | |
181 | ||
182 | struct f_trie | |
183 | { | |
7f0d245a | 184 | linpool *lp; |
b1a597e0 | 185 | int zero; |
51762a45 OZ |
186 | uint node_size; |
187 | struct f_trie_node root[0]; /* Root trie node follows */ | |
b1a597e0 OZ |
188 | }; |
189 | ||
d3dd620b PM |
190 | #define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); |
191 | ||
3076b5ae | 192 | #define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */ |
0a06a9b8 | 193 | |
b9d70dc8 | 194 | #endif |