]>
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" |
b9d70dc8 | 14 | |
b7005824 PM |
15 | struct f_inst { /* Instruction */ |
16 | struct f_inst *next; /* Structure is 16 bytes, anyway */ | |
c7b43f33 PM |
17 | u16 code; |
18 | u16 aux; | |
2db3b288 PM |
19 | union { |
20 | int i; | |
21 | void *p; | |
22 | } a1; | |
23 | union { | |
24 | int i; | |
25 | void *p; | |
26 | } a2; | |
b9d70dc8 PM |
27 | }; |
28 | ||
2db3b288 PM |
29 | #define arg1 a1.p |
30 | #define arg2 a2.p | |
31 | ||
23b1539b PM |
32 | struct prefix { |
33 | ip_addr ip; | |
34 | int len; | |
d3dd620b | 35 | #define LEN_MASK 0xff |
6dc7a0cb PM |
36 | #define LEN_PLUS 0x1000000 |
37 | #define LEN_MINUS 0x2000000 | |
38 | #define LEN_RANGE 0x4000000 | |
39 | /* If range then prefix must be in range (len >> 16 & 0xff, len >> 8 & 0xff) */ | |
23b1539b PM |
40 | }; |
41 | ||
b7005824 PM |
42 | struct f_val { |
43 | int type; | |
44 | union { | |
45 | int i; | |
6dc7a0cb | 46 | /* ip_addr ip; Folded into prefix */ |
2db3b288 | 47 | struct prefix px; |
23b1539b | 48 | char *s; |
38506f71 | 49 | struct f_tree *t; |
b7005824 PM |
50 | } val; |
51 | }; | |
52 | ||
e0f2e42f MM |
53 | struct filter { |
54 | char *name; | |
55 | struct f_inst *root; | |
56 | }; | |
57 | ||
ca3d562b | 58 | void filters_postconfig(void); |
b7005824 | 59 | struct f_inst *f_new_inst(void); |
38506f71 PM |
60 | struct f_tree *f_new_tree(void); |
61 | ||
62 | struct f_tree *build_tree(struct f_tree *); | |
63 | struct f_tree *find_tree(struct f_tree *t, struct f_val val); | |
84c7e194 | 64 | |
9a706f32 MM |
65 | struct ea_list; |
66 | struct rte; | |
67 | ||
63a381db MM |
68 | int f_run(struct filter *filter, struct rte **rte, struct ea_list **tmp_attrs, struct linpool *tmp_pool); |
69 | char *filter_name(struct filter *filter); | |
e0f2e42f | 70 | |
38506f71 PM |
71 | int val_compare(struct f_val v1, struct f_val v2); |
72 | void val_print(struct f_val v); | |
23b1539b PM |
73 | |
74 | #define F_NOP 0 | |
d3dd620b PM |
75 | #define F_NONL 1 |
76 | #define F_ACCEPT 2 /* Need to preserve ordering: accepts < rejects! */ | |
77 | #define F_MODIFY 3 /* FIXME: Introduce modification flags instead? */ | |
78 | #define F_REJECT 4 | |
79 | #define F_ERROR 5 | |
80 | #define F_QUITBIRD 6 | |
ca3d562b | 81 | |
63a381db MM |
82 | #define FILTER_ACCEPT NULL |
83 | #define FILTER_REJECT ((void *) 1) | |
84 | ||
ba921648 PM |
85 | /* Type numbers must be in 0..0xff range */ |
86 | #define T_MASK 0xff | |
87 | ||
88 | /* Internal types */ | |
c7b43f33 PM |
89 | /* Do not use type of zero, that way we'll see errors easier. */ |
90 | #define T_VOID 1 | |
91 | #define T_RETURN 2 | |
ba921648 PM |
92 | |
93 | /* User visible types, which fit in int */ | |
94 | #define T_INT 0x10 | |
95 | #define T_BOOL 0x11 | |
96 | #define T_PAIR 0x12 | |
f4536657 PM |
97 | |
98 | /* Put enumerational types in 0x30..0x7f range */ | |
99 | #define T_ENUM_LO 0x30 | |
100 | #define T_ENUM_HI 0x7f | |
101 | ||
cb8034f4 PM |
102 | #define T_ENUM_RTS 0x30 |
103 | ||
f4536657 | 104 | #define T_ENUM T_ENUM_LO ... T_ENUM_HI |
ba921648 PM |
105 | |
106 | /* Bigger ones */ | |
107 | #define T_IP 0x20 | |
108 | #define T_PREFIX 0x21 | |
109 | #define T_STRING 0x22 | |
110 | ||
111 | #define T_SET 0x80 | |
d36d838d | 112 | |
38506f71 PM |
113 | struct f_tree { |
114 | struct f_tree *left, *right; | |
115 | struct f_val from, to; | |
116 | void *data; | |
117 | }; | |
118 | ||
d3dd620b PM |
119 | #define NEW_F_VAL struct f_val * val; val = cfg_alloc(sizeof(struct f_val)); |
120 | ||
b9d70dc8 | 121 | #endif |