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

Follow-up commit on integrated BIRD

Use net_addr for interface address prefixes, support net_addr in
configuration parser.
parent fe9f1a6d
Loading
Loading
Loading
Loading
+26 −14
Original line number Diff line number Diff line
@@ -41,6 +41,8 @@ CF_DECLS
  ip_addr a;
  ip4_addr ip4;
  ip6_addr ip6;
  net_addr_union net;
  net_addr *net_ptr;
  struct symbol *s;
  char *t;
  struct rtable_config *r;
@@ -78,10 +80,11 @@ CF_DECLS
%type <i32> expr_us
%type <time> datetime
%type <a> ipa ipa_raw
%type <px> prefix prefix_or_ipa
%type <t> text
%type <t> text_or_none
%type <t> opttext
%type <px> prefix
%type <net> net_ip4 net_ip6 net_ip net_or_ipa
%type <net_ptr> net_any

%type <t> text opttext

%nonassoc PREFIX_DUMMY
%left AND OR
@@ -169,6 +172,25 @@ ipa_scope:
 | '%' SYM { $$ = if_get_by_name($2->name); }
 ;


/* XXXX - symbols and tests */

net_ip4: IP4 pxlen { $$.ip4 = NET_ADDR_IP4($1, $2); }

net_ip6: IP6 pxlen { $$.ip6 = NET_ADDR_IP6($1, $2); }

net_ip: net_ip4 | net_ip6 ;

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

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); }
 ;


prefix:
   ipa pxlen {
     if (!ip_is_prefix($1, $2)) cf_error("Invalid prefix");
@@ -176,11 +198,6 @@ prefix:
   }
 ;

prefix_or_ipa:
   prefix
 | ipa { $$.addr = $1; $$.len = BITS_PER_IP_ADDRESS; }
 ;

pxlen:
   '/' expr {
     if ($2 < 0 || $2 > BITS_PER_IP_ADDRESS) cf_error("Invalid prefix length %d", $2);
@@ -208,11 +225,6 @@ text:
   }
 ;

text_or_none:
   TEXT { $$ = $1; }
 |      { $$ = NULL; }
 ;

opttext:
    TEXT
 | /* empty */ { $$ = NULL; }
+4 −1
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@ typedef struct net_addr {
  u8 type;
  u8 pxlen;
  u16 length;
  u8 data[16];
  u64 align[0];
  u32 space[4];
} net_addr;

typedef struct net_addr_ip4 {
@@ -207,6 +207,9 @@ int net_classify(const net_addr *N);
char * net_format(const net_addr *N, char *buf, int buflen);


int ipa_in_netX(const ip_addr A, const net_addr *N);
int net_in_netX(const net_addr *A, const net_addr *N);


#endif

+6 −7
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ iface_patt_check(void)
  struct iface_patt_node *pn;

  WALK_LIST(pn, this_ipatt->ipn_list)
    if (!pn->pattern || pn->pxlen)
    if (!pn->pattern || pn->prefix.pxlen) /* XXXX */
      cf_error("Interface name/mask expected, not IP prefix");
}

@@ -284,9 +284,8 @@ iface_patt_node_init:
 ;

iface_patt_node_body:
   TEXT { this_ipn->pattern = $1; this_ipn->prefix = IPA_NONE; this_ipn->pxlen = 0; }
 | prefix_or_ipa { this_ipn->pattern = NULL; this_ipn->prefix = $1.addr; this_ipn->pxlen = $1.len; }
 | TEXT prefix_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.addr; this_ipn->pxlen = $2.len; }
   TEXT { this_ipn->pattern = $1; net_fill_ip6(&this_ipn->prefix, IP6_NONE, 0); /* XXXX */ }
 | opttext net_or_ipa { this_ipn->pattern = $1; this_ipn->prefix = $2.n; }
 ;

