The IP Routing Information Base (RIB): Where Every BGP Route Has to Earn Its Place

What the RIB Is and Who Feeds It

Every router has to answer one question millions of times per second: where does this packet go next? The answer does not come from BGP, OSPF or EIGRP directly. It comes from a single table that collects the best routes from every source on the router. That table is the IP Routing Information Base, the RIB, and it is what you see when you type "#show ip route".

It helps to separate the router into two planes. The control plane is where protocols run, exchange information and make decisions. The data plane is where packets are actually forwarded. The RIB sits at the top of the data plane's supply chain: it is the control plane's final answer, and on Cisco it is copied into CEF, the Forwarding Information Base, which the data plane uses to switch packets.

Each routing protocol keeps its own private database before it talks to the RIB. OSPF keeps its link state database and runs SPF over it. EIGRP keeps its topology table with feasible successors. BGP keeps the BGP table, the Loc-RIB of the protocol, which can hold several paths for the same prefix. None of these databases forwards a single packet. Each protocol picks its own best route for each prefix and offers that route to the RIB. Connected interfaces and static routes are offered the same way, with no protocol database behind them.

R1#show ip route summary
IP routing table name is default (0x0)
IP routing table maximum-paths is 32
Route Source    Networks    Subnets     Replicates  Overhead    Memory (bytes)
application     0           0           0           0           0
connected       0           4           0           384         1216
static          1           0           0           96          304
ospf 1          0           3           0           288         912
  Intra-area: 3 Inter-area: 0 External-1: 0 External-2: 0
  NSSA External-1: 0 NSSA External-2: 0
bgp 65001       2           0           0           192         608
  External: 1 Internal: 1 Local: 0
internal        3                                               1412
Total           6           7           0           960         4452

This output is the RIB's view of who supplied what. Four connected subnets, one static route, three OSPF routes and two BGP routes made it into the table. The BGP line also splits its routes into external, internal and locally originated, which matters later in this course. On IOS XR the same idea is even more visible, because the RIB runs as a separate process from the protocols and pushes its results to the line card FIBs.

How a Route Wins Its Place in the RIB

Because several sources can offer the same prefix, the RIB needs a rule to choose between them, and that rule is administrative distance (AD). AD is a trust ranking for the source of a route, from 0 to 255, where lower is better. The Cisco defaults are worth memorising: connected 0, static 1, EIGRP summary 5, eBGP 20, EIGRP internal 90, OSPF 110, IS-IS 115, RIP 120, EIGRP external 170, iBGP 200. A route with AD 255 is treated as unreliable and is never installed.

The important detail is that AD only compares offers for exactly the same prefix and mask. If OSPF offers 10.0.0.0/16 and BGP offers 10.0.5.0/24, there is no competition. Both are installed, because they are different entries. The choice between them happens later, at forwarding time, through longest prefix match. AD decides which source gets to own a particular prefix. Longest match decides which installed prefix a packet uses.

Metric is the other number in the brackets of the routing table, and it is the most common source of confusion. A metric only means something inside its own protocol. An OSPF cost of 20 and an EIGRP metric of 3,072 cannot be compared, so the RIB never uses metric to choose between protocols. Within one protocol the metric has already done its job, because the protocol only offered its best route. When two sources offer the same prefix with the same AD, Cisco does not document a tie-break rule, so a design should never depend on that case.

R1#show ip route 10.0.5.0
Routing entry for 10.0.5.0/24
  Known via "bgp 65001", distance 20, metric 0
  Tag 65002, type external
  Last update from 10.1.12.2 00:04:11 ago
  Routing Descriptor Blocks:
  * 10.1.12.2, from 10.1.12.2, 00:04:11 ago
      Route metric is 0, traffic share count is 1
      AS Hops 1
      Route tag 65002
      MPLS label: none

Here the RIB tells you the owner of the prefix ("Known via"), its distance and metric, and the next hop. When a protocol offers a route that loses on AD, the route stays in that protocol's own database but does not appear here.

The RIB can also hold more than one path for a prefix when the paths come from the same source with equal cost. Most IPv4 routing protocols install up to 4 equal paths by default. BGP installs only 1 by default, and you raise it with "#maximum-paths" under the BGP address family. That single default explains why a network with two equal eBGP exits uses only one of them until someone changes it.

Why the RIB Matters So Much to BGP

With the RIB's rules in place, it becomes clear that BGP is a client of the RIB in three different ways, and each of them comes back again and again in this course.

The first is origination. The "#network" command under BGP does not create a route. It asks the RIB whether an exact match for that prefix and mask exists, and only if it does will BGP announce it. A missing static route or a wrong mask means a silent failure: nothing is advertised and nothing is logged.

The second is next hop resolution. A BGP route carries a next hop that is often not directly connected, for example the loopback of another router in the AS. BGP looks that next hop up in the RIB. If the RIB has no route to it, the BGP path is marked inaccessible and cannot become best. On IOS XR, a default route is not even accepted for this lookup unless you configure "#nexthop resolution allow-default".

The third is installation. BGP chooses its best path in its own table and then offers it to the RIB like any other protocol. If another source owns the same prefix with a lower AD, BGP loses. The path is still best in BGP, but it is flagged as a RIB failure, and by default BGP keeps advertising it anyway.

R1#show ip bgp rib-failure
  Network            Next Hop                      RIB-failure   RIB-NH Matches
10.1.12.0/24       10.1.12.2           Higher admin distance              n/a

The lesson for everything that follows is simple. BGP makes decisions, but the RIB makes them real. Whenever a BGP route does not behave as expected, check the RIB first: is the next hop resolvable, does the originated prefix exist, and who owns the prefix in "#show ip route". Most BGP problems that look complicated are RIB problems underneath.