Recursive Routing: How BGP Next Hops Are Resolved Through the RIB

What a Recursive Route Is

Most routes in an IGP point straight at a neighbour on a directly connected link. OSPF tells you "go to 10.1.12.2 out of GigabitEthernet0/0", and the router can act on that at once. BGP is different. A BGP route usually points at a next hop that is not directly connected, such as the loopback of a router three hops away. To use that route, the router has to look up the next hop itself in the routing table, find how to reach it, and only then forward the packet. That second lookup is called recursion, and a route that needs it is a recursive route.

Recursion is not unique to BGP, and a static route is the simplest way to see it. A static route can name a next hop address without naming an interface.

R1(config)#ip route 172.30.0.0 255.255.0.0 3.3.3.3
R1#show ip route 172.30.0.0
Routing entry for 172.30.0.0/16
  Known via "static", distance 1, metric 0
  Routing Descriptor Blocks:
  * 3.3.3.3
      Route metric is 0, traffic share count is 1

The entry has a next hop but no interface. When a packet for 172.30.5.5 arrives, the router matches this route, then looks up 3.3.3.3, finds the OSPF route through GigabitEthernet0/0, and forwards the packet to the OSPF next hop 10.1.12.2. If the route to 3.3.3.3 disappears, the static route becomes useless and is removed from the table, because its next hop no longer resolves.

On a Cisco router the data plane does not repeat this work for every packet. CEF resolves the recursion in advance and stores the final answer, so forwarding stays a single lookup.

R1#show ip cef 172.30.0.0 detail
172.30.0.0/16, epoch 2
  recursive via 3.3.3.3
    nexthop 10.1.12.2 GigabitEthernet0/0

The output shows both levels: the recursive next hop from the RIB and the real adjacency CEF will use. This is the exact view to remember, because every iBGP route looks like this.

How BGP Resolves Its Next Hops

With recursion understood, the BGP next hop rules fall into place. Every BGP route carries a NEXT_HOP attribute, and the router must be able to resolve it through the RIB before the route can be used at all.

On eBGP sessions between directly connected routers, the next hop is the neighbour's interface address, which is a connected route, so resolution is immediate. The interesting case is iBGP. By default, a router does not change the next hop when it passes an eBGP-learned route to an iBGP peer. The route arrives at every router in the AS still pointing at the external neighbour's address, for example 203.0.113.1 on the ISP link. Every router in the AS now needs a route to 203.0.113.1.

R4#show ip bgp 198.51.100.0
BGP routing table entry for 198.51.100.0/24, version 0
Paths: (1 available, no best path)
  Not advertised to any peer
  Refresh Epoch 1
  64500
    203.0.113.1 (inaccessible) from 1.1.1.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal

The word "inaccessible" says it all. R4 has the route, but the RIB has no entry for 203.0.113.1, so the path cannot be best, is not installed, and is not used. There are two standard fixes. The edge router can rewrite the next hop to its own update source with "#neighbor 4.4.4.4 next-hop-self", or the ISP link subnet can be carried in the IGP, usually as a passive interface. The first is the common choice, because it keeps external addresses out of the IGP.

R1(config)#router bgp 65001
R1(config-router)#address-family ipv4 unicast
R1(config-router-af)#neighbor 4.4.4.4 next-hop-self
R4#show ip bgp 198.51.100.0
BGP routing table entry for 198.51.100.0/24, version 14
Paths: (1 available, best #1, table default)
  Not advertised to any peer
  Refresh Epoch 1
  64500
    1.1.1.1 (metric 3) from 1.1.1.1 (1.1.1.1)
      Origin IGP, metric 0, localpref 100, valid, internal, best

The next hop is now 1.1.1.1, R1's loopback, and the "(metric 3)" next to it is the IGP cost to reach it, taken straight from the RIB. That number is also what the BGP best path algorithm uses in its IGP metric step, so the RIB influences BGP's own decisions as well as its forwarding.

BGP also watches its next hops continuously. When the RIB route that resolves a next hop changes or disappears, Cisco's next hop tracking reacts to the RIB event and re-evaluates the affected paths, rather than waiting for a periodic scan. That is why a failed PE loopback in the IGP can trigger BGP convergence long before the BGP session itself times out.

When Resolution Fails or Goes Wrong

Knowing how resolution works also tells you how it breaks, and the failures are worth recognising on sight.

The first failure is the one shown above: no route to the next hop at all. The path is kept, flagged inaccessible, and ignored. Nothing is logged, so the symptom is simply a prefix that some routers in the AS use and others do not.

The second failure is subtler: the next hop resolves, but through the wrong route. A next hop that is only covered by a default route, or by a broad summary, looks reachable even when the specific router behind it has failed. Traffic is then sent towards a dead exit. IOS XR avoids the worst case by refusing to resolve BGP next hops through a default route unless "#nexthop resolution allow-default" is configured, and it can also require a minimum prefix length. On IOS XE, the tool is "#bgp nexthop route-map", applied per address family, which marks a next hop unreachable whenever the route that resolves it fails the route map.

R4(config)#ip prefix-list NH-HOST-ONLY seq 5 permit 0.0.0.0/0 ge 32
R4(config)#route-map NH-CHECK permit 10
R4(config-route-map)#match ip address prefix-list NH-HOST-ONLY
R4(config-route-map)#router bgp 65001
R4(config-router)#address-family ipv4 unicast
R4(config-router-af)#bgp nexthop route-map NH-CHECK

With this policy, a next hop is accepted only if a /32 host route in the RIB resolves it. In a design where every PE loopback is carried as a /32, a failed PE immediately becomes inaccessible instead of hiding behind a summary or the default route. Whether IOS XE resolves BGP next hops through a default route without such a policy is not stated in Cisco's documentation, so test your release rather than relying on either answer.

The third failure is the RIB losing the competition for the next hop itself, for example when a less specific static route or an unexpected BGP route ends up resolving the loopback of another router. The check is always the same pair of commands. First use "#show ip bgp" for the prefix to read the next hop and its metric, then use "#show ip route" for the next hop address to see which source resolves it and through which interface.

R4#show ip route 1.1.1.1
Routing entry for 1.1.1.1/32
  Known via "ospf 1", distance 110, metric 3, type intra area
  Last update from 10.4.24.2 on GigabitEthernet0/1, 00:41:07 ago
  Routing Descriptor Blocks:
  * 10.4.24.2, from 1.1.1.1, 00:41:07 ago, via GigabitEthernet0/1
      Route metric is 3, traffic share count is 1

A /32 learned from OSPF with a sensible metric is the healthy answer. Anything else, a default route, a summary, a static or BGP itself, is a reason to stop and look closer. Recursive resolution is invisible when it works and baffling when it does not, which is exactly why it belongs at the very start of a BGP course.