]> git.ipfire.org Git - thirdparty/bird.git/blame - filter/config.Y
Filter: fixed error-checking bug in !~ operator
[thirdparty/bird.git] / filter / config.Y
CommitLineData
b9d70dc8
PM
1/*
2 * BIRD - filters
3 *
1c20608e 4 * Copyright 1998--2000 Pavel Machek
b9d70dc8
PM
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
c9f8c1a8 7 *
1877dab2 8 FIXME: priority of ! should be lower
b9d70dc8
PM
9 */
10
11CF_HDR
12
8bdb05ed 13#include "filter/f-inst.h"
4f082dfa 14#include "filter/data.h"
8bdb05ed 15
2edb31b0
MM
16CF_DEFINES
17
b8cc390e
OZ
18static inline u32 pair(u32 a, u32 b) { return (a << 16) | b; }
19static inline u32 pair_a(u32 p) { return p >> 16; }
20static inline u32 pair_b(u32 p) { return p & 0xFFFF; }
21
9b46748d 22#define f_generate_complex(fi_code, da, arg) \
c0e958e0 23 f_new_inst(FI_EA_SET, f_new_inst(fi_code, f_new_inst(FI_EA_GET, da), arg), da)
b8cc390e
OZ
24
25/*
26 * Sets and their items are during parsing handled as lists, linked
27 * through left ptr. The first item in a list also contains a pointer
28 * to the last item in a list (right ptr). For convenience, even items
29 * are handled as one-item lists. Lists are merged by f_merge_items().
30 */
b2f00837
OZ
31static int
32f_valid_set_type(int type)
33{
34 switch (type)
35 {
36 case T_INT:
37 case T_PAIR:
38 case T_QUAD:
39 case T_ENUM:
40 case T_IP:
41 case T_EC:
66dbdbd9 42 case T_LC:
83715aa8 43 case T_RD:
b2f00837
OZ
44 return 1;
45
46 default:
47 return 0;
48 }
49}
b8cc390e
OZ
50
51static inline struct f_tree *
52f_new_item(struct f_val from, struct f_val to)
92a72a4c 53{
b8cc390e
OZ
54 struct f_tree *t = f_new_tree();
55 t->right = t;
56 t->from = from;
57 t->to = to;
58 return t;
59}
92a72a4c 60
b8cc390e
OZ
61static inline struct f_tree *
62f_merge_items(struct f_tree *a, struct f_tree *b)
63{
64 if (!a) return b;
65 a->right->left = b;
66 a->right = b->right;
67 b->right = NULL;
68 return a;
69}
92a72a4c 70
b8cc390e
OZ
71static inline struct f_tree *
72f_new_pair_item(int fa, int ta, int fb, int tb)
73{
60566c5c
OZ
74 check_u16(fa);
75 check_u16(ta);
76 check_u16(fb);
77 check_u16(tb);
78
79 if ((ta < fa) || (tb < fb))
80 cf_error( "From value cannot be higher that To value in pair sets");
81
b8cc390e
OZ
82 struct f_tree *t = f_new_tree();
83 t->right = t;
84 t->from.type = t->to.type = T_PAIR;
85 t->from.val.i = pair(fa, fb);
86 t->to.val.i = pair(ta, tb);
87 return t;
92a72a4c
OZ
88}
89
b8cc390e
OZ
90static inline struct f_tree *
91f_new_pair_set(int fa, int ta, int fb, int tb)
4fc36f39 92{
60566c5c
OZ
93 check_u16(fa);
94 check_u16(ta);
95 check_u16(fb);
96 check_u16(tb);
c454872f 97
b8cc390e
OZ
98 if ((ta < fa) || (tb < fb))
99 cf_error( "From value cannot be higher that To value in pair sets");
c454872f 100
60566c5c
OZ
101 struct f_tree *lst = NULL;
102 int i;
103
b8cc390e
OZ
104 for (i = fa; i <= ta; i++)
105 lst = f_merge_items(lst, f_new_pair_item(i, i, fb, tb));
106
107 return lst;
4fc36f39
OF
108}
109
60566c5c 110#define CC_ALL 0xFFFF
42a0c054 111#define EC_ALL 0xFFFFFFFF
60566c5c 112#define LC_ALL 0xFFFFFFFF
42a0c054
OZ
113
114static struct f_tree *
115f_new_ec_item(u32 kind, u32 ipv4_used, u32 key, u32 vf, u32 vt)
116{
117 u64 fm, to;
118
e46128fb 119 if ((kind != EC_GENERIC) && (ipv4_used || (key >= 0x10000))) {
42a0c054
OZ
120 check_u16(vf);
121 if (vt == EC_ALL)
122 vt = 0xFFFF;
123 else
124 check_u16(vt);
125 }
126
127 if (kind == EC_GENERIC) {
128 fm = ec_generic(key, vf);
129 to = ec_generic(key, vt);
130 }
131 else if (ipv4_used) {
132 fm = ec_ip4(kind, key, vf);
133 to = ec_ip4(kind, key, vt);
134 }
135 else if (key < 0x10000) {
136 fm = ec_as2(kind, key, vf);
137 to = ec_as2(kind, key, vt);
138 }
139 else {
140 fm = ec_as4(kind, key, vf);
141 to = ec_as4(kind, key, vt);
142 }
143
144 struct f_tree *t = f_new_tree();
145 t->right = t;
146 t->from.type = t->to.type = T_EC;
147 t->from.val.ec = fm;
148 t->to.val.ec = to;
149 return t;
150}
151
60566c5c
OZ
152static struct f_tree *
153f_new_lc_item(u32 f1, u32 t1, u32 f2, u32 t2, u32 f3, u32 t3)
154{
155 struct f_tree *t = f_new_tree();
156 t->right = t;
157 t->from.type = t->to.type = T_LC;
158 t->from.val.lc = (lcomm) {f1, f2, f3};
159 t->to.val.lc = (lcomm) {t1, t2, t3};
160 return t;
161}
162
42a0c054 163static inline struct f_inst *
5a14df39 164f_generate_empty(struct f_dynamic_attr dyn)
5e173e9f 165{
9b46748d 166 struct f_val empty;
42a0c054 167
5a14df39 168 switch (dyn.type & EAF_TYPE_MASK) {
42a0c054 169 case EAF_TYPE_AS_PATH:
9b46748d 170 empty = f_const_empty_path;
42a0c054
OZ
171 break;
172 case EAF_TYPE_INT_SET:
9b46748d 173 empty = f_const_empty_clist;
42a0c054
OZ
174 break;
175 case EAF_TYPE_EC_SET:
9b46748d 176 empty = f_const_empty_eclist;
42a0c054 177 break;
66dbdbd9 178 case EAF_TYPE_LC_SET:
9b46748d 179 empty = f_const_empty_lclist;
66dbdbd9 180 break;
42a0c054
OZ
181 default:
182 cf_error("Can't empty that attribute");
183 }
184
c0e958e0 185 return f_new_inst(FI_EA_SET, f_new_inst(FI_CONSTANT, empty), dyn);
42a0c054
OZ
186}
187
9b46748d 188#if 0
42a0c054
OZ
189
190static inline struct f_inst *
191f_generate_dpair(struct f_inst *t1, struct f_inst *t2)
192{
193 struct f_inst *rv;
194
5a14df39 195 if ((t1->fi_code == FI_CONSTANT) && (t2->fi_code == FI_CONSTANT)) {
ca2ee91a 196 if ((t1->val.type != T_INT) || (t2->val.type != T_INT))
42a0c054
OZ
197 cf_error( "Can't operate with value of non-integer type in pair constructor");
198
7f0ac737
MM
199 check_u16(t1->a[1].i);
200 check_u16(t2->a[1].i);
42a0c054 201
5a14df39 202 rv = f_new_inst(FI_CONSTANT);
ca2ee91a
MM
203 rv->val = (struct f_val) {
204 .type = T_PAIR,
205 .val.i = pair(t1->a[1].i, t2->a[1].i),
206 };
42a0c054
OZ
207 }
208 else {
5a14df39 209 rv = f_new_inst(FI_PAIR_CONSTRUCT);
7f0ac737
MM
210 rv->a[0].p = t1;
211 rv->a[1].p = t2;
42a0c054
OZ
212 }
213
214 return rv;
215}
216
217static inline struct f_inst *
218f_generate_ec(u16 kind, struct f_inst *tk, struct f_inst *tv)
219{
220 struct f_inst *rv;
221 int c1 = 0, c2 = 0, ipv4_used = 0;
222 u32 key = 0, val2 = 0;
223
5a14df39 224 if (tk->fi_code == FI_CONSTANT) {
42a0c054 225 c1 = 1;
ca2ee91a 226 struct f_val *val = &(tk->val);
1103b32e
OZ
227
228 if (val->type == T_INT) {
229 ipv4_used = 0; key = val->val.i;
230 }
ca2ee91a 231 else if (tk->val.type == T_QUAD) {
1103b32e
OZ
232 ipv4_used = 1; key = val->val.i;
233 }
5e173e9f
JMM
234 else if ((val->type == T_IP) && ipa_is_ip4(val->val.ip)) {
235 ipv4_used = 1; key = ipa_to_u32(val->val.ip);
42a0c054
OZ
236 }
237 else
238 cf_error("Can't operate with key of non-integer/IPv4 type in EC constructor");
239 }
42a0c054 240
5a14df39 241 if (tv->fi_code == FI_CONSTANT) {
ca2ee91a 242 if (tv->val.type != T_INT)
42a0c054
OZ
243 cf_error("Can't operate with value of non-integer type in EC constructor");
244 c2 = 1;
ca2ee91a 245 val2 = tv->val.val.i;
42a0c054
OZ
246 }
247
248 if (c1 && c2) {
249 u64 ec;
5e173e9f 250
42a0c054
OZ
251 if (kind == EC_GENERIC) {
252 ec = ec_generic(key, val2);
253 }
254 else if (ipv4_used) {
255 check_u16(val2);
256 ec = ec_ip4(kind, key, val2);
257 }
258 else if (key < 0x10000) {
259 ec = ec_as2(kind, key, val2);
260 }
261 else {
262 check_u16(val2);
263 ec = ec_as4(kind, key, val2);
264 }
265
ca2ee91a
MM
266 rv = f_new_inst(FI_CONSTANT);
267 rv->val = (struct f_val) {
268 .type = T_EC,
269 .val.ec = ec,
270 };
42a0c054
OZ
271 }
272 else {
5a14df39 273 rv = f_new_inst(FI_EC_CONSTRUCT);
42a0c054 274 rv->aux = kind;
7f0ac737
MM
275 rv->a[0].p = tk;
276 rv->a[1].p = tv;
42a0c054
OZ
277 }
278
279 return rv;
78e33c29 280}
42a0c054 281
66dbdbd9
OZ
282static inline struct f_inst *
283f_generate_lc(struct f_inst *t1, struct f_inst *t2, struct f_inst *t3)
284{
285 struct f_inst *rv;
286
5a14df39 287 if ((t1->fi_code == FI_CONSTANT) && (t2->fi_code == FI_CONSTANT) && (t3->fi_code == FI_CONSTANT)) {
ca2ee91a 288 if ((t1->val.type != T_INT) || (t2->val.type != T_INT) || (t3->val.type != T_INT))
66dbdbd9
OZ
289 cf_error( "LC - Can't operate with value of non-integer type in tuple constructor");
290
ca2ee91a
MM
291 rv = f_new_inst(FI_CONSTANT);
292 rv->val = (struct f_val) {
293 .type = T_LC,
294 .val.lc = (lcomm) { t1->a[1].i, t2->a[1].i, t3->a[1].i },
295 };
66dbdbd9
OZ
296 }
297 else
298 {
478f9bab 299 rv = f_new_inst(FI_LC_CONSTRUCT);
7f0ac737
MM
300 rv->a[0].p = t1;
301 rv->a[1].p = t2;
302 rv->a[2].p = t3;
66dbdbd9
OZ
303 }
304
305 return rv;
306}
307
e8bc64e3 308static inline struct f_inst *
4c553c5a 309f_generate_path_mask(struct f_inst *t)
e8bc64e3 310{
4c553c5a
MM
311 uint len = 0;
312 uint dyn = 0;
313 for (const struct f_inst *tt = t; tt; tt = tt->next) {
314 if (tt->fi_code != FI_CONSTANT)
315 dyn++;
316 len++;
317 }
318
319 if (dyn) {
320 struct f_inst *pmc = f_new_inst(FI_PATHMASK_CONSTRUCT);
321 pmc->a[0].p = t;
322 pmc->a[1].i = len;
323 return pmc;
e8bc64e3
JMM
324 }
325
4c553c5a 326 struct f_path_mask *pm = cfg_allocz(sizeof(struct f_path_mask) + len * sizeof(struct f_path_mask_item));
e8bc64e3 327
4c553c5a
MM
328 uint i = 0;
329 for (const struct f_inst *tt = t; tt; tt = tt->next)
330 pm->item[i++] = tt->val.val.pmi;
331
332 pm->len = i;
333 struct f_inst *pmc = f_new_inst(FI_CONSTANT);
334 pmc->val = (struct f_val) { .type = T_PATH_MASK, .val.path_mask = pm, };
335
336 return pmc;
e8bc64e3 337}
42a0c054 338
9b46748d
MM
339#endif
340
9b0a0ba9
OZ
341/*
342 * Remove all new lines and doubled whitespaces
343 * and convert all tabulators to spaces
344 * and return a copy of string
345 */
346char *
347assert_copy_expr(const char *start, size_t len)
348{
349 /* XXX: Allocates maybe a little more memory than we really finally need */
350 char *str = cfg_alloc(len + 1);
351
352 char *dst = str;
353 const char *src = start - 1;
354 const char *end = start + len;
355 while (++src < end)
356 {
357 if (*src == '\n')
358 continue;
359
360 /* Skip doubled whitespaces */
361 if (src != start)
362 {
363 const char *prev = src - 1;
364 if ((*src == ' ' || *src == '\t') && (*prev == ' ' || *prev == '\t'))
365 continue;
366 }
367
368 if (*src == '\t')
369 *dst = ' ';
370 else
371 *dst = *src;
372
373 dst++;
374 }
375 *dst = '\0';
376
377 return str;
378}
379
380/*
381 * assert_done - create f_instruction of bt_assert
382 * @expr: expression in bt_assert()
383 * @start: pointer to first char of test expression
384 * @end: pointer to the last char of test expression
385 */
386static struct f_inst *
387assert_done(struct f_inst *expr, const char *start, const char *end)
388{
9b46748d
MM
389 return f_new_inst(FI_ASSERT, expr,
390 (end >= start) ?
391 assert_copy_expr(start, end - start + 1)
392 : "???");
9b0a0ba9 393}
42a0c054 394
c0e958e0
MM
395static struct f_inst *
396assert_assign(struct f_lval *lval, struct f_inst *expr, const char *start, const char *end)
397{
398 struct f_inst *setter, *getter, *checker;
399 switch (lval->type) {
400 case F_LVAL_VARIABLE:
401 setter = f_new_inst(FI_SET, expr, lval->sym);
402 getter = f_new_inst(FI_VARIABLE, lval->sym);
403 break;
404 case F_LVAL_PREFERENCE:
405 setter = f_new_inst(FI_PREF_SET, expr);
406 getter = f_new_inst(FI_PREF_GET);
407 break;
408 case F_LVAL_SA:
409 setter = f_new_inst(FI_RTA_SET, expr, lval->sa);
410 getter = f_new_inst(FI_RTA_GET, lval->sa);
411 break;
412 case F_LVAL_EA:
413 setter = f_new_inst(FI_EA_SET, expr, lval->da);
414 getter = f_new_inst(FI_EA_GET, lval->da);
415 break;
416 default:
417 bug("Unknown lval type");
418 }
419
420 checker = f_new_inst(FI_EQ, expr, getter);
4f082dfa 421 setter->next = checker;
c0e958e0
MM
422
423 return assert_done(setter, start, end);
424}
425
b9d70dc8
PM
426CF_DECLS
427
e4a73dbf 428CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
ba921648 429 ACCEPT, REJECT, ERROR, QUITBIRD,
8c9986d3 430 INT, BOOL, IP, TYPE, PREFIX, RD, PAIR, QUAD, EC, LC,
66dbdbd9 431 SET, STRING, BGPMASK, BGPPATH, CLIST, ECLIST, LCLIST,
7db7b7db 432 IF, THEN, ELSE, CASE,
42a0c054 433 TRUE, FALSE, RT, RO, UNKNOWN, GENERIC,
5b208e29 434 FROM, GW, NET, MASK, PROTO, SOURCE, SCOPE, DEST, IFNAME, IFINDEX,
a5fc5958 435 PREFERENCE,
b24b7811 436 ROA_CHECK, ASN, SRC,
61e501da 437 IS_V4, IS_V6,
e58f8c28 438 LEN, MAXLEN,
f4536657 439 DEFINED,
7f77e250 440 ADD, DELETE, CONTAINS, RESET,
9c9cc35c 441 PREPEND, FIRST, LAST, LAST_NONAGGREGATED, MATCH,
afc54517 442 EMPTY,
265419a3 443 FILTER, WHERE, EVAL, ATTRIBUTE,
132529ce 444 BT_ASSERT, BT_TEST_SUITE, BT_CHECK_ASSIGN, BT_TEST_SAME, FORMAT)
b9d70dc8 445
f4536657 446%nonassoc THEN
4ed8718a 447%nonassoc ELSE
f4536657 448
32793ab6 449%type <xp> cmds_int function_body declsn function_params
c0e958e0 450%type <x> term block cmd cmds constant constructor print_one print_list var_list var_listn function_call symbol_value bgp_path_expr bgp_path bgp_path_tail one_decl decls
5a14df39
MJM
451%type <fda> dynamic_attr
452%type <fsa> static_attr
0b39b1cb
MM
453%type <f> filter where_filter
454%type <fl> filter_body
c0e958e0 455%type <flv> lvalue
9b46748d
MM
456%type <i> type
457%type <ecs> ec_kind
458%type <fret> break_command
60566c5c
OZ
459%type <i32> cnum
460%type <e> pair_item ec_item lc_item set_item switch_item set_items switch_items switch_body
b1a597e0 461%type <trie> fprefix_set
5e173e9f
JMM
462%type <v> set_atom switch_atom fipa
463%type <px> fprefix
9b0a0ba9 464%type <t> get_cf_position
b9d70dc8
PM
465
466CF_GRAMMAR
467
f851f0d7 468conf: filter_def ;
e0f2e42f 469filter_def:
0b39b1cb 470 FILTER CF_SYM_VOID { $2 = cf_define_symbol($2, SYM_FILTER, filter, NULL); cf_push_scope( $2 ); }
b2b7bbfc 471 filter_body {
0b39b1cb 472 struct filter *f = cfg_alloc(sizeof(struct filter));
f249d0b8 473 *f = (struct filter) { .sym = $2, .root = $4 };
0b39b1cb
MM
474 $2->filter = f;
475
ae3e1af2 476 cf_pop_scope();
b9d70dc8
PM
477 }
478 ;
479
f851f0d7 480conf: filter_eval ;
1c20608e 481filter_eval:
4c553c5a 482 EVAL term { f_eval_int(f_postfixify($2)); }
1c20608e
MM
483 ;
484
265419a3 485conf: custom_attr ;
c0e958e0 486custom_attr: ATTRIBUTE type CF_SYM_VOID ';' {
0b39b1cb 487 cf_define_symbol($3, SYM_ATTRIBUTE, attribute, ca_lookup(new_config->pool, $3->name, $2)->fda);
265419a3
MM
488};
489
f851f0d7 490conf: bt_test_suite ;
9b0a0ba9 491bt_test_suite:
c0e958e0 492 BT_TEST_SUITE '(' CF_SYM_FUNCTION ',' text ')' {
132529ce 493 struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite));
0b39b1cb 494 t->fn = $3->function;
9b0a0ba9
OZ
495 t->fn_name = $3->name;
496 t->dsc = $5;
497
498 add_tail(&new_config->tests, &t->n);
499 }
500 ;
501
132529ce
MM
502conf: bt_test_same ;
503bt_test_same:
504 BT_TEST_SAME '(' CF_SYM_FUNCTION ',' CF_SYM_FUNCTION ',' NUM ')' {
505 struct f_bt_test_suite *t = cfg_allocz(sizeof(struct f_bt_test_suite));
0b39b1cb
MM
506 t->fn = $3->function;
507 t->cmp = $5->function;
132529ce
MM
508 t->result = $7;
509 t->fn_name = $3->name;
510 t->dsc = $5->name;
511 add_tail(&new_config->tests, &t->n);
512 }
513 ;
514
ba921648
PM
515type:
516 INT { $$ = T_INT; }
517 | BOOL { $$ = T_BOOL; }
518 | IP { $$ = T_IP; }
8c9986d3 519 | RD { $$ = T_RD; }
5e173e9f 520 | PREFIX { $$ = T_NET; }
ba921648 521 | PAIR { $$ = T_PAIR; }
126683fe 522 | QUAD { $$ = T_QUAD; }
42a0c054 523 | EC { $$ = T_EC; }
66dbdbd9 524 | LC { $$ = T_LC; }
ba921648 525 | STRING { $$ = T_STRING; }
10a53608
PM
526 | BGPMASK { $$ = T_PATH_MASK; }
527 | BGPPATH { $$ = T_PATH; }
528 | CLIST { $$ = T_CLIST; }
42a0c054 529 | ECLIST { $$ = T_ECLIST; }
66dbdbd9 530 | LCLIST { $$ = T_LCLIST; }
c8cafc8e 531 | type SET {
ba921648 532 switch ($1) {
b1a597e0 533 case T_INT:
b1a597e0 534 case T_PAIR:
126683fe 535 case T_QUAD:
42a0c054 536 case T_EC:
66dbdbd9 537 case T_LC:
83715aa8 538 case T_RD:
126683fe 539 case T_IP:
b1a597e0
OZ
540 $$ = T_SET;
541 break;
542
5e173e9f 543 case T_NET:
b1a597e0
OZ
544 $$ = T_PREFIX_SET;
545 break;
546
ba921648 547 default:
a5a947d4 548 cf_error( "You can't create sets of this type." );
ba921648 549 }
b1a597e0 550 }
ba921648
PM
551 ;
552
6dc7a0cb 553one_decl:
c0e958e0 554 type CF_SYM_VOID {
4ee39ff2
OZ
555 struct f_val * val = cfg_alloc(sizeof(struct f_val));
556 val->type = T_VOID;
0b39b1cb 557 $2 = cf_define_symbol($2, SYM_VARIABLE | $1, val, val);
d4d75628 558 DBG( "New variable %s type %x\n", $2->name, $1 );
9b46748d 559 $$ = f_new_inst(FI_SET, NULL, $2);
ba921648
PM
560 }
561 ;
562
32793ab6 563/* Decls with ';' at the end. Beware; these are reversed. */
6dc7a0cb
PM
564decls: /* EMPTY */ { $$ = NULL; }
565 | one_decl ';' decls {
566 $$ = $1;
4f082dfa 567 $$->next = $3;
6dc7a0cb
PM
568 }
569 ;
570
32793ab6
MM
571/* Declarations that have no ';' at the end. */
572declsn: one_decl { $$[0] = $$[1] = $1; }
736fd730 573 | one_decl ';' declsn {
32793ab6
MM
574 $3[1]->next = $1;
575 $$[1] = $3[1] = $1;
576 $$[0] = $3[0];
6dc7a0cb
PM
577 }
578 ;
579
e0f2e42f 580filter_body:
ba921648 581 function_body {
9b46748d
MM
582 if ($1[0]) {
583 const struct f_inst *inst[2] = { $1[0], $1[1] };
0b39b1cb 584 $$ = f_postfixify_concat(inst, 2);
9b46748d
MM
585 }
586 else
0b39b1cb 587 $$ = f_postfixify($1[1]);
e0f2e42f
MM
588 }
589 ;
590
591filter:
c0e958e0 592 CF_SYM_FILTER {
0b39b1cb
MM
593 $$ = $1->filter;
594 }
595 | filter_body {
596 struct filter *f = cfg_alloc(sizeof(struct filter));
597 *f = (struct filter) { .root = $1 };
598 $$ = f;
e0f2e42f 599 }
e0f2e42f
MM
600 ;
601
430da60f
MM
602where_filter:
603 WHERE term {
224b77d4 604 /* Construct 'IF term THEN { ACCEPT; } ELSE { REJECT; }' */
9b46748d 605 $$ = f_new_where($2);
4c553c5a 606 }
430da60f
MM
607 ;
608
ba921648 609function_params:
32793ab6
MM
610 '(' declsn ')' { $$[0] = $2[0]; $$[1] = $2[1]; }
611 | '(' ')' { $$[0] = $$[1] = NULL; }
ba921648 612 ;
b9d70dc8 613
ba921648
PM
614function_body:
615 decls '{' cmds '}' {
9b46748d
MM
616 $$[0] = $1 ? f_clear_local_vars($1) : NULL;
617 $$[1] = $3;
84c7e194 618 }
ba921648
PM
619 ;
620
f851f0d7 621conf: function_def ;
ba921648 622function_def:
c0e958e0 623 FUNCTION CF_SYM_VOID { DBG( "Beginning of function %s\n", $2->name );
0b39b1cb 624 $2 = cf_define_symbol($2, SYM_FUNCTION, function, NULL);
bf3eb98e
MM
625 cf_push_scope($2);
626 } function_params function_body {
9b46748d
MM
627 const struct f_inst *catlist[4];
628 uint count = 0;
629
630 /* Argument setters */
32793ab6
MM
631 if ($4[0])
632 catlist[count++] = $4[0];
9b46748d
MM
633
634 /* Local var clearers */
635 if ($5[0])
636 catlist[count++] = $5[0];
637
638 /* Return void if no return is needed */
639 catlist[count++] = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_VOID });
640
641 /* Function body itself */
642 if ($5[1])
643 catlist[count++] = $5[1];
644
0b39b1cb 645 struct f_line *fl = f_postfixify_concat(catlist, count);
32793ab6
MM
646
647 fl->args = 0;
648 for (const struct f_inst *arg = $4[0]; arg; arg = arg->next)
649 fl->args++;
650
0b39b1cb
MM
651 $2->function = fl;
652
ae3e1af2 653 cf_pop_scope();
ba921648
PM
654 }
655 ;
656
657/* Programs */
658
659cmds: /* EMPTY */ { $$ = NULL; }
9b46748d 660 | cmds_int { $$ = $1[0]; }
5f47c4c1
OZ
661 ;
662
9b46748d 663cmds_int: cmd { $$[0] = $$[1] = $1; }
4f082dfa 664 | cmds_int cmd { $$[1] = $2; $1[1]->next = $2; $$[0] = $1[0]; }
84c7e194
PM
665 ;
666
2575593e 667block:
ba921648 668 cmd {
2575593e
PM
669 $$=$1;
670 }
671 | '{' cmds '}' {
672 $$=$2;
673 }
674 ;
675
d3dd620b
PM
676/*
677 * Complex types, their bison value is struct f_val
678 */
e3f2d5fc 679fipa:
04632fd7
OZ
680 IP4 %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = ipa_from_ip4($1); }
681 | IP6 %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = ipa_from_ip6($1); }
d3dd620b
PM
682 ;
683
b8cc390e
OZ
684
685
686/*
687 * Set constants. They are also used in switch cases. We use separate
688 * nonterminals for switch (set_atom/switch_atom, set_item/switch_item ...)
689 * to elude a collision between symbol (in expr) in set_atom and symbol
690 * as a function call in switch case cmds.
691 */
692
38506f71 693set_atom:
83715aa8
OZ
694 NUM { $$.type = T_INT; $$.val.i = $1; }
695 | fipa { $$ = $1; }
696 | VPN_RD { $$.type = T_RD; $$.val.ec = $1; }
697 | ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
b2f00837 698 | '(' term ')' {
4c553c5a 699 if (f_eval(f_postfixify($2), cfg_mem, &($$)) > F_RETURN) cf_error("Runtime error");
b2f00837
OZ
700 if (!f_valid_set_type($$.type)) cf_error("Set-incompatible type");
701 }
c0e958e0 702 | CF_SYM_CONSTANT {
b2f00837 703 if (!f_valid_set_type(SYM_TYPE($1))) cf_error("%s: set-incompatible type", $1->name);
0b39b1cb 704 $$ = *$1->val;
b2f00837 705 }
b8cc390e 706 ;
38506f71 707
b8cc390e
OZ
708switch_atom:
709 NUM { $$.type = T_INT; $$.val.i = $1; }
4c553c5a 710 | '(' term ')' { $$.type = T_INT; $$.val.i = f_eval_int(f_postfixify($2)); }
b8cc390e
OZ
711 | fipa { $$ = $1; }
712 | ENUM { $$.type = pair_a($1); $$.val.i = pair_b($1); }
713 ;
714
60566c5c 715cnum:
4c553c5a 716 term { $$ = f_eval_int(f_postfixify($1)); }
b8cc390e
OZ
717
718pair_item:
60566c5c
OZ
719 '(' cnum ',' cnum ')' { $$ = f_new_pair_item($2, $2, $4, $4); }
720 | '(' cnum ',' cnum DDOT cnum ')' { $$ = f_new_pair_item($2, $2, $4, $6); }
721 | '(' cnum ',' '*' ')' { $$ = f_new_pair_item($2, $2, 0, CC_ALL); }
722 | '(' cnum DDOT cnum ',' cnum ')' { $$ = f_new_pair_set($2, $4, $6, $6); }
723 | '(' cnum DDOT cnum ',' cnum DDOT cnum ')' { $$ = f_new_pair_set($2, $4, $6, $8); }
724 | '(' cnum DDOT cnum ',' '*' ')' { $$ = f_new_pair_item($2, $4, 0, CC_ALL); }
725 | '(' '*' ',' cnum ')' { $$ = f_new_pair_set(0, CC_ALL, $4, $4); }
726 | '(' '*' ',' cnum DDOT cnum ')' { $$ = f_new_pair_set(0, CC_ALL, $4, $6); }
727 | '(' '*' ',' '*' ')' { $$ = f_new_pair_item(0, CC_ALL, 0, CC_ALL); }
728 | '(' cnum ',' cnum ')' DDOT '(' cnum ',' cnum ')'
729 { $$ = f_new_pair_item($2, $8, $4, $10); }
38506f71
PM
730 ;
731
42a0c054
OZ
732ec_kind:
733 RT { $$ = EC_RT; }
734 | RO { $$ = EC_RO; }
735 | UNKNOWN NUM { $$ = $2; }
736 | GENERIC { $$ = EC_GENERIC; }
737 ;
738
739ec_item:
60566c5c
OZ
740 '(' ec_kind ',' cnum ',' cnum ')' { $$ = f_new_ec_item($2, 0, $4, $6, $6); }
741 | '(' ec_kind ',' cnum ',' cnum DDOT cnum ')' { $$ = f_new_ec_item($2, 0, $4, $6, $8); }
742 | '(' ec_kind ',' cnum ',' '*' ')' { $$ = f_new_ec_item($2, 0, $4, 0, EC_ALL); }
42a0c054
OZ
743 ;
744
60566c5c
OZ
745lc_item:
746 '(' cnum ',' cnum ',' cnum ')' { $$ = f_new_lc_item($2, $2, $4, $4, $6, $6); }
747 | '(' cnum ',' cnum ',' cnum DDOT cnum ')' { $$ = f_new_lc_item($2, $2, $4, $4, $6, $8); }
748 | '(' cnum ',' cnum ',' '*' ')' { $$ = f_new_lc_item($2, $2, $4, $4, 0, LC_ALL); }
749 | '(' cnum ',' cnum DDOT cnum ',' '*' ')' { $$ = f_new_lc_item($2, $2, $4, $6, 0, LC_ALL); }
750 | '(' cnum ',' '*' ',' '*' ')' { $$ = f_new_lc_item($2, $2, 0, LC_ALL, 0, LC_ALL); }
751 | '(' cnum DDOT cnum ',' '*' ',' '*' ')' { $$ = f_new_lc_item($2, $4, 0, LC_ALL, 0, LC_ALL); }
752 | '(' '*' ',' '*' ',' '*' ')' { $$ = f_new_lc_item(0, LC_ALL, 0, LC_ALL, 0, LC_ALL); }
753 | '(' cnum ',' cnum ',' cnum ')' DDOT '(' cnum ',' cnum ',' cnum ')'
754 { $$ = f_new_lc_item($2, $10, $4, $12, $6, $14); }
755;
42a0c054 756
b8cc390e
OZ
757set_item:
758 pair_item
42a0c054 759 | ec_item
60566c5c 760 | lc_item
b8cc390e
OZ
761 | set_atom { $$ = f_new_item($1, $1); }
762 | set_atom DDOT set_atom { $$ = f_new_item($1, $3); }
763 ;
764
765switch_item:
766 pair_item
42a0c054 767 | ec_item
60566c5c 768 | lc_item
b8cc390e
OZ
769 | switch_atom { $$ = f_new_item($1, $1); }
770 | switch_atom DDOT switch_atom { $$ = f_new_item($1, $3); }
771 ;
772
38506f71 773set_items:
b8cc390e
OZ
774 set_item
775 | set_items ',' set_item { $$ = f_merge_items($1, $3); }
776 ;
777
778switch_items:
779 switch_item
780 | switch_items ',' switch_item { $$ = f_merge_items($1, $3); }
38506f71
PM
781 ;
782
b1a597e0 783fprefix:
04632fd7
OZ
784 net_ip_ { $$.net = $1; $$.lo = $1.pxlen; $$.hi = $1.pxlen; }
785 | net_ip_ '+' { $$.net = $1; $$.lo = $1.pxlen; $$.hi = net_max_prefix_length[$1.type]; }
786 | net_ip_ '-' { $$.net = $1; $$.lo = 0; $$.hi = $1.pxlen; }
787 | net_ip_ '{' NUM ',' NUM '}' {
5e173e9f 788 $$.net = $1; $$.lo = $3; $$.hi = $5;
6aaaa635
OZ
789 if (($3 > $5) || ($5 > net_max_prefix_length[$1.type]))
790 cf_error("Invalid prefix pattern range: {%u, %u}", $3, $5);
b1a597e0
OZ
791 }
792 ;
793
794fprefix_set:
04632fd7
OZ
795 fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_prefix($$, &($1.net), $1.lo, $1.hi); }
796 | fprefix_set ',' fprefix { $$ = $1; trie_add_prefix($$, &($3.net), $3.lo, $3.hi); }
b1a597e0
OZ
797 ;
798
41be4444 799switch_body: /* EMPTY */ { $$ = NULL; }
b8cc390e
OZ
800 | switch_body switch_items ':' cmds {
801 /* Fill data fields */
802 struct f_tree *t;
4c553c5a 803 struct f_line *line = f_postfixify($4);
b8cc390e 804 for (t = $2; t; t = t->left)
4c553c5a 805 t->data = line;
b8cc390e 806 $$ = f_merge_items($1, $2);
41be4444 807 }
5e173e9f 808 | switch_body ELSECOL cmds {
b8cc390e
OZ
809 struct f_tree *t = f_new_tree();
810 t->from.type = t->to.type = T_VOID;
811 t->right = t;
4c553c5a 812 t->data = f_postfixify($3);
b8cc390e
OZ
813 $$ = f_merge_items($1, t);
814 }
41be4444 815 ;
d3dd620b 816
92a72a4c 817bgp_path_expr:
c0e958e0 818 symbol_value { $$ = $1; }
92a72a4c
OZ
819 | '(' term ')' { $$ = $2; }
820 ;
821
f9491630 822bgp_path:
3e52d112 823 PO bgp_path_tail PC { $$ = $2; }
f9491630
OZ
824 ;
825
3e52d112 826bgp_path_tail:
4f082dfa
MM
827 NUM bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .asn = $1, .kind = PM_ASN, }, }); $$->next = $2; }
828 | NUM DDOT NUM bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .from = $1, .to = $3, .kind = PM_ASN_RANGE }, }); $$->next = $4; }
829 | '*' bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .kind = PM_ASTERISK }, }); $$->next = $2; }
830 | '?' bgp_path_tail { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PATH_MASK_ITEM, .val.pmi = { .kind = PM_QUESTION }, }); $$->next = $2; }
831 | bgp_path_expr bgp_path_tail { $$ = $1; $$->next = $2; }
122deb6d 832 | { $$ = NULL; }
f9491630 833 ;
77de6882 834
23b1539b 835constant:
9b46748d
MM
836 NUM { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_INT, .val.i = $1, }); }
837 | TRUE { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_BOOL, .val.i = 1, }); }
838 | FALSE { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_BOOL, .val.i = 0, }); }
839 | TEXT { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_STRING, .val.s = $1, }); }
840 | fipa { $$ = f_new_inst(FI_CONSTANT, $1); }
841 | VPN_RD { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_RD, .val.ec = $1, }); }
842 | net_ { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_NET, .val.net = $1, }); }
ca2ee91a
MM
843 | '[' set_items ']' {
844 DBG( "We've got a set here..." );
9b46748d 845 $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_SET, .val.t = build_tree($2), });
ca2ee91a
MM
846 DBG( "ook\n" );
847 }
9b46748d
MM
848 | '[' fprefix_set ']' { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = T_PREFIX_SET, .val.ti = $2, }); }
849 | ENUM { $$ = f_new_inst(FI_CONSTANT, (struct f_val) { .type = $1 >> 16, .val.i = $1 & 0xffff, }); }
23b1539b
PM
850 ;
851
42a0c054 852constructor:
9b46748d
MM
853 '(' term ',' term ')' { $$ = f_new_inst(FI_PAIR_CONSTRUCT, $2, $4); }
854 | '(' ec_kind ',' term ',' term ')' { $$ = f_new_inst(FI_EC_CONSTRUCT, $4, $6, $2); }
855 | '(' term ',' term ',' term ')' { $$ = f_new_inst(FI_LC_CONSTRUCT, $2, $4, $6); }
856 | bgp_path { $$ = f_new_inst(FI_PATHMASK_CONSTRUCT, $1, 0); }
42a0c054
OZ
857 ;
858
92a72a4c 859
2d496d20 860function_call:
c0e958e0 861 CF_SYM_FUNCTION '(' var_list ')' {
9b46748d 862 $$ = f_new_inst(FI_CALL, $1, $3);
2d496d20
PM
863 }
864 ;
865
c0e958e0 866symbol_value:
ea4f55e3 867 CF_SYM_CONSTANT { $$ = f_new_inst(FI_VARIABLE, $1); }
c0e958e0 868 | CF_SYM_VARIABLE { $$ = f_new_inst(FI_VARIABLE, $1); }
0b39b1cb 869 | CF_SYM_ATTRIBUTE { $$ = f_new_inst(FI_EA_GET, *$1->attribute); }
c0e958e0 870 ;
92a72a4c 871
2bdb5e00 872static_attr:
4c553c5a
MM
873 FROM { $$ = f_new_static_attr(T_IP, SA_FROM, 0); }
874 | GW { $$ = f_new_static_attr(T_IP, SA_GW, 0); }
875 | NET { $$ = f_new_static_attr(T_NET, SA_NET, 1); }
876 | PROTO { $$ = f_new_static_attr(T_STRING, SA_PROTO, 1); }
877 | SOURCE { $$ = f_new_static_attr(T_ENUM_RTS, SA_SOURCE, 1); }
878 | SCOPE { $$ = f_new_static_attr(T_ENUM_SCOPE, SA_SCOPE, 0); }
879 | DEST { $$ = f_new_static_attr(T_ENUM_RTD, SA_DEST, 0); }
880 | IFNAME { $$ = f_new_static_attr(T_STRING, SA_IFNAME, 0); }
881 | IFINDEX { $$ = f_new_static_attr(T_INT, SA_IFINDEX, 1); }
2bdb5e00
PM
882 ;
883
84c7e194 884term:
5a14df39 885 '(' term ')' { $$ = $2; }
9b46748d
MM
886 | term '+' term { $$ = f_new_inst(FI_ADD, $1, $3); }
887 | term '-' term { $$ = f_new_inst(FI_SUBTRACT, $1, $3); }
888 | term '*' term { $$ = f_new_inst(FI_MULTIPLY, $1, $3); }
889 | term '/' term { $$ = f_new_inst(FI_DIVIDE, $1, $3); }
890 | term AND term { $$ = f_new_inst(FI_AND, $1, $3); }
891 | term OR term { $$ = f_new_inst(FI_OR, $1, $3); }
892 | term '=' term { $$ = f_new_inst(FI_EQ, $1, $3); }
893 | term NEQ term { $$ = f_new_inst(FI_NEQ, $1, $3); }
894 | term '<' term { $$ = f_new_inst(FI_LT, $1, $3); }
895 | term LEQ term { $$ = f_new_inst(FI_LTE, $1, $3); }
896 | term '>' term { $$ = f_new_inst(FI_LT, $3, $1); }
897 | term GEQ term { $$ = f_new_inst(FI_LTE, $3, $1); }
898 | term '~' term { $$ = f_new_inst(FI_MATCH, $1, $3); }
899 | term NMA term { $$ = f_new_inst(FI_NOT_MATCH, $1, $3); }
900 | '!' term { $$ = f_new_inst(FI_NOT, $2); }
901 | DEFINED '(' term ')' { $$ = f_new_inst(FI_DEFINED, $3); }
23b1539b 902
c0e958e0 903 | symbol_value { $$ = $1; }
1183b6b2 904 | constant { $$ = $1; }
42a0c054 905 | constructor { $$ = $1; }
4515bdba 906
5a14df39 907 | PREFERENCE { $$ = f_new_inst(FI_PREF_GET); }
2bdb5e00 908
c0e958e0 909 | static_attr { $$ = f_new_inst(FI_RTA_GET, $1); }
fe613ecd 910
c0e958e0 911 | dynamic_attr { $$ = f_new_inst(FI_EA_GET, $1); }
36bbfc70 912
9b46748d
MM
913 | term '.' IS_V4 { $$ = f_new_inst(FI_IS_V4, $1); }
914 | term '.' TYPE { $$ = f_new_inst(FI_TYPE, $1); }
915 | term '.' IP { $$ = f_new_inst(FI_IP, $1); }
916 | term '.' RD { $$ = f_new_inst(FI_ROUTE_DISTINGUISHER, $1); }
917 | term '.' LEN { $$ = f_new_inst(FI_LENGTH, $1); }
918 | term '.' MAXLEN { $$ = f_new_inst(FI_ROA_MAXLEN, $1); }
919 | term '.' ASN { $$ = f_new_inst(FI_ROA_ASN, $1); }
920 | term '.' SRC { $$ = f_new_inst(FI_SADR_SRC, $1); }
921 | term '.' MASK '(' term ')' { $$ = f_new_inst(FI_IP_MASK, $1, $5); }
922 | term '.' FIRST { $$ = f_new_inst(FI_AS_PATH_FIRST, $1); }
923 | term '.' LAST { $$ = f_new_inst(FI_AS_PATH_LAST, $1); }
924 | term '.' LAST_NONAGGREGATED { $$ = f_new_inst(FI_AS_PATH_LAST_NAG, $1); }
7f77e250
PM
925
926/* Communities */
10a53608 927/* This causes one shift/reduce conflict
c0e958e0
MM
928 | dynamic_attr '.' ADD '(' term ')' { }
929 | dynamic_attr '.' DELETE '(' term ')' { }
930 | dynamic_attr '.' CONTAINS '(' term ')' { }
931 | dynamic_attr '.' RESET{ }
10a53608 932*/
7f77e250 933
9b46748d
MM
934 | '+' EMPTY '+' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_path); }
935 | '-' EMPTY '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_clist); }
936 | '-' '-' EMPTY '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_eclist); }
937 | '-' '-' '-' EMPTY '-' '-' '-' { $$ = f_new_inst(FI_CONSTANT, f_const_empty_lclist); }
938 | PREPEND '(' term ',' term ')' { $$ = f_new_inst(FI_PATH_PREPEND, $3, $5); }
939 | ADD '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_ADD, $3, $5); }
940 | DELETE '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_DEL, $3, $5); }
941 | FILTER '(' term ',' term ')' { $$ = f_new_inst(FI_CLIST_FILTER, $3, $5); }
afc54517 942
9b46748d
MM
943 | ROA_CHECK '(' rtable ')' { $$ = f_new_inst(FI_ROA_CHECK_IMPLICIT, $3); }
944 | ROA_CHECK '(' rtable ',' term ',' term ')' { $$ = f_new_inst(FI_ROA_CHECK_EXPLICIT, $5, $7, $3); }
af582c48 945
9b46748d 946 | FORMAT '(' term ')' { $$ = f_new_inst(FI_FORMAT, $3); }
9b0a0ba9 947
a2d15746 948/* | term '.' LEN { $$->code = P('P','l'); } */
7f77e250 949
4c553c5a 950 | function_call
ba921648
PM
951 ;
952
953break_command:
03e3d184
MM
954 QUITBIRD { $$ = F_QUITBIRD; }
955 | ACCEPT { $$ = F_ACCEPT; }
956 | REJECT { $$ = F_REJECT; }
957 | ERROR { $$ = F_ERROR; }
958 | PRINT { $$ = F_NOP; }
959 | PRINTN { $$ = F_NONL; }
ba921648
PM
960 ;
961
23b1539b 962print_one:
9b46748d 963 term { $$ = f_new_inst(FI_PRINT, $1); }
23b1539b
PM
964 ;
965
966print_list: /* EMPTY */ { $$ = NULL; }
995e5894
PM
967 | print_one { $$ = $1; }
968 | print_one ',' print_list {
23b1539b 969 if ($1) {
4f082dfa 970 $1->next = $3;
23b1539b 971 $$ = $1;
995e5894 972 } else $$ = $3;
23b1539b
PM
973 }
974 ;
975
c8cafc8e 976var_listn: term {
9b46748d 977 $$ = $1;
d3dd620b 978 }
6dc7a0cb 979 | term ',' var_listn {
9b46748d 980 $$ = $1;
4f082dfa 981 $$->next = $3;
6542ece9
PM
982 }
983 ;
984
6dc7a0cb
PM
985var_list: /* EMPTY */ { $$ = NULL; }
986 | var_listn { $$ = $1; }
987 ;
988
23b1539b 989cmd:
49955645 990 IF term THEN block {
9b46748d 991 $$ = f_new_inst(FI_CONDITION, $2, $4, NULL);
23b1539b 992 }
49955645 993 | IF term THEN block ELSE block {
9b46748d 994 $$ = f_new_inst(FI_CONDITION, $2, $4, $6);
23b1539b 995 }
c0e958e0 996 | CF_SYM_ATTRIBUTE '=' term ';' {
0b39b1cb 997 $$ = f_new_inst(FI_EA_SET, $3, *$1->attribute);
c0e958e0
MM
998 }
999 | CF_SYM_VARIABLE '=' term ';' {
1000 $$ = f_new_inst(FI_SET, $3, $1);
b9d70dc8 1001 }
2d496d20 1002 | RETURN term ';' {
d4d75628 1003 DBG( "Ook, we'll return the value\n" );
9b46748d 1004 $$ = f_new_inst(FI_RETURN, $2);
2d496d20 1005 }
c0e958e0
MM
1006 | dynamic_attr '=' term ';' {
1007 $$ = f_new_inst(FI_EA_SET, $3, $1);
f31156ca 1008 }
c0e958e0
MM
1009 | static_attr '=' term ';' {
1010 if ($1.readonly)
0dc4431c 1011 cf_error( "This static attribute is read-only.");
c0e958e0 1012 $$ = f_new_inst(FI_RTA_SET, $3, $1);
0dc4431c
PM
1013 }
1014 | PREFERENCE '=' term ';' {
9b46748d 1015 $$ = f_new_inst(FI_PREF_SET, $3);
c8cafc8e 1016 }
c0e958e0
MM
1017 | UNSET '(' dynamic_attr ')' ';' {
1018 $$ = f_new_inst(FI_EA_UNSET, $3);
c7b43f33 1019 }
9b46748d
MM
1020 | break_command print_list ';' { $$ = f_new_inst(FI_PRINT_AND_DIE, $2, $1); }
1021 | function_call ';' { $$ = f_new_inst(FI_DROP_RESULT, $1); }
7db7b7db 1022 | CASE term '{' switch_body '}' {
9b46748d 1023 $$ = f_new_inst(FI_SWITCH, $2, build_tree($4));
7db7b7db 1024 }
7d6eebae 1025
c0e958e0
MM
1026 | dynamic_attr '.' EMPTY ';' { $$ = f_generate_empty($1); }
1027 | dynamic_attr '.' PREPEND '(' term ')' ';' { $$ = f_generate_complex( FI_PATH_PREPEND, $1, $5 ); }
1028 | dynamic_attr '.' ADD '(' term ')' ';' { $$ = f_generate_complex( FI_CLIST_ADD, $1, $5 ); }
1029 | dynamic_attr '.' DELETE '(' term ')' ';' { $$ = f_generate_complex( FI_CLIST_DEL, $1, $5 ); }
1030 | dynamic_attr '.' FILTER '(' term ')' ';' { $$ = f_generate_complex( FI_CLIST_FILTER, $1, $5 ); }
3ec0bedc 1031 | BT_ASSERT '(' get_cf_position term get_cf_position ')' ';' { $$ = assert_done($4, $3 + 1, $5 - 1); }
c0e958e0 1032 | BT_CHECK_ASSIGN '(' get_cf_position lvalue get_cf_position ',' term ')' ';' { $$ = assert_assign(&$4, $7, $3 + 1, $5 - 1); }
9b0a0ba9
OZ
1033 ;
1034
1035get_cf_position:
1036{
1037 $$ = cf_text;
1038};
1039
c0e958e0
MM
1040lvalue:
1041 CF_SYM_VARIABLE { $$ = (struct f_lval) { .type = F_LVAL_VARIABLE, .sym = $1 }; }
1042 | PREFERENCE { $$ = (struct f_lval) { .type = F_LVAL_PREFERENCE }; }
1043 | static_attr { $$ = (struct f_lval) { .type = F_LVAL_SA, .sa = $1 }; }
1044 | dynamic_attr { $$ = (struct f_lval) { .type = F_LVAL_EA, .da = $1 }; };
9b0a0ba9 1045
b9d70dc8 1046CF_END