Commit 04632fd7 authored by Ondrej Zajicek (work)'s avatar Ondrej Zajicek (work)
Browse files

Follow-up work on integration

parent 70b90dde
Loading
Loading
Loading
Loading
+73 −33
Original line number Diff line number Diff line
@@ -41,7 +41,7 @@ CF_DECLS
  ip_addr a;
  ip4_addr ip4;
  ip6_addr ip6;
  net_addr_union net;
  net_addr net;
  net_addr *net_ptr;
  struct symbol *s;
  char *t;
@@ -76,12 +76,12 @@ CF_DECLS
%token <t> TEXT
%type <iface> ipa_scope

%type <i> expr bool pxlen4 pxlen6
%type <i> expr bool pxlen4
%type <i32> expr_us
%type <time> datetime
%type <a> ipa ipa_raw
%type <net> net_ip4 net_ip6 net_ip net_or_ipa
%type <net_ptr> net_any
%type <a> ipa
%type <net> net_ip4_ net_ip6_ net_ip6 net_ip_ net_ip net_or_ipa
%type <net_ptr> net_ net_any

%type <t> text opttext

@@ -151,15 +151,12 @@ bool:
 | /* Silence means agreement */ { $$ = 1; }
 ;

/* Addresses, prefixes and netmasks */

ipa_raw:
   IP4 { $$ = ipa_from_ip4($1); }
 | IP6 { $$ = ipa_from_ip6($1); }
 ;
/* Addresses */

