]> git.ipfire.org Git - thirdparty/bird.git/blame - filter/filter.h
Rewrites static attribute filter code and adds ifname/ifindex attributes.
[thirdparty/bird.git] / filter / filter.h
CommitLineData
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
17struct 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() */
36struct f_inst_roa_check {
37 struct f_inst i;
38 struct roa_table_config *rtc;
39};
40
b1c9d871 41struct f_prefix {
23b1539b
PM
42 ip_addr ip;
43 int len;
d3dd620b 44#define LEN_MASK 0xff
6dc7a0cb
PM
45#define LEN_PLUS 0x1000000
46#define LEN_MINUS 0x2000000
47#define LEN_RANGE 0x4000000
48 /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */
23b1539b
PM
49};
50
b7005824
PM
51struct f_val {
52 int type;
53 union {
54 int i;
42a0c054 55 u64 ec;
6dc7a0cb 56 /* ip_addr ip; Folded into prefix */
b1c9d871 57 struct f_prefix px;
23b1539b 58 char *s;
38506f71 59 struct f_tree *t;
b1a597e0 60 struct f_trie *ti;
10a53608
PM
61 struct adata *ad;
62 struct f_path_mask *path_mask;
b7005824
PM
63 } val;
64};
65
e0f2e42f
MM
66struct filter {
67 char *name;
68 struct f_inst *root;
69};
70
b7005824 71struct f_inst *f_new_inst(void);
a2d15746 72struct 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 73struct f_tree *f_new_tree(void);
ad9074e9 74struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
af582c48
OZ
75struct f_inst *f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn);
76
38506f71
PM
77
78struct f_tree *build_tree(struct f_tree *);
79struct f_tree *find_tree(struct f_tree *t, struct f_val val);
9a4037d4 80int same_tree(struct f_tree *t1, struct f_tree *t2);
84c7e194 81
7f0d245a
OZ
82struct f_trie *f_new_trie(linpool *lp);
83void trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h);
84int trie_match_prefix(struct f_trie *t, ip_addr px, int plen);
b1a597e0 85int trie_same(struct f_trie *t1, struct f_trie *t2);
0d1b3c4c 86void trie_print(struct f_trie *t);
b1a597e0 87
7f0d245a
OZ
88void fprefix_get_bounds(struct f_prefix *px, int *l, int *h);
89
90static inline void
91trie_add_fprefix(struct f_trie *t, struct f_prefix *px)
92{
93 int l, h;
94 fprefix_get_bounds(px, &l, &h);
95 trie_add_prefix(t, px->ip, px->len & LEN_MASK, l, h);
96}
97
98static inline int
99trie_match_fprefix(struct f_trie *t, struct f_prefix *px)
100{
101 return trie_match_prefix(t, px->ip, px->len & LEN_MASK);
102}
103
104
9a706f32
MM
105struct ea_list;
106struct rte;
107
0a06a9b8 108int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
508d9360 109struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool);
b1c9d871 110int f_eval_int(struct f_inst *expr);
05198c12
OZ
111u32 f_eval_asn(struct f_inst *expr);
112
63a381db 113char *filter_name(struct filter *filter);
30a6108c 114int filter_same(struct filter *new, struct filter *old);
e0f2e42f 115
9a4037d4
PM
116int i_same(struct f_inst *f1, struct f_inst *f2);
117
38506f71 118int val_compare(struct f_val v1, struct f_val v2);
dfd48621 119int tree_compare(const void *p1, const void *p2);
23b1539b 120
508d9360
OZ
121void val_print(struct f_val v);
122
23b1539b 123#define F_NOP 0
d3dd620b
PM
124#define F_NONL 1
125#define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */
d46ffc97
MM
126#define F_REJECT 3
127#define F_ERROR 4
128#define F_QUITBIRD 5
ca3d562b 129
63a381db
MM
130#define FILTER_ACCEPT NULL
131#define FILTER_REJECT ((void *) 1)
132
ba921648
PM
133/* Type numbers must be in 0..0xff range */
134#define T_MASK 0xff
135
136/* Internal types */
c7b43f33
PM
137/* Do not use type of zero, that way we'll see errors easier. */
138#define T_VOID 1
ba921648
PM
139
140/* User visible types, which fit in int */
141#define T_INT 0x10
142#define T_BOOL 0x11
7a86a8b0 143#define T_PAIR 0x12 /* Notice that pair is stored as integer: first << 16 | second */
126683fe 144#define T_QUAD 0x13
f4536657 145
2d496d20 146/* Put enumerational types in 0x30..0x3f range */
f4536657 147#define T_ENUM_LO 0x30
2d496d20 148#define T_ENUM_HI 0x3f
f4536657 149
cb8034f4 150#define T_ENUM_RTS 0x30
471bd6c3 151#define T_ENUM_BGP_ORIGIN 0x31
26c09e1d
PM
152#define T_ENUM_SCOPE 0x32
153#define T_ENUM_RTC 0x33
154#define T_ENUM_RTD 0x34
af582c48 155#define T_ENUM_ROA 0x35
471bd6c3 156/* new enums go here */
3bbc4ad6 157#define T_ENUM_EMPTY 0x3f /* Special hack for atomic_aggr */
cb8034f4 158
f4536657 159#define T_ENUM T_ENUM_LO ... T_ENUM_HI
ba921648
PM
160
161/* Bigger ones */
162#define T_IP 0x20
163#define T_PREFIX 0x21
164#define T_STRING 0x22
dcab7890 165#define T_PATH_MASK 0x23 /* mask for BGP path */
10a53608
PM
166#define T_PATH 0x24 /* BGP path */
167#define T_CLIST 0x25 /* Community list */
42a0c054
OZ
168#define T_ECLIST 0x26 /* Extended community list */
169#define T_EC 0x27 /* Extended community value, u64 */
ba921648 170
2d496d20 171#define T_RETURN 0x40
ba921648 172#define T_SET 0x80
b1a597e0 173#define T_PREFIX_SET 0x81
d36d838d 174
a5fc5958
OZ
175
176#define SA_FROM 1
177#define SA_GW 2
178#define SA_NET 3
179#define SA_PROTO 4
180#define SA_SOURCE 5
181#define SA_SCOPE 6
182#define SA_CAST 7
183#define SA_DEST 8
184#define SA_IFNAME 9
185#define SA_IFINDEX 10
186
187
38506f71
PM
188struct f_tree {
189 struct f_tree *left, *right;
190 struct f_val from, to;
191 void *data;
192};
193
b1a597e0
OZ
194struct f_trie_node
195{
196 ip_addr addr, mask, accept;
197 int plen;
198 struct f_trie_node *c[2];
199};
200
201struct f_trie
202{
7f0d245a 203 linpool *lp;
b1a597e0
OZ
204 int zero;
205 struct f_trie_node root;
206};
207
d3dd620b
PM
208#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
209
3076b5ae 210#define FF_FORCE_TMPATTR 1 /* Force all attributes to be temporary */
0a06a9b8 211
b9d70dc8 212#endif