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