ipa:
   ipa_raw
   IP4 { $$ = ipa_from_ip4($1); }
 | IP6 { $$ = ipa_from_ip6($1); }
 | SYM {
     if ($1->class != (SYM_CONSTANT | T_IP)) cf_error("IP address expected");
     $$ = SYM_VAL($1).ip;
@@ -172,42 +169,85 @@ ipa_scope:
 ;


/* XXXX - symbols and tests */
/* Networks - internal */

net_ip4: IP4 pxlen4 { $$.ip4 = NET_ADDR_IP4($1, $2); }
pxlen4:
   '/' NUM {
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
     $$ = $2;
   }
 | ':' IP4 {
     $$ = ip4_masklen($2);
     if ($$ == 255) cf_error("Invalid netmask %I", $2); /* XXXX */
   }
 ;

net_ip6: IP6 pxlen6 { $$.ip6 = NET_ADDR_IP6($1, $2); }
net_ip4_: IP4 pxlen4
{
  net_fill_ip4(&($$), $1, $2);
  if (!net_validate_ip4((net_addr_ip4 *) &($$)))
    cf_error("Invalid IPv4 prefix");
};

net_ip: net_ip4 | net_ip6 ;
net_ip6_: IP6 '/' NUM
{
  net_fill_ip6(&($$), $1, $3);
  if ($3 < 0 || $3 > IP6_MAX_PREFIX_LENGTH)
    cf_error("Invalid prefix length %d", $3);
  if (!net_validate_ip6((net_addr_ip6 *) &($$)))
    cf_error("Invalid IPv6 prefix");
};

net_any: net_ip { $$ = cfg_alloc($1.n.length); net_copy($$, &($1.n)); }
net_ip_: net_ip4_ | net_ip6_ ;

net_or_ipa:
   net_ip4
 | net_ip6
 | IP4 { $$.ip4 = NET_ADDR_IP4($1, IP4_MAX_PREFIX_LENGTH); }
 | IP6 { $$.ip6 = NET_ADDR_IP6($1, IP6_MAX_PREFIX_LENGTH); }
 ;
net_: net_ip_ { $$ = cfg_alloc($1.length); net_copy($$, &($1)); } ;


pxlen4:
   '/' expr {
     if ($2 < 0 || $2 > IP4_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
     $$ = $2;
/* Networks - regular */

net_ip6:
   net_ip6_
 | SYM {
     if (($1->class != (SYM_CONSTANT | T_NET)) || (SYM_VAL($1).net->type != NET_IP6))
       cf_error("IPv6 network expected");
     $$ = * SYM_VAL($1).net;
   }
 | ':' IP4 {
     $$ = ip4_masklen($2);
     if ($$ < 0) cf_error("Invalid netmask %I", $2);
 ;

net_ip:
   net_ip_
 | SYM {
     if (($1->class != (SYM_CONSTANT | T_NET)) || !net_is_ip(SYM_VAL($1).net))
       cf_error("IP network expected");
     $$ = * SYM_VAL($1).net;
   }
 ;

pxlen6:
   '/' expr {
     if ($2 < 0 || $2 > IP6_MAX_PREFIX_LENGTH) cf_error("Invalid prefix length %d", $2);
     $$ = $2;
net_any:
   net_
 | SYM {
     if ($1->class != (SYM_CONSTANT | T_NET))
       cf_error("Network expected");
     $$ = (net_addr *) SYM_VAL($1).net; /* Avoid const warning */
   }
 ;

net_or_ipa:
   net_ip4_
 | net_ip6_
 | IP4 { net_fill_ip4(&($$), $1, IP4_MAX_PREFIX_LENGTH); }
 | IP6 { net_fill_ip6(&($$), $1, IP6_MAX_PREFIX_LENGTH); }
 | SYM {
     if ($1->class == (SYM_CONSTANT | T_IP))
       net_fill_ip_host(&($$), SYM_VAL($1).ip);
     else if (($1->class == (SYM_CONSTANT | T_NET)) && net_is_ip(SYM_VAL($1).net))
       $$ = * SYM_VAL($1).net;
     else
       cf_error("IP address or network expected");
   }
 ;


datetime:
   TEXT {
     $$ = tm_parse_datetime($1);
+10 −9
Original line number Diff line number Diff line
@@ -475,7 +475,8 @@ block:
 * Complex types, their bison value is struct f_val
 */
fipa:
   ipa_raw %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = $1; }
   IP4 %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = ipa_from_ip4($1); }
 | IP6 %prec PREFIX_DUMMY { $$.type = T_IP; $$.val.ip = ipa_from_ip6($1); }
 ;


@@ -571,19 +572,19 @@ switch_items:
 ;

fprefix:
   net_ip	{ $$.net = $1; $$.lo = $1.n.pxlen; $$.hi = $1.n.pxlen; }
 | net_ip '+'	{ $$.net = $1; $$.lo = $1.n.pxlen; $$.hi = net_max_prefix_length[$1.n.type]; }
 | net_ip '-'	{ $$.net = $1; $$.lo = 0; $$.hi = $1.n.pxlen; }
 | net_ip '{' NUM ',' NUM '}' {
   net_ip_	{ $$.net = $1; $$.lo = $1.pxlen; $$.hi = $1.pxlen; }
 | net_ip_ '+'	{ $$.net = $1; $$.lo = $1.pxlen; $$.hi = net_max_prefix_length[$1.type]; }
 | net_ip_ '-'	{ $$.net = $1; $$.lo = 0; $$.hi = $1.pxlen; }
 | net_ip_ '{' NUM ',' NUM '}' {
     $$.net = $1; $$.lo = $3; $$.hi = $5;
     if ((0 > $3) || ($3 > $5) || ($5 > net_max_prefix_length[$1.n.type]))
     if ((0 > $3) || ($3 > $5) || ($5 > net_max_prefix_length[$1.type]))
       cf_error("Invalid prefix pattern range: {%d, %d}", $3, $5);
   }
 ;

fprefix_set:
   fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_prefix($$, &($1.net.n), $1.lo, $1.hi); }
 | fprefix_set ',' fprefix { $$ = $1; trie_add_prefix($$, &($3.net.n), $3.lo, $3.hi); }
   fprefix { $$ = f_new_trie(cfg_mem, sizeof(struct f_trie_node)); trie_add_prefix($$, &($1.net), $1.lo, $1.hi); }
 | fprefix_set ',' fprefix { $$ = $1; trie_add_prefix($$, &($3.net), $3.lo, $3.hi); }
 ;

switch_body: /* EMPTY */ { $$ = NULL; }
@@ -635,7 +636,7 @@ constant:
 | FALSE  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_BOOL; $$->a2.i = 0;  }
 | TEXT   { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_STRING; $$->a2.p = $1; }
 | fipa	  { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; $$->a1.p = val; *val = $1; }
 | net_any { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; val->type = T_NET; val->val.net = $1; $$->a1.p = val; }
 | net_   { NEW_F_VAL; $$ = f_new_inst(); $$->code = 'C'; val->type = T_NET; val->val.net = $1; $$->a1.p = val; }
 | '[' 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" ); }
 | '[' fprefix_set ']' { $$ = f_new_inst(); $$->code = 'c'; $$->aux = T_PREFIX_SET;  $$->a2.p = $2; }
 | ENUM	  { $$ = f_new_inst(); $$->code = 'c'; $$->aux = $1 >> 16; $$->a2.i = $1 & 0xffff; }
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ struct f_inst_roa_check {
};

struct f_prefix {
  net_addr_union net;
  net_addr net;
  u8 lo, hi;
};

+11 −5
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@ define ten = 10;
define p23 = (2, 3);
define ip1222 = 1.2.2.2;

define net10 = 10.0.0.0/8;
define netdoc = 2001:db8::/32;


function onef(int a)
{
	return 1;
@@ -55,6 +59,7 @@ function fifteen()
	return 15;
}

/*
roa table rl
{
	roa 10.110.0.0/16 max 16 as 1000;
@@ -80,6 +85,7 @@ function test_roa()
	      " ", roa_check(rl, 10.130.30.0/24, 3000) = ROA_INVALID,
	      " ", roa_check(rl, 10.130.130.0/24, 3000) = ROA_VALID;
}
*/

function path_test()
bgpmask pm1;
@@ -232,7 +238,7 @@ function __test2()
function test_pxset(prefix set pxs)
{
	print pxs;
	print "  must be true:  ",	10.0.0.0/8  ~ pxs, ",", 10.0.0.0/10  ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
	print "  must be true:  ",	net10  ~ pxs, ",", 10.0.0.0/10  ~ pxs, ",", 10.0.0.0/12 ~ pxs, ",",
					20.0.0.0/24 ~ pxs, ",", 20.0.40.0/24 ~ pxs, ",", 20.0.0.0/26 ~ pxs, ",",
					20.0.100.0/26 ~ pxs, ",", 20.0.0.0/28 ~ pxs, ",", 20.0.255.0/28 ~ pxs;
	print "  must be false: ",	10.0.0.0/7 ~ pxs,  ",", 10.0.0.0/13 ~ pxs, ",", 10.0.0.0/16 ~ pxs, ",",
@@ -312,8 +318,8 @@ string st;

	px = 1.2.0.0/18;
	print "Testing prefixes: 1.2.0.0/18 = ", px;
	print "  must be true:  ",	192.168.0.0/16 ~ 192.168.0.0/16, " ", 192.168.0.0/17 ~ 192.168.0.0/16, " ", 192.168.254.0/24 ~ 192.168.0.0/16;
	print "  must be false: ",	192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16;
	print "  must be true:  ",	192.168.0.0/16 ~ 192.168.0.0/16, " ", 192.168.0.0/17 ~ 192.168.0.0/16, " ", 192.168.254.0/24 ~ 192.168.0.0/16, " ", netdoc ~ 2001::/16;
	print "  must be false: ",	192.168.0.0/15 ~ 192.168.0.0/16, " ", 192.160.0.0/17 ~ 192.168.0.0/16, " ", px ~ netdoc;

	p = 127.1.2.3;
	print "Testing mask : 127.0.0.0 = ", p.mask(8);
@@ -397,7 +403,7 @@ string st;
	print "1.2.3.4 = ", onetwo;

	i = 4200000000;
	print "4200000000 = ", i, "   false: ", i = 4200000000, " ", i > 4100000000, "   false: ", i > 4250000000;
	print "4200000000 = ", i, "    true: ", i = 4200000000, " ", i > 4100000000, "   false: ", i > 4250000000;

	test_undef(2);
	test_undef(3);
+1 −1
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ ip6_masklen(ip6_addr *a)
    if (a->addr[i] != ~0U)
    {
      j = u32_masklen(a->addr[i]);
      if (j < 0)
      if (j == 255)
	return j;
      n += j;
      while (++i < 4)
Loading