Statistics
| Branch: | Revision:

iof-bird-daemon / filter / filter.h @ 51762a45

History | View | Annotate | Download (5.11 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;
20
  u16 aux;
21
  union {
22
    int i;
23
    void *p;
24
  } a1;
25
  union {
26
    int i;
27
    void *p;
28
  } a2;
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 roa_table_config *rtc;        
39
};
40

    
41
struct f_prefix {
42
  ip_addr ip;
43
  int len;
44
#define LEN_MASK 0xff
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) */
49
};
50

    
51
struct f_val {
52
  int type;
53
  union {
54
    uint i;
55
    u64 ec;
56
    /*    ip_addr ip; Folded into prefix */        
57
    struct f_prefix px;
58
    char *s;
59
    struct f_tree *t;
60
    struct f_trie *ti;
61
    struct adata *ad;
62
    struct f_path_mask *path_mask;
63
  } val;
64
};
65

    
66
struct filter {
67
  char *name;
68
  struct f_inst *root;
69
};
70

    
71
struct f_inst *f_new_inst(void);
72
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 */
73
struct f_tree *f_new_tree(void);
74
struct f_inst *f_generate_complex(int operation, int operation_aux, struct f_inst *dyn, struct f_inst *argument);
75
struct f_inst *f_generate_roa_check(struct symbol *sym, struct f_inst *prefix, struct f_inst *asn);
76

    
77

    
78
struct f_tree *build_tree(struct f_tree *);
79
struct f_tree *find_tree(struct f_tree *t, struct f_val val);
80
int same_tree(struct f_tree *t1, struct f_tree *t2);
81
void tree_format(struct f_tree *t, buffer *buf);
82

    
83
struct f_trie *f_new_trie(linpool *lp, uint node_size);
84
void *trie_add_prefix(struct f_trie *t, ip_addr px, int plen, int l, int h);
85
int trie_match_prefix(struct f_trie *t, ip_addr px, int plen);
86
int trie_same(struct f_trie *t1, struct f_trie *t2);
87
void trie_format(struct f_trie *t, buffer *buf);
88

    
89
void fprefix_get_bounds(struct f_prefix *px, int *l, int *h);
90

    
91
static inline void
92
trie_add_fprefix(struct f_trie *t, struct f_prefix *px)
93
{
94
  int l, h;
95
  fprefix_get_bounds(px, &l, &h);
96
  trie_add_prefix(t, px->ip, px->len & LEN_MASK, l, h);
97
}
98

    
99
static inline int
100
trie_match_fprefix(struct f_trie *t, struct f_prefix *px)
101
{
102
  return trie_match_prefix(t, px->ip, px->len & LEN_MASK);
103
}
104

    
105

    
106
struct ea_list;
107
struct rte;
108

    
109
int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool, int flags);
110
struct f_val f_eval(struct f_inst *expr, struct linpool *tmp_pool);
111
uint f_eval_int(struct f_inst *expr);
112
u32 f_eval_asn(struct f_inst *expr);
113

    
114
char *filter_name(struct filter *filter);
115
int filter_same(struct filter *new, struct filter *old);
116

    
117
int i_same(struct f_inst *f1, struct f_inst *f2);
118

    
119
int val_compare(struct f_val v1, struct f_val v2);
120
int val_same(struct f_val v1, struct f_val v2);
121

    
122
void val_format(struct f_val v, buffer *buf);
123

    
124

    
125
#define F_NOP 0
126
#define F_NONL 1
127
#define F_ACCEPT 2        /* Need to preserve ordering: accepts < rejects! */
128
#define F_REJECT 3
129
#define F_ERROR 4
130
#define F_QUITBIRD 5
131

    
132
#define FILTER_ACCEPT NULL
133
#define FILTER_REJECT ((void *) 1)
134

    
135
/* Type numbers must be in 0..0xff range */
136
#define T_MASK 0xff
137

    
138
/* Internal types */
139
/* Do not use type of zero, that way we'll see errors easier. */
140
#define T_VOID 1
141

    
142
/* User visible types, which fit in int */
143
#define T_INT 0x10
144
#define T_BOOL 0x11
145
#define T_PAIR 0x12  /*        Notice that pair is stored as integer: first << 16 | second */
146
#define T_QUAD 0x13
147

    
148
/* Put enumerational types in 0x30..0x3f range */
149
#define T_ENUM_LO 0x30
150
#define T_ENUM_HI 0x3f
151

    
152
#define T_ENUM_RTS 0x30
153
#define T_ENUM_BGP_ORIGIN 0x31
154
#define T_ENUM_SCOPE 0x32
155
#define T_ENUM_RTC 0x33
156
#define T_ENUM_RTD 0x34
157
#define T_ENUM_ROA 0x35
158
/* new enums go here */
159
#define T_ENUM_EMPTY 0x3f        /* Special hack for atomic_aggr */
160

    
161
#define T_ENUM T_ENUM_LO ... T_ENUM_HI
162

    
163
/* Bigger ones */
164
#define T_IP 0x20
165
#define T_PREFIX 0x21
166
#define T_STRING 0x22
167
#define T_PATH_MASK 0x23        /* mask for BGP path */
168
#define T_PATH 0x24                /* BGP path */
169
#define T_CLIST 0x25                /* Community list */
170
#define T_ECLIST 0x26                /* Extended community list */
171
#define T_EC 0x27                /* Extended community value, u64 */
172

    
173
#define T_RETURN 0x40
174
#define T_SET 0x80
175
#define T_PREFIX_SET 0x81
176

    
177

    
178
#define SA_FROM                 1    
179
#define SA_GW                 2      
180
#define SA_NET                 3     
181
#define SA_PROTO         4   
182
#define SA_SOURCE         5  
183
#define SA_SCOPE         6   
184
#define SA_CAST             7
185
#define SA_DEST             8
186
#define SA_IFNAME           9
187
#define SA_IFINDEX            10
188

    
189

    
190
struct f_tree {
191
  struct f_tree *left, *right;
192
  struct f_val from, to;
193
  void *data;
194
};
195

    
196
struct f_trie_node
197
{
198
  ip_addr addr, mask, accept;
199
  int plen;
200
  struct f_trie_node *c[2];
201
};
202

    
203
struct f_trie
204
{
205
  linpool *lp;
206
  int zero;
207
  uint node_size;
208
  struct f_trie_node root[0];                /* Root trie node follows */
209
};
210

    
211
#define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val));
212

    
213
#define FF_FORCE_TMPATTR 1                /* Force all attributes to be temporary */
214

    
215
#endif