iface_negate:
@@ -479,11 +478,11 @@ r_args:
     $$->prefix = $2.addr;
     $$->pxlen = $2.len;
   }
 | r_args FOR prefix_or_ipa {
 | r_args FOR net_or_ipa {
     $$ = $1;
     if ($$->pxlen != 256) cf_error("Only one prefix expected");
     $$->prefix = $3.addr;
     $$->pxlen = $3.len;
     $$->prefix = IPA_NONE; /* XXXX */
     $$->pxlen = 0; /* XXXX */
     $$->show_for = 1;
   }
 | r_args TABLE SYM {
+13 −18
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ list iface_list;
void
ifa_dump(struct ifa *a)
{
  debug("\t%I, net %I/%-2d bc %I -> %I%s%s%s\n", a->ip, a->prefix, a->pxlen, a->brd, a->opposite,
  debug("\t%I, net %N bc %I -> %I%s%s%s\n", a->ip, &a->prefix, a->brd, a->opposite,
	(a->flags & IF_UP) ? "" : " DOWN",
	(a->flags & IA_PRIMARY) ? "" : " SEC",
	(a->flags & IA_PEER) ? "PEER" : "");
@@ -141,10 +141,9 @@ ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
  if (p->ifa_notify)
    {
      if (p->debug & D_IFACES)
	log(L_TRACE "%s < %s address %I/%d on interface %s %s",
	log(L_TRACE "%s < %s address %N on interface %s %s",
	    p->name, (a->flags & IA_PRIMARY) ? "primary" : "secondary",
	    a->prefix, a->pxlen, a->iface->name,
	    (c & IF_CHANGE_UP) ? "added" : "removed");
	    &a->prefix, a->iface->name, (c & IF_CHANGE_UP) ? "added" : "removed");
      p->ifa_notify(p, c, a);
    }
}
@@ -500,8 +499,7 @@ ifa_recalc_all_primary_addresses(void)
static inline int
ifa_same(struct ifa *a, struct ifa *b)
{
  return ipa_equal(a->ip, b->ip) && ipa_equal(a->prefix, b->prefix) &&
    a->pxlen == b->pxlen;
  return ipa_equal(a->ip, b->ip) && net_equal(&a->prefix, &b->prefix);
}


@@ -586,7 +584,6 @@ ifa_delete(struct ifa *a)
u32
if_choose_router_id(struct iface_patt *mask, u32 old_id)
{
#ifndef IPV6
  struct iface *i;
  struct ifa *a, *b;

@@ -599,6 +596,9 @@ if_choose_router_id(struct iface_patt *mask, u32 old_id)

      WALK_LIST(a, i->addrs)
	{
	  if (a->prefix.type != NET_IP4)
	    continue;

	  if (a->flags & IA_SECONDARY)
	    continue;

@@ -623,10 +623,6 @@ if_choose_router_id(struct iface_patt *mask, u32 old_id)
    log(L_INFO "Chosen router ID %R according to interface %s", id, b->iface->name);

  return id;

#else
  return 0;
#endif
}

/**
@@ -669,17 +665,17 @@ iface_patt_match(struct iface_patt *ifp, struct iface *i, struct ifa *a)
	    continue;
	}

      if (p->pxlen == 0)
      if (p->prefix.pxlen == 0)
	return pos;

      if (!a)
	continue;

      if (ipa_in_net(a->ip, p->prefix, p->pxlen))
      if (ipa_in_netX(a->ip, &p->prefix))
	return pos;

      if ((a->flags & IA_PEER) &&
	  ipa_in_net(a->opposite, p->prefix, p->pxlen))
	  ipa_in_netX(a->opposite, &p->prefix))
	return pos;

      continue;
@@ -713,8 +709,7 @@ iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb)
	  (!x->pattern && y->pattern) ||	/* This nasty lines where written by me... :-( Feela */
	  (!y->pattern && x->pattern) ||
	  ((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) ||
	  !ipa_equal(x->prefix, y->prefix) ||
	  (x->pxlen != y->pxlen))
	  !net_equal(&x->prefix, &y->prefix))
	return 0;
      x = (void *) x->n.next;
      y = (void *) y->n.next;
@@ -754,7 +749,7 @@ if_show_addr(struct ifa *a)
  else
    opp[0] = 0;
  cli_msg(-1003, "\t%I/%d (%s%s, scope %s)",
	  a->ip, a->pxlen,
	  a->ip, a->prefix.pxlen,
	  (a->flags & IA_PRIMARY) ? "Primary" : (a->flags & IA_SECONDARY) ? "Secondary" : "Unselected",
	  opp, ip_scope_text(a->scope));
}
@@ -804,7 +799,7 @@ if_show_summary(void)
  WALK_LIST(i, iface_list)
    {
      if (i->addr)
	bsprintf(addr, "%I/%d", i->addr->ip, i->addr->pxlen);
	bsprintf(addr, "%I/%d", i->addr->ip, i->addr->prefix.pxlen);
      else
	addr[0] = 0;
      cli_msg(-1005, "%-9s %-5s %s", i->name, (i->flags & IF_UP) ? "up" : "DOWN", addr);
+2 −4
Original line number Diff line number Diff line
@@ -19,9 +19,8 @@ struct pool;
struct ifa {				/* Interface address */
  node n;
  struct iface *iface;			/* Interface this address belongs to */
  net_addr prefix;			/* Network prefix */
  ip_addr ip;				/* IP address of this host */
  ip_addr prefix;			/* Network prefix */
  unsigned pxlen;			/* Prefix length */
  ip_addr brd;				/* Broadcast address */
  ip_addr opposite;			/* Opposite end of a point-to-point link */
  unsigned scope;			/* Interface address scope */
@@ -148,8 +147,7 @@ struct iface_patt_node {
  node n;
  int positive;
  byte *pattern;
  ip_addr prefix;
  int pxlen;
  net_addr prefix;
};

struct iface_patt {
Loading