]>
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 | ||
b1c9d871 | 35 | struct f_prefix { |
23b1539b PM |
36 | ip_addr ip; |
37 | int len; | |
d3dd620b | 38 | #define LEN_MASK 0xff |
6dc7a0cb PM |
39 | #define LEN_PLUS 0x1000000 |
40 | #define LEN_MINUS 0x2000000 | |
41 | #define LEN_RANGE 0x4000000 | |
42 | /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */ | |
23b1539b PM |
43 | }; |
44 | ||
b7005824 PM |
45 | struct f_val { |
46 | int type; | |
47 | union { | |
48 | int i; | |
6dc7a0cb | 49 | /* ip_addr ip; Folded into prefix */ |
b1c9d871 | 50 | struct f_prefix px; |
23b1539b | 51 | char *s; |
38506f71 | 52 | struct f_tree *t; |
b1a597e0 | 53 | struct f_trie *ti; |
10a53608 PM |
54 | struct adata *ad; |
55 | struct f_path_mask *path_mask; | |
b7005824 PM |
56 | } val; |
57 | }; | |
58 | ||
e0f2e42f MM |
59 | struct filter { |
60 | char *name; | |
61 | struct f_inst *root; | |
62 | }; | |
63 | ||
b7005824 | 64 | struct f_inst *f_new_inst(void); |
a2d15746 | 65 | 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 | 66 | struct f_tree *f_new_tree(void); |
ad9074e9 | 67 | struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument); |
38506f71 PM |
68 | |
69 | struct f_tree *build_tree(struct f_tree *); | |
70 | struct f_tree *find_tree(struct f_tree *t, struct f_val val); | |
9a4037d4 | 71 | int same_tree(struct f_tree *t1, struct f_tree *t2); |
84c7e194 | 72 | |
b1a597e0 OZ |
73 | struct f_trie *f_new_trie(void); |
74 | void trie_add_prefix(struct f_trie *t, struct f_prefix *px); | |
75 | int trie_match_prefix(struct f_trie *t, struct f_prefix *px); | |
76 | int trie_same(struct f_trie *t1, struct f_trie *t2); | |
77 | int trie_print(struct f_trie *t, char *buf, int blen); | |
78 | ||
9a706f32 MM |
79 | struct ea_list; |
80 | struct rte; | |
81 | ||
0a06a9b8 | 82 | int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags); |
b1c9d871 | 83 | int f_eval_int(struct f_inst *expr); |
63a381db | 84 | char *filter_name(struct filter *filter); |
30a6108c | 85 | int filter_same(struct filter *new, struct filter *old); |
e0f2e42f | 86 | |
9a4037d4 PM |
87 | int i_same(struct f_inst *f1, struct f_inst *f2); |
88 | ||
38506f71 PM |
89 | int val_compare(struct f_val v1, struct f_val v2); |
90 | void val_print(struct f_val v); | |
23b1539b PM |
91 | |
92 | #define F_NOP 0 | |
d3dd620b PM |
93 | #define F_NONL 1 |
94 | #define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */ | |
d46ffc97 MM |
95 | #define F_REJECT 3 |
96 | #define F_ERROR 4 | |
97 | #define F_QUITBIRD 5 | |
ca3d562b | 98 | |
63a381db MM |
99 | #define FILTER_ACCEPT NULL |
100 | #define FILTER_REJECT ((void *) 1) | |
101 | ||
ba921648 PM |
102 | /* Type numbers must be in 0..0xff range */ |
103 | #define T_MASK 0xff | |
104 | ||
105 | /* Internal types */ | |
c7b43f33 PM |
106 | /* Do not use type of zero, that way we'll see errors easier. */ |
107 | #define T_VOID 1 | |
ba921648 PM |
108 | |
109 | /* User visible types, which fit in int */ | |
110 | #define T_INT 0x10 | |
111 | #define T_BOOL 0x11 | |
7a86a8b0 | 112 | #define T_PAIR 0x12 /* Notice that pair is stored as integer: first << 16 | second */ |
f4536657 | 113 | |
2d496d20 | 114 | /* Put enumerational types in 0x30..0x3f range */ |
f4536657 | 115 | #define T_ENUM_LO 0x30 |
2d496d20 | 116 | #define T_ENUM_HI 0x3f |
f4536657 | 117 | |
cb8034f4 | 118 | #define T_ENUM_RTS 0x30 |
471bd6c3 | 119 | #define T_ENUM_BGP_ORIGIN 0x31 |
26c09e1d PM |
120 | #define T_ENUM_SCOPE 0x32 |
121 | #define T_ENUM_RTC 0x33 | |
122 | #define T_ENUM_RTD 0x34 | |
471bd6c3 | 123 | /* new enums go here */ |
3bbc4ad6 | 124 | #define T_ENUM_EMPTY 0x3f /* Special hack for atomic_aggr */ |
cb8034f4 | 125 | |
f4536657 | 126 | #define T_ENUM T_ENUM_LO ... T_ENUM_HI |
ba921648 PM |
127 | |
128 | /* Bigger ones */ | |
129 | #define T_IP 0x20 | |
130 | #define T_PREFIX 0x21 | |
131 | #define T_STRING 0x22 | |
dcab7890 | 132 | #define T_PATH_MASK 0x23 /* mask for BGP path */ |
10a53608 PM |
133 | #define T_PATH 0x24 /* BGP path */ |
134 | #define T_CLIST 0x25 /* Community list */ | |
ba921648 | 135 | |
2d496d20 | 136 | #define T_RETURN 0x40 |
ba921648 | 137 | #define T_SET 0x80 |
b1a597e0 | 138 | #define T_PREFIX_SET 0x81 |
d36d838d | 139 | |
38506f71 PM |
140 | struct f_tree { |
141 | struct f_tree *left, *right; | |
142 | struct f_val from, to; | |
143 | void *data; | |
144 | }; | |
145 | ||
b1a597e0 OZ |
146 | struct f_trie_node |
147 | { | |
148 | ip_addr addr, mask, accept; | |
149 | int plen; | |
150 | struct f_trie_node *c[2]; | |
151 | }; | |
152 | ||
153 | struct f_trie | |
154 | { | |
155 | int zero; | |
156 | struct f_trie_node root; | |
157 | }; | |
158 | ||
d3dd620b PM |
159 | #define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); |
160 | ||
3076b5ae | 161 | #define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */ |
0a06a9b8 | 162 | |
b9d70dc8 | 163 | #endif |