Revision 5e173e9f filter/config.Y

View differences:

filter/config.Y
134 134

  
135 135
static inline struct f_inst *
136 136
f_generate_empty(struct f_inst *dyn)
137
{ 
137
{
138 138
  struct f_inst *e = f_new_inst();
139 139
  e->code = 'E';
140 140

  
......
217 217
    else if (val->type == T_QUAD) {
218 218
      ipv4_used = 1; key = val->val.i;
219 219
    }
220
    else if (val->type == T_IP) {
221
      ipv4_used = 1; key = ipa_to_u32(val->val.px.ip);
220
    else if ((val->type == T_IP) && ipa_is_ip4(val->val.ip)) {
221
      ipv4_used = 1; key = ipa_to_u32(val->val.ip);
222 222
    }
223 223
    else
224 224
      cf_error("Can't operate with key of non-integer/IPv4 type in EC constructor");
......
234 234

  
235 235
  if (c1 && c2) {
236 236
    u64 ec;
237
  
237

  
238 238
    if (kind == EC_GENERIC) {
239 239
      ec = ec_generic(key, val2);
240 240
    }
......
253 253
    NEW_F_VAL;
254 254
    rv = f_new_inst();
255 255
    rv->code = 'C';
256
    rv->a1.p = val;    
256
    rv->a1.p = val;
257 257
    val->type = T_EC;
258 258
    val->val.ec = ec;
259 259
  }
......
297 297
%type <i32> pair_atom ec_expr
298 298
%type <e> pair_item ec_item set_item switch_item set_items switch_items switch_body
299 299
%type <trie> fprefix_set
300
%type <v> set_atom switch_atom fprefix fprefix_s fipa
301
%type <s> decls declsn one_decl function_params 
300
%type <v> set_atom switch_atom fipa
301
%type <px> fprefix
302
%type <s> decls declsn one_decl function_params
302 303
%type <h> bgp_path bgp_path_tail1 bgp_path_tail2
303 304

  
304 305
CF_GRAMMAR
......
323 324
   INT { $$ = T_INT; }
324 325
 | BOOL { $$ = T_BOOL; }
325 326
 | IP { $$ = T_IP; }
326
 | PREFIX { $$ = T_PREFIX; }
327
 | PREFIX { $$ = T_NET; }
327 328
 | PAIR { $$ = T_PAIR; }
328 329
 | QUAD { $$ = T_QUAD; }
329 330
 | EC { $$ = T_EC; }
......
342 343
	       $$ = T_SET;
343 344
	       break;
344 345

  
345
	  case T_PREFIX:
346
	  case T_NET:
346 347
	       $$ = T_PREFIX_SET;
347 348
	    break;
348 349

  
......
477 478
 * Complex types, their bison value is struct f_val
478 479
 */
479 480
fipa:
480
   ipa_raw %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.px.ip = $1; }
481
   ipa_raw %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = $1; }
481 482
 ;
482 483

  
483 484

  
......
572 573
 | switch_items ',' switch_item { $$ = f_merge_items($1, $3); }
573 574
 ;
574 575

  
575
fprefix_s:
576
   ipa_raw '/' NUM %prec '/' {
577
     if (($3 < 0) || ($3 > (ipa_is_ip4($1) ? IP4_MAX_PREFIX_LENGTH : IP6_MAX_PREFIX_LENGTH)) || !ip_is_prefix($1, $3)) cf_error("Invalid network prefix: %I/%d.", $1, $3);
578
     $$.type = T_PREFIX; $$.val.px.ip = $1; $$.val.px.len = $3;
579
   }
580
 ;
581

  
582 576
fprefix:
583
   fprefix_s { $$ = $1; }
584
 | fprefix_s '+' { $$ = $1; $$.val.px.len |= LEN_PLUS; }
585
 | fprefix_s '-' { $$ = $1; $$.val.px.len |= LEN_MINUS; }
586
 | fprefix_s '{' NUM ',' NUM '}' { 
587
     if (! ((0 <= $3) && ($3 <= $5) && ($5 <= (ipa_is_ip4($1.val.px.ip) ? IP4_MAX_PREFIX_LENGTH : IP6_MAX_PREFIX_LENGTH)))) cf_error("Invalid prefix pattern range: {%d, %d}.", $3, $5);
588
     $$ = $1; $$.val.px.len |= LEN_RANGE | ($3 << 16) | ($5 << 8);
577
   net_ip	{ $$.net = $1; $$.lo = $1.n.pxlen; $$.hi = $1.n.pxlen; }
578
 | net_ip '+'	{ $$.net = $1; $$.lo = $1.n.pxlen; $$.hi = net_max_prefix_length[$1.n.type]; }
579
 | net_ip '-'	{ $$.net = $1; $$.lo = 0; $$.hi = $1.n.pxlen; }
580
 | net_ip '{' NUM ',' NUM '}' {
581
     $$.net = $1; $$.lo = $3; $$.hi = $5;
582
     if ((0 > $3) || ($3 > $5) || ($5 > net_max_prefix_length[$1.n.type]))
583
       cf_error("Invalid prefix pattern range: {%d, %d}", $3, $5);
589 584
   }
590 585
 ;
591 586

  
592 587
fprefix_set:
593
   fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_fprefix($$, &($1.val.px)); }
594
 | fprefix_set ',' fprefix { $$ = $1; trie_add_fprefix($$, &($3.val.px)); }
588
   fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_prefix($$, &($1.net.n), $1.lo, $1.hi); }
