Statistics
| Branch: | Revision:

iof-bird-daemon / filter / filter.h @ c8cafc8e

History | View | Annotate | Download (5.4 KB)

1 b9d70dc8 Pavel Machek
/*
2 e0f2e42f Martin Mares
 *        BIRD Internet Routing Daemon -- Filters
3 b9d70dc8 Pavel Machek
 *
4 e0f2e42f Martin Mares
 *        (c) 1999 Pavel Machek <pavel@ucw.cz>
5 b9d70dc8 Pavel Machek
 *
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 23b1539b Pavel Machek
#include "lib/ip.h"
14 4847a894 Ondrej Zajicek
#include "nest/route.h"
15 159fa4ce Pavel Machek
#include "nest/attrs.h"
16 b9d70dc8 Pavel Machek
17 b7005824 Pavel Machek
struct f_inst {                /* Instruction */
18
  struct f_inst *next;        /* Structure is 16 bytes, anyway */
19 c7b43f33 Pavel Machek
  u16 code;
20
  u16 aux;
21 2db3b288 Pavel Machek
  union {
22
    int i;
23
    void *p;
24
  } a1;
25
  union {
26
    int i;
27
    void *p;
28
  } a2;
29 a96a979d Pavel Machek
  int lineno;
30 b9d70dc8 Pavel Machek
};
31
32 2db3b288 Pavel Machek
#define arg1 a1.p
33
#define arg2 a2.p
34
35 af582c48 Ondrej Zajicek
/* 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 c8cafc8e Ondrej Zajicek (work)
  struct roa_table_config *rtc;
39 af582c48 Ondrej Zajicek
};
40
41 66dbdbd9 Ondrej Zajicek (work)
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 b1c9d871 Martin Mares
struct f_prefix {
53 23b1539b Pavel Machek
  ip_addr ip;
54
  int len;
55 d3dd620b Pavel Machek
#define LEN_MASK 0xff
56 6dc7a0cb Pavel Machek
#define LEN_PLUS  0x1000000
57
#define LEN_MINUS 0x2000000
58
#define LEN_RANGE 0x4000000
59
  /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */
