iof-bird-daemon / filter / filter.h @ 62e64905
History | View | Annotate | Download (5.32 KB)
1 |
/*
|
---|---|
2 |
* BIRD Internet Routing Daemon -- Filters
|
3 |
*
|
4 |
* (c) 1999 Pavel Machek <pavel@ucw.cz>
|
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" |
13 |
#include "lib/ip.h" |
14 |
#include "nest/route.h" |
15 |
#include "nest/attrs.h" |
16 |
|
17 |
struct f_inst { /* Instruction */ |
18 |
struct f_inst *next; /* Structure is 16 bytes, anyway */ |
19 |
u16 code; /* Instruction code, see the interpret() function and P() macro */
|
20 |
u16 aux; /* Extension to instruction code, T_*, EA_*, EAF_* */
|
21 |
union {
|
22 |
int i;
|
23 |
void *p;
|
24 |
} a1; /* The first argument */
|
25 |
union {
|
26 |
int i;
|
27 |
void *p;
|
28 |
} a2; /* The second argument */
|
29 |
int lineno;
|
30 |
}; |
31 |
|
32 |
#define arg1 a1.p
|
33 |
#define arg2 a2.p
|
34 |
|
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 rtable_config *rtc;
|
39 |
}; |
40 |
|
41 |
struct f_inst3 {
|
42 |
struct f_inst i;
|
43 |
union {
|
44 |
int i;
|
45 |
void *p;
|
46 |
} a3; |
47 |
}; |
48 |
|
49 |
#define INST3(x) (((struct f_inst3 *) x)->a3) |
50 |
|
51 |
|
52 |
struct f_prefix {
|
53 |
net_addr net; |
54 |
u8 lo, hi; |
55 |
}; |
56 |
|
57 |
struct f_val {
|
58 |
int type; /* T_* */ |
59 |
union {
|
60 |
uint i; |
61 |
u64 ec; |
62 |
lcomm lc; |
63 |
ip_addr ip; |
64 |
const net_addr *net;
|
65 |
char *s;
|
66 |
struct f_tree *t;
|
67 |
struct f_trie *ti;
|
68 |
struct adata *ad;
|
69 |
struct f_path_mask *path_mask;
|
70 |
} val; |
71 |
}; |
72 |
|
73 |
struct filter {
|
74 |
char *name;
|
75 |
struct f_inst *root;
|
76 |
}; |
77 |
|
78 |
struct f_inst *f_new_inst(void); |
79 |
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 */ |
80 |
struct f_tree *f_new_tree(void); |
81 |
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument); |
82 |
struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn); |
83 |
|
84 |
|
85 |
struct f_tree *build_tree(struct f_tree *); |
86 |
struct f_tree *find_tree(struct f_tree *t, struct f_val val); |
87 |
int same_tree(struct f_tree *t1, struct f_tree *t2); |
88 |
void tree_format(struct f_tree *t, buffer *buf); |
89 |
|
90 |
struct f_trie *f_new_trie(linpool *lp, uint node_size);
|
91 |
void *trie_add_prefix(struct f_trie *t, const net_addr *n, uint l, uint h); |
92 |
int trie_match_net(struct f_trie *t, const net_addr *n); |
93 |
int trie_same(struct f_trie *t1, struct f_trie *t2); |
94 |
void trie_format(struct f_trie *t, buffer *buf); |
95 |
|
96 |
struct ea_list;
|
97 |
struct rte;
|
98 |
|
99 |
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags); |
100 |
struct f_val f_eval_rte(struct f_inst *expr, struct rte **rte, struct linpool *tmp_pool); |
101 |
struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool); |
102 |
uint f_eval_int(struct f_inst *expr);
|
103 |
u32 f_eval_asn(struct f_inst *expr);
|
104 |
|
105 |
char *filter_name(struct filter *filter); |
106 |
int filter_same(struct filter *new, struct filter *old); |
107 |
|
108 |
int i_same(struct f_inst *f1, struct f_inst *f2); |
109 |
|
110 |
int val_compare(struct f_val v1, struct f_val v2); |
111 |
int val_same(struct f_val v1, struct f_val v2); |
112 |
|
113 |
void val_format(struct f_val v, buffer *buf); |
114 |
|
115 |
|
116 |
#define F_NOP 0 |
117 |
#define F_NONL 1 |
118 |
#define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */ |
119 |
#define F_REJECT 3 |
120 |
#define F_ERROR 4 |
121 |
#define F_QUITBIRD 5 |
122 |
|
123 |
#define FILTER_ACCEPT NULL |
124 |
#define FILTER_REJECT ((void *) 1) |
125 |
|
126 |
/* Type numbers must be in 0..0xff range */
|
127 |
#define T_MASK 0xff |
128 |
|
129 |
/* Internal types */
|
130 |
/* Do not use type of zero, that way we'll see errors easier. */
|
131 |
#define T_VOID 1 |
132 |
|
133 |
/* User visible types, which fit in int */
|
134 |
#define T_INT 0x10 |
135 |
#define T_BOOL 0x11 |
136 |
#define T_PAIR 0x12 /* Notice that pair is stored as integer: first << 16 | second */ |
137 |
#define T_QUAD 0x13 |
138 |
|
139 |
/* Put enumerational types in 0x30..0x3f range */
|
140 |
#define T_ENUM_LO 0x30 |
141 |
#define T_ENUM_HI 0x3f |
142 |
|
143 |
#define T_ENUM_RTS 0x30 |
144 |
#define T_ENUM_BGP_ORIGIN 0x31 |
145 |
#define T_ENUM_SCOPE 0x32 |
146 |
#define T_ENUM_RTC 0x33 |
147 |
#define T_ENUM_RTD 0x34 |
148 |
#define T_ENUM_ROA 0x35 |
149 |
/* new enums go here */
|
150 |
#define T_ENUM_EMPTY 0x3f /* Special hack for atomic_aggr */ |
151 |
|
152 |
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
|
153 |
|
154 |
/* Bigger ones */
|
155 |
#define T_IP 0x20 |
156 |
#define T_NET 0x21 |
157 |
#define T_STRING 0x22 |
158 |
#define T_PATH_MASK 0x23 /* mask for BGP path */ |
159 |
#define T_PATH 0x24 /* BGP path */ |
160 |
#define T_CLIST 0x25 /* Community list */ |
161 |
#define T_EC 0x26 /* Extended community value, u64 */ |
162 |
#define T_ECLIST 0x27 /* Extended community list */ |
163 |
#define T_LC 0x28 /* Large community value, lcomm */ |
164 |
#define T_LCLIST 0x29 /* Large community list */ |
165 |
|
166 |
#define T_RETURN 0x40 |
167 |
#define T_SET 0x80 |
168 |
#define T_PREFIX_SET 0x81 |
169 |
|
170 |
|
171 |
#define SA_FROM 1 |
172 |
#define SA_GW 2 |
173 |
#define SA_NET 3 |
174 |
#define SA_PROTO 4 |
175 |
#define SA_SOURCE 5 |
176 |
#define SA_SCOPE 6 |
177 |
#define SA_DEST 7 |
178 |
#define SA_IFNAME 8 |
179 |
#define SA_IFINDEX 9 |
180 |
|
181 |
|
182 |
struct f_tree {
|
183 |
struct f_tree *left, *right;
|
184 |
struct f_val from, to;
|
185 |
void *data;
|
186 |
}; |
187 |
|
188 |
struct f_trie_node
|
189 |
{ |
190 |
ip_addr addr, mask, accept; |
191 |
uint plen; |
192 |
struct f_trie_node *c[2]; |
193 |
}; |
194 |
|
195 |
struct f_trie
|
196 |
{ |
197 |
linpool *lp; |
198 |
int zero;
|
199 |
uint node_size; |
200 |
struct f_trie_node root[0]; /* Root trie node follows */ |
201 |
}; |
202 |
|
203 |
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); |
204 |
|
205 |
#define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */ |
206 |
|
207 |
/* Bird Tests */
|
208 |
struct f_bt_test_suite {
|
209 |
node n; /* Node in config->tests */
|
210 |
struct f_inst *fn; /* Root of function */ |
211 |
const char *fn_name; /* Name of test */ |
212 |
const char *dsc; /* Description */ |
213 |
}; |
214 |
|
215 |
/* Hook for call bt_assert() function in configuration */
|
216 |
extern void (*bt_assert_hook)(int result, struct f_inst *assert); |
217 |
|
218 |
#endif
|