Sub topic 15
The FIB and fast forwarding in hardware
This chapter assumes you know longest prefix match, the control plane versus data plane split, and how a router rewrites a frame. Here you will see how a router turns its routing table into a structure it can search at line rate.
From RIB to FIB
The control plane keeps a routing information base (RIB). It holds every route learned from connected networks, static configuration and routing protocols, including routes that lost route selection. The RIB is built for correctness and policy.
The data plane uses a forwarding information base (FIB). The FIB holds only the winning route for each prefix, already resolved to an outgoing interface and a next hop. It also stores the Layer 2 rewrite information, or a pointer to the adjacency entry that holds it. The FIB is built for speed.
When a route changes, the control plane updates the RIB, reruns selection, and pushes the difference to the FIB. Packets never wait for a protocol to converge. They use whatever the FIB holds at that moment.
Why a linear scan does not scale
The Python example earlier in this tutorial checks every route. That is fine for three routes. The global IPv4 table holds hundreds of thousands of prefixes, and a fast link can deliver tens of millions of packets per second. A scan per packet is far too slow.
Routers instead use structures built for prefix search:
- Binary trie (radix tree). Each bit of the destination address chooses a branch. The deepest node marked as a prefix on the path is the longest match. Lookup cost depends on address length, not table size.
- Compressed tries. Chains of single-child nodes are merged, which saves memory and memory accesses. Linux uses a form of this for its IPv4 FIB.
- TCAM. Ternary content-addressable memory compares the destination against all stored prefixes in parallel. Each bit can be 0, 1, or "don't care". Entries are ordered by prefix length so the first hit is the longest match.
Hardware forwarding
High-end routers and switches forward in specialized chips (ASICs) or network processors. The FIB is copied into the chip's TCAM or SRAM. The chip parses the header, looks up the destination, decrements the TTL, updates the checksum, rewrites the Layer 2 header and queues the packet, all without involving the main CPU.
Software routers can also be fast. Linux caches nothing per flow in recent kernels. It does a compressed-trie lookup per packet, and tools such as DPDK or XDP skip most of the kernel's per-packet overhead.
Packets that need special handling go to the CPU, often called the slow path. Examples are packets addressed to the router itself, packets with a TTL of 1 that require an ICMP reply, and packets for next hops with no ARP entry yet. Slow-path capacity is small. A flood of such packets can overload the CPU even when the data plane is healthy.
Looking at the FIB on Linux
On Linux, the kernel's FIB is what ip route shows. This command asks the FIB for the entry a packet would use:
ip route get 10.1.2.3The answer shows the chosen next hop, the outgoing interface and the source address. If it disagrees with what a protocol advertises, the route may not have been installed in the FIB.
Exercise
A router's BGP process shows a route to 203.0.113.0/24, but traffic to that network is dropped. Which table should you check next, and what is one reason the route might be absent from it?
Show answer
Check the FIB (for example with ip route get 203.0.113.5 on Linux). The route may be missing because its next hop cannot be resolved, because a route from another source with a lower administrative distance won selection, or because the hardware FIB is full.
Exercise
Why does a TCAM lookup take the same time regardless of how many prefixes it holds, and what must be true about the entries for the first match to be the longest prefix?
Show answer
A TCAM compares the destination with every entry in parallel in a single operation. Entries must be sorted so that longer prefixes come before shorter ones.