]>
Commit | Line | Data |
---|---|---|
9b46748d MM |
1 | /* |
2 | * BIRD Internet Routing Daemon -- Filter instructions | |
3 | * | |
8bdb05ed | 4 | * (c) 1999 Pavel Machek <pavel@ucw.cz> |
9b46748d MM |
5 | * (c) 2018--2019 Maria Matejka <mq@jmq.cz> |
6 | * | |
7 | * Can be freely distributed and used under the terms of the GNU GPL. | |
8 | */ | |
9 | ||
8bdb05ed MM |
10 | #ifndef _BIRD_F_INST_H_ |
11 | #define _BIRD_F_INST_H_ | |
12 | ||
13 | #include "filter/filter.h" | |
14 | #include "filter/f-util.h" | |
15 | ||
16 | /* Filter l-value type */ | |
17 | enum f_lval_type { | |
18 | F_LVAL_VARIABLE, | |
19 | F_LVAL_PREFERENCE, | |
20 | F_LVAL_SA, | |
21 | F_LVAL_EA, | |
22 | }; | |
23 | ||
24 | /* Filter l-value */ | |
25 | struct f_lval { | |
26 | enum f_lval_type type; | |
27 | union { | |
28 | const struct symbol *sym; | |
29 | struct f_dynamic_attr da; | |
30 | struct f_static_attr sa; | |
31 | }; | |
32 | }; | |
33 | ||
34 | /* Filter instruction declarations */ | |
9b46748d | 35 | #define FI__LIST \ |
8bdb05ed MM |
36 | F(FI_NOP) \ |
37 | F(FI_ADD, ARG, ARG) \ | |
38 | F(FI_SUBTRACT, ARG, ARG) \ | |
39 | F(FI_MULTIPLY, ARG, ARG) \ | |
40 | F(FI_DIVIDE, ARG, ARG) \ | |
41 | F(FI_AND, ARG, LINE) \ | |
42 | F(FI_OR, ARG, LINE) \ | |
43 | F(FI_PAIR_CONSTRUCT, ARG, ARG) \ | |
44 | F(FI_EC_CONSTRUCT, ARG, ARG, ECS) \ | |
45 | F(FI_LC_CONSTRUCT, ARG, ARG, ARG) \ | |
46 | F(FI_PATHMASK_CONSTRUCT, ARG, COUNT) \ | |
47 | F(FI_NEQ, ARG, ARG) \ | |
48 | F(FI_EQ, ARG, ARG) \ | |
49 | F(FI_LT, ARG, ARG) \ | |
50 | F(FI_LTE, ARG, ARG) \ | |
51 | F(FI_NOT, ARG) \ | |
52 | F(FI_MATCH, ARG, ARG) \ | |
53 | F(FI_NOT_MATCH, ARG, ARG) \ | |
54 | F(FI_DEFINED, ARG) \ | |
55 | F(FI_TYPE, ARG) \ | |
56 | F(FI_IS_V4, ARG) \ | |
57 | F(FI_SET, ARG, SYMBOL) \ | |
58 | F(FI_CONSTANT, VALI) \ | |
59 | F(FI_VARIABLE, SYMBOL) \ | |
60 | F(FI_CONSTANT_INDIRECT, VALP) \ | |
61 | F(FI_PRINT, ARG) \ | |
62 | F(FI_CONDITION, ARG, LINE, LINE) \ | |
63 | F(FI_PRINT_AND_DIE, ARG, FRET) \ | |
64 | F(FI_RTA_GET, SA) \ | |
65 | F(FI_RTA_SET, ARG, SA) \ | |
66 | F(FI_EA_GET, EA) \ | |
67 | F(FI_EA_SET, ARG, EA) \ | |
68 | F(FI_EA_UNSET, EA) \ | |
69 | F(FI_PREF_GET) \ | |
70 | F(FI_PREF_SET, ARG) \ | |
71 | F(FI_LENGTH, ARG) \ | |
72 | F(FI_ROA_MAXLEN, ARG) \ | |
73 | F(FI_ROA_ASN, ARG) \ | |
74 | F(FI_SADR_SRC, ARG) \ | |
75 | F(FI_IP, ARG) \ | |
76 | F(FI_ROUTE_DISTINGUISHER, ARG) \ | |
77 | F(FI_AS_PATH_FIRST, ARG) \ | |
78 | F(FI_AS_PATH_LAST, ARG) \ | |
79 | F(FI_AS_PATH_LAST_NAG, ARG) \ | |
80 | F(FI_RETURN, ARG) \ | |
81 | F(FI_CALL, SYMBOL, LINE) \ | |
82 | F(FI_DROP_RESULT, ARG) \ | |
83 | F(FI_SWITCH, ARG, TREE) \ | |
84 | F(FI_IP_MASK, ARG, ARG) \ | |
85 | F(FI_PATH_PREPEND, ARG, ARG) \ | |
86 | F(FI_CLIST_ADD, ARG, ARG) \ | |
87 | F(FI_CLIST_DEL, ARG, ARG) \ | |
88 | F(FI_CLIST_FILTER, ARG, ARG) \ | |
89 | F(FI_ROA_CHECK_IMPLICIT, RTC) \ | |
90 | F(FI_ROA_CHECK_EXPLICIT, ARG, ARG, RTC) \ | |
91 | F(FI_FORMAT, ARG) \ | |
92 | F(FI_ASSERT, ARG, STRING) | |
9b46748d MM |
93 | |
94 | /* The enum itself */ | |
95 | enum f_instruction_code { | |
8bdb05ed | 96 | #define F(c, ...) c, |
9b46748d MM |
97 | FI__LIST |
98 | #undef F | |
99 | FI__MAX, | |
100 | } PACKED; | |
101 | ||
102 | /* Convert the instruction back to the enum name */ | |
103 | const char *f_instruction_name(enum f_instruction_code fi); | |
104 | ||
8bdb05ed MM |
105 | struct f_inst; |
106 | void f_inst_next(struct f_inst *first, const struct f_inst *append); | |
107 | struct f_inst *f_clear_local_vars(struct f_inst *decls); | |
108 | ||
109 | #define FIA(x) , FIA_##x | |
110 | #define FIA_ARG const struct f_inst * | |
111 | #define FIA_LINE const struct f_inst * | |
112 | #define FIA_COUNT uint | |
113 | #define FIA_SYMBOL const struct symbol * | |
114 | #define FIA_VALI struct f_val | |
115 | #define FIA_VALP const struct f_val * | |
116 | #define FIA_FRET enum filter_return | |
117 | #define FIA_ECS enum ec_subtype | |
118 | #define FIA_SA struct f_static_attr | |
119 | #define FIA_EA struct f_dynamic_attr | |
120 | #define FIA_RTC const struct rtable_config * | |
121 | #define FIA_TREE const struct f_tree * | |
122 | #define FIA_STRING const char * | |
123 | #define F(c, ...) \ | |
124 | struct f_inst *f_new_inst_##c(enum f_instruction_code MACRO_IFELSE(MACRO_ISLAST(__VA_ARGS__))()(MACRO_FOREACH(FIA, __VA_ARGS__))); | |
125 | FI__LIST | |
126 | #undef F | |
127 | #undef FIA_ARG | |
128 | #undef FIA_LINE | |
129 | #undef FIA_LINEP | |
130 | #undef FIA_COUNT | |
131 | #undef FIA_SYMBOL | |
132 | #undef FIA_VALI | |
133 | #undef FIA_VALP | |
134 | #undef FIA_FRET | |
135 | #undef FIA_ECS | |
136 | #undef FIA_SA | |
137 | #undef FIA_EA | |
138 | #undef FIA_RTC | |
139 | #undef FIA_STRING | |
140 | #undef FIA | |
141 | ||
142 | #define f_new_inst(...) MACRO_CONCAT_AFTER(f_new_inst_, MACRO_FIRST(__VA_ARGS__))(__VA_ARGS__) | |
143 | ||
144 | /* Flags for instructions */ | |
145 | enum f_instruction_flags { | |
146 | FIF_PRINTED = 1, /* FI_PRINT_AND_DIE: message put in buffer */ | |
147 | }; | |
9b46748d | 148 | |
8bdb05ed MM |
149 | /* Filter structures for execution */ |
150 | struct f_line; | |
9b46748d | 151 | |
8bdb05ed MM |
152 | /* The single instruction item */ |
153 | struct f_line_item { | |
154 | enum f_instruction_code fi_code; /* What to do */ | |
155 | enum f_instruction_flags flags; /* Flags, instruction-specific */ | |
156 | uint lineno; /* Where */ | |
157 | union { | |
9b46748d | 158 | struct { |
8bdb05ed MM |
159 | const struct f_val *vp; |
160 | const struct symbol *sym; | |
9b46748d | 161 | }; |
8bdb05ed MM |
162 | struct f_val val; |
163 | const struct f_line *lines[2]; | |
164 | enum filter_return fret; | |
165 | struct f_static_attr sa; | |
166 | struct f_dynamic_attr da; | |
167 | enum ec_subtype ecs; | |
168 | const char *s; | |
169 | const struct f_tree *tree; | |
170 | const struct rtable_config *rtc; | |
171 | uint count; | |
172 | }; /* Additional instruction data */ | |
173 | }; | |
9b46748d | 174 | |
8bdb05ed MM |
175 | /* Line of instructions to be unconditionally executed one after another */ |
176 | struct f_line { | |
177 | uint len; /* Line length */ | |
178 | struct f_line_item items[0]; /* The items themselves */ | |
179 | }; | |
9b46748d | 180 | |
8bdb05ed MM |
181 | /* Convert the f_inst infix tree to the f_line structures */ |
182 | struct f_line *f_postfixify_concat(const struct f_inst * const inst[], uint count); | |
183 | static inline struct f_line *f_postfixify(const struct f_inst *root) | |
184 | { return f_postfixify_concat(&root, 1); } | |
185 | ||
186 | struct filter *f_new_where(const struct f_inst *); | |
187 | static inline struct f_dynamic_attr f_new_dynamic_attr(u8 type, u8 bit, enum f_type f_type, uint code) /* Type as core knows it, type as filters know it, and code of dynamic attribute */ | |
188 | { return (struct f_dynamic_attr) { .type = type, .bit = bit, .f_type = f_type, .ea_code = code }; } /* f_type currently unused; will be handy for static type checking */ | |
189 | static inline struct f_static_attr f_new_static_attr(int f_type, int code, int readonly) | |
190 | { return (struct f_static_attr) { .f_type = f_type, .sa_code = code, .readonly = readonly }; } | |
191 | struct f_inst *f_generate_complex(enum f_instruction_code fi_code, struct f_dynamic_attr da, struct f_inst *argument); | |
192 | struct f_inst *f_generate_roa_check(struct rtable_config *table, struct f_inst *prefix, struct f_inst *asn); | |
193 | ||
194 | /* Hook for call bt_assert() function in configuration */ | |
195 | extern void (*bt_assert_hook)(int result, const struct f_line_item *assert); | |
196 | ||
197 | /* Bird Tests */ | |
198 | struct f_bt_test_suite { | |
199 | node n; /* Node in config->tests */ | |
200 | struct f_line *fn; /* Root of function */ | |
201 | const char *fn_name; /* Name of test */ | |
202 | const char *dsc; /* Description */ | |
9b46748d MM |
203 | }; |
204 | ||
8bdb05ed MM |
205 | /* Include the auto-generated structures */ |
206 | #include "filter/f-inst-struct.h" | |
207 | ||
208 | #endif |