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

Basic VRF support

Add basic VRF (virtual routing and forwarding) support. Protocols can be
associated with VRFs, such protocols will be restricted to interfaces
assigned to the VRF (as reported by Linux kernel) and will use sockets
bound to the VRF. E.g., different multihop BGP instances can use diffent
kernel routing tables to handle BGP TCP connections.

The VRF support is preliminary, currently there are several limitations:

- Recent Linux kernels (4.11) do not handle correctly sockets bound
to interaces that are part of VRF, so most protocols other than multihop
BGP do not work. This will be fixed by future kernel versions.

- Neighbor cache ignores VRFs. Breaks config with the same prefix on
local interfaces in different VRFs. Not much problem as single hop
protocols do not work anyways.

- Olock code ignores VRFs. Breaks config with multiple BGP peers with the
same IP address in different VRFs.

- Incoming BGP connections are not dispatched according to VRFs.
Breaks config with multiple BGP peers with the same IP address in
different VRFs. Perhaps we would need some kernel API to read VRF of
incoming connection? Or probably use multiple listening sockets in
int-new branch.

- We should handle master VRF interface up/down events and perhaps
disable associated protocols when VRF goes down. Or at least disable
associated interfaces.

- Also we should check if the master iface is really VRF iface and
not some other kind of master iface.

- BFD session request dispatch should be aware of VRFs.

- Perhaps kernel protocol should read default kernel table ID from VRF
iface so it is not necessary to configure it.

- Perhaps we should have per-VRF default table.
parent 98bb80a2
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -598,6 +598,15 @@ agreement").

	<tag><label id="proto-table">table <m/name/</tag>
	Connect this protocol to a non-default routing table.

	<tag><label id="proto-vrf">vrf "<m/text/"</tag>
	Associate the protocol with specific VRF. The protocol will be
	restricted to interfaces assigned to the VRF and will use sockets bound
	to the VRF. Appropriate VRF interface must exist on OS level. For kernel
	protocol, an appropriate table still must be explicitly selected by
	<cf/table/ option. Note that the VRF support in BIRD and Linux kernel
	(4.11) is still in development and is currently problematic outside of
	multihop BGP.
</descrip>

<p>There are several options that give sense only with certain protocols:
+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ typedef struct birdsock {
  int ttl;				/* Time To Live, -1 = default */
  u32 flags;
  struct iface *iface;			/* Interface; specify this for broad/multicast sockets */
  struct iface *vrf;			/* Related VRF instance, NULL if global */

  byte *rbuf, *rpos;			/* NULL=allocate automatically */
  uint fast_rx;				/* RX has higher priority in event loop */
+2 −1
Original line number Diff line number Diff line
@@ -55,7 +55,7 @@ get_passwords(void)
CF_DECLS

CF_KEYWORDS(ROUTER, ID, PROTOCOL, TEMPLATE, PREFERENCE, DISABLED, DEBUG, ALL, OFF, DIRECT)
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, TABLE, STATES, ROUTES, FILTERS)
CF_KEYWORDS(INTERFACE, IMPORT, EXPORT, FILTER, NONE, VRF, TABLE, STATES, ROUTES, FILTERS)
CF_KEYWORDS(RECEIVE, LIMIT, ACTION, WARN, BLOCK, RESTART, DISABLE, KEEP, FILTERED)
CF_KEYWORDS(PASSWORD, FROM, PASSIVE, TO, ID, EVENTS, PACKETS, PROTOCOLS, INTERFACES)
CF_KEYWORDS(ALGORITHM, KEYED, HMAC, MD5, SHA1, SHA256, SHA384, SHA512)
@@ -227,6 +227,7 @@ proto_item:
 | IMPORT LIMIT limit_spec { this_proto->in_limit = $3; }
 | EXPORT LIMIT limit_spec { this_proto->out_limit = $3; }
 | IMPORT KEEP FILTERED bool { this_proto->in_keep_filtered = $4; }
 | VRF TEXT { this_proto->vrf = if_get_by_name($2); }
 | TABLE rtable { this_proto->table = $2; }
 | ROUTER ID idval { this_proto->router_id = $3; }
 | DESCRIPTION text { this_proto->dsc = $2; }
+14 −5
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ if_what_changed(struct iface *i, struct iface *j)
  unsigned c;

  if (((i->flags ^ j->flags) & ~(IF_UP | IF_SHUTDOWN | IF_UPDATED | IF_ADMIN_UP | IF_LINK_UP | IF_TMP_DOWN | IF_JUST_CREATED))
      || i->index != j->index)
      || (i->index != j->index) || (i->master != j->master))
    return IF_CHANGE_TOO_MUCH;
  c = 0;
  if ((i->flags ^ j->flags) & IF_UP)
@@ -133,12 +133,14 @@ if_copy(struct iface *to, struct iface *from)
{
  to->flags = from->flags | (to->flags & IF_TMP_DOWN);
  to->mtu = from->mtu;
  to->master_index = from->master_index;
  to->master = from->master;
}

static inline void
ifa_send_notify(struct proto *p, unsigned c, struct ifa *a)
{
  if (p->ifa_notify)
  if (p->ifa_notify && (!p->vrf || p->vrf == a->iface->master))
    {
      if (p->debug & D_IFACES)
	log(L_TRACE "%s <%s address %I/%d on interface %s %s",
@@ -175,7 +177,7 @@ ifa_notify_change(unsigned c, struct ifa *a)
static inline void
if_send_notify(struct proto *p, unsigned c, struct iface *i)
{
  if (p->if_notify)
  if (p->if_notify && (!p->vrf || p->vrf == i->master))
    {
      if (p->debug & D_IFACES)
	log(L_TRACE "%s < interface %s %s", p->name, i->name,
@@ -238,7 +240,8 @@ if_recalc_flags(struct iface *i, unsigned flags)
{
  if ((flags & (IF_SHUTDOWN | IF_TMP_DOWN)) ||
      !(flags & IF_ADMIN_UP) ||
      !i->addr)
      !i->addr ||
      (i->master_index && !i->master))
    flags &= ~IF_UP;
  else
    flags |= IF_UP;
@@ -771,7 +774,13 @@ if_show(void)
      if (i->flags & IF_SHUTDOWN)
	continue;

      cli_msg(-1001, "%s %s (index=%d)", i->name, (i->flags & IF_UP) ? "up" : "DOWN", i->index);
      char mbuf[16 + sizeof(i->name)] = {};
      if (i->master)
	bsprintf(mbuf, " master=%s", i->master->name);
      else if (i->master_index)
	bsprintf(mbuf, " master=#%u", i->master_index);

      cli_msg(-1001, "%s %s (index=%d%s)", i->name, (i->flags & IF_UP) ? "up" : "DOWN", i->index, mbuf);
      if (!(i->flags & IF_MULTIACCESS))
	type = "PtP";
      else
+2 −0
Original line number Diff line number Diff line
@@ -34,8 +34,10 @@ struct iface {
  unsigned flags;
  unsigned mtu;
  unsigned index;			/* OS-dependent interface index */
  unsigned master_index;		/* Interface index of master iface */
  list addrs;				/* Addresses assigned to this interface */
  struct ifa *addr;			/* Primary address */
  struct iface *master;			/* Master iface (e.g. for VRF) */
  list neighbors;			/* All neighbors on this interface */
};

Loading