60 23b1539b Pavel Machek
};
61
62 b7005824 Pavel Machek
struct f_val {
63
  int type;
64
  union {
65 52e030e1 Ondrej Zajicek
    uint i;
66 42a0c054 Ondrej Zajicek
    u64 ec;
67 66dbdbd9 Ondrej Zajicek (work)
    lcomm lc;
68 c8cafc8e Ondrej Zajicek (work)
    /*    ip_addr ip; Folded into prefix */
69 b1c9d871 Martin Mares
    struct f_prefix px;
70 23b1539b Pavel Machek
    char *s;
71 38506f71 Pavel Machek
    struct f_tree *t;
72 b1a597e0 Ondrej Zajicek
    struct f_trie *ti;
73 10a53608 Pavel Machek
    struct adata *ad;
74
    struct f_path_mask *path_mask;
75 b7005824 Pavel Machek
  } val;
76
};
77
78 e0f2e42f Martin Mares
struct filter {
79
  char *name;
80
  struct f_inst *root;
81
};
82
83 b7005824 Pavel Machek
struct f_inst *f_new_inst(void);
84 a2d15746 Pavel Machek
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 */
85 38506f71 Pavel Machek
struct f_tree *f_new_tree(void);
86 ad9074e9 Pavel Machek
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
87 af582c48 Ondrej Zajicek
struct f_inst *f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn);
88
89 38506f71 Pavel Machek
90
struct f_tree *build_tree(struct f_tree *);
91
struct f_tree *find_tree(struct f_tree *t, struct f_val val);
92 9a4037d4 Pavel Machek
int same_tree(struct f_tree *t1, struct f_tree *t2);
93 0e175f9f Ondrej Zajicek
void tree_format(struct f_tree *t, buffer *buf);
94 84c7e194 Pavel Machek
95 51762a45 Ondrej Zajicek
struct f_trie *f_new_trie(linpool *lp, uint node_size);
96
void *trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h);
97 7f0d245a Ondrej Zajicek
int trie_match_prefix(struct f_trie *t, ip_addr px, int plen);
98 b1a597e0 Ondrej Zajicek
int trie_same(struct f_trie *t1, struct f_trie *t2);
99 0e175f9f Ondrej Zajicek
void trie_format(struct f_trie *t, buffer *buf);
100 b1a597e0 Ondrej Zajicek
101 7f0d245a Ondrej Zajicek
void fprefix_get_bounds(struct f_prefix *px, int *l, int *h);
102
103
static inline void
104
trie_add_fprefix(struct f_trie *t, struct f_prefix *px)
105
{
106
  int l, h;
107
  fprefix_get_bounds(px, &l, &h);
108
  trie_add_prefix(t, px->ip, px->len & LEN_MASK, l, h);
109
}
110
111
static inline int
112
trie_match_fprefix(struct f_trie *t, struct f_prefix *px)
113
{
114
  return trie_match_prefix(t, px->ip, px->len & LEN_MASK);
115
}
116
117
118 9a706f32 Martin Mares
struct ea_list;
119
struct rte;
120
121 0a06a9b8 Pavel Machek
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
122 1321e12a Ondrej Zajicek
struct f_val f_eval_rte(struct f_inst *expr, struct rte **rte, struct linpool *tmp_pool);
123 508d9360 Ondrej Zajicek
struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool);
124 52e030e1 Ondrej Zajicek
uint f_eval_int(struct f_inst *expr);
125 05198c12 Ondrej Zajicek
u32 f_eval_asn(struct f_inst *expr);
126
127 63a381db Martin Mares
char *filter_name(struct filter *filter);
128 30a6108c Martin Mares
int filter_same(struct filter *new, struct filter *old);
129 e0f2e42f Martin Mares
130 9a4037d4 Pavel Machek
int i_same(struct f_inst *f1, struct f_inst *f2);
131
132 38506f71 Pavel Machek
int val_compare(struct f_val v1, struct f_val v2);
133 28a10f84 Ondrej Zajicek
int val_same(struct f_val v1, struct f_val v2);
134 23b1539b Pavel Machek
135 0e175f9f Ondrej Zajicek
void val_format(struct f_val v, buffer *buf);
136
137 508d9360 Ondrej Zajicek
138 23b1539b Pavel Machek
#define F_NOP 0
139 d3dd620b Pavel Machek
#define F_NONL 1
140
#define F_ACCEPT 2        /* Need to preserve ordering: accepts < rejects! */
141 d46ffc97 Martin Mares
#define F_REJECT 3
142
#define F_ERROR 4
143
#define F_QUITBIRD 5
144 ca3d562b Pavel Machek
145 63a381db Martin Mares
#define FILTER_ACCEPT NULL
146
#define FILTER_REJECT ((void *) 1)
147
148 ba921648 Pavel Machek
/* Type numbers must be in 0..0xff range */
149
#define T_MASK 0xff
150
151
/* Internal types */
152 c7b43f33 Pavel Machek
/* Do not use type of zero, that way we'll see errors easier. */
153
#define T_VOID 1
154 ba921648 Pavel Machek
155
/* User visible types, which fit in int */
156
#define T_INT 0x10
157
#define T_BOOL 0x11
158 7a86a8b0 Pavel Machek
#define T_PAIR 0x12  /*        Notice that pair is stored as integer: first << 16 | second */
159 126683fe Ondrej Zajicek
#define T_QUAD 0x13
160 f4536657 Pavel Machek
161 2d496d20 Pavel Machek
/* Put enumerational types in 0x30..0x3f range */
162 f4536657 Pavel Machek
#define T_ENUM_LO 0x30
163 2d496d20 Pavel Machek
#define T_ENUM_HI 0x3f
164 f4536657 Pavel Machek
165 cb8034f4 Pavel Machek
#define T_ENUM_RTS 0x30
166 471bd6c3 Pavel Machek
#define T_ENUM_BGP_ORIGIN 0x31
167 26c09e1d Pavel Machek
#define T_ENUM_SCOPE 0x32
168
#define T_ENUM_RTC 0x33
169
#define T_ENUM_RTD 0x34
170 af582c48 Ondrej Zajicek
#define T_ENUM_ROA 0x35
171 471bd6c3 Pavel Machek
/* new enums go here */
172 3bbc4ad6 Pavel Machek
#define T_ENUM_EMPTY 0x3f        /* Special hack for atomic_aggr */
173 cb8034f4 Pavel Machek
174 f4536657 Pavel Machek
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
175 ba921648 Pavel Machek
176
/* Bigger ones */
177
#define T_IP 0x20
178
#define T_PREFIX 0x21
179
#define T_STRING 0x22
180 dcab7890 Pavel Machek
#define T_PATH_MASK 0x23        /* mask for BGP path */
181 10a53608 Pavel Machek
#define T_PATH 0x24                /* BGP path */
182
#define T_CLIST 0x25                /* Community list */
183 66dbdbd9 Ondrej Zajicek (work)
#define T_EC 0x26                /* Extended community value, u64 */
184
#define T_ECLIST 0x27                /* Extended community list */
185
#define T_LC 0x28                /* Large community value, lcomm */
186
#define T_LCLIST 0x29                /* Large community list */
187 ba921648 Pavel Machek
188 2d496d20 Pavel Machek
#define T_RETURN 0x40
189 ba921648 Pavel Machek
#define T_SET 0x80
190 b1a597e0 Ondrej Zajicek
#define T_PREFIX_SET 0x81
191 d36d838d Pavel Machek
192 a5fc5958 Ondrej Zajicek
193 c8cafc8e Ondrej Zajicek (work)
#define SA_FROM                 1
194
#define SA_GW                 2
195
#define SA_NET                 3
196
#define SA_PROTO         4
197
#define SA_SOURCE         5
198
#define SA_SCOPE         6
199
#define SA_CAST                 7
200
#define SA_DEST                 8
201
#define SA_IFNAME         9
202
#define SA_IFINDEX        10
203 a5fc5958 Ondrej Zajicek
204
205 38506f71 Pavel Machek
struct f_tree {
206
  struct f_tree *left, *right;
207
  struct f_val from, to;
208
  void *data;
209
};
210
211 b1a597e0 Ondrej Zajicek
struct f_trie_node
212
{
213
  ip_addr addr, mask, accept;
214
  int plen;
215
  struct f_trie_node *c[2];
216
};
217
218
struct f_trie
219
{
220 7f0d245a Ondrej Zajicek
  linpool *lp;
221 b1a597e0 Ondrej Zajicek
  int zero;
222 51762a45 Ondrej Zajicek
  uint node_size;
223
  struct f_trie_node root[0];                /* Root trie node follows */
224 b1a597e0 Ondrej Zajicek
};
225
226 d3dd620b Pavel Machek
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
227
228 3076b5ae Martin Mares
#define FF_FORCE_TMPATTR 1                /* Force all attributes to be temporary */
229 0a06a9b8 Pavel Machek
230 b9d70dc8 Pavel Machek
#endif