589
 | fprefix_set ',' fprefix { $$ = $1; trie_add_prefix($$, &($3.net.n), $3.lo, $3.hi); }
595 590
 ;
596 591

  
597 592
switch_body: /* EMPTY */ { $$ = NULL; }
......
602 597
       t->data = $4;
603 598
     $$ = f_merge_items($1, $2);
604 599
   }
605
 | switch_body ELSECOL cmds { 
600
 | switch_body ELSECOL cmds {
606 601
     struct f_tree *t = f_new_tree();
607 602
     t->from.type = t->to.type = T_VOID;
608 603
     t->right = t;
......
642 637
 | TRUE   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 1;  }
643 638
 | FALSE  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 0;  }
644 639
 | TEXT   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_STRING; $$->a2.p = $1; }
645
 | fipa	   { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
646
 | fprefix_s {NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
640
 | fipa	  { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
641
 | net_any { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; val->type = T_NET; val->val.net = $1; $$->a1.p = val; }
647 642
 | '[' set_items ']' { DBG( "We've got a set here..." ); $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_SET; $$->a2.p = build_tree($2); DBG( "ook\n" ); }
648 643
 | '[' fprefix_set ']' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_PREFIX_SET;  $$->a2.p = $2; }
649 644
 | ENUM	  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
......
706 701
static_attr:
707 702
   FROM    { $$ = f_new_inst(); $$->aux = T_IP;         $$->a2.i = SA_FROM;	$$->a1.i = 1; }
708 703
 | GW      { $$ = f_new_inst(); $$->aux = T_IP;         $$->a2.i = SA_GW;	$$->a1.i = 1; }
709
 | NET     { $$ = f_new_inst(); $$->aux = T_PREFIX;     $$->a2.i = SA_NET; }
704
 | NET     { $$ = f_new_inst(); $$->aux = T_NET;        $$->a2.i = SA_NET; }
710 705
 | PROTO   { $$ = f_new_inst(); $$->aux = T_STRING;     $$->a2.i = SA_PROTO; }
711 706
 | SOURCE  { $$ = f_new_inst(); $$->aux = T_ENUM_RTS;   $$->a2.i = SA_SOURCE; }
712 707
 | SCOPE   { $$ = f_new_inst(); $$->aux = T_ENUM_SCOPE; $$->a2.i = SA_SCOPE;	$$->a1.i = 1; }

Also available in: Unified diff