4.3.13Computer Networks

Routing — forwarding table, routing table

2,152 words10 min readdifficulty · medium

WHAT are these two tables?


HOW a packet is forwarded (longest prefix match)


Figure — Routing — forwarding table, routing table

Worked example 1 — basic LPM

Forwarding table:

Prefix Out interface
0.0.0.0/0 (default) eth0
10.0.0.0/8 eth1
10.20.0.0/16 eth2

Packet destined for 10.20.30.40.

  1. Check 0.0.0.0/0 → matches (every address matches default). Why this step? The default route matches everything; it's the fallback.
  2. Check 10.0.0.0/8 → top 8 bits 10 match 10 ✓. Why? 10.20.30.40 AND /8 mask = 10.0.0.0 = prefix.
  3. Check 10.20.0.0/16 → top 16 bits 10.20 match ✓. Why? 10.20.30.40 AND 255.255.0.0 = 10.20.0.0 = prefix.
  4. Three matches: lengths 0, 8, 16. Longest = 16 → send out eth2. Why? The most specific route is the most precise about where the destination is.

HOW the forwarding table is derived from the routing table


Common mistakes


Recall Feynman: explain to a 12-year-old

Imagine the post office. The routing table is like the postmaster's big map and notebook where he figures out the best road to every town — he studies it carefully and updates it when roads close. The forwarding table is the little cheat-sheet taped to each sorting machine: "letters starting with these digits → put on truck #3." The machine doesn't think; it just reads the cheat-sheet super fast. And when two labels both fit a letter (one says "Springfield" and a more detailed one says "Springfield, Elm Street"), it always uses the more detailed one. That's longest prefix match!


Flashcards

What is a routing table (which plane, who builds it)?
Control-plane structure built by routing protocols (OSPF/RIP/BGP); holds all candidate routes, next-hops, metrics, administrative distances.
What is a forwarding table / FIB?
Data-plane table derived from the routing table; maps each destination prefix to an outgoing interface + next-hop, consulted per packet at line rate.
Why have a separate forwarding table instead of routing per packet?
Routing computation is slow & rich; baking best paths into a lean table lets hardware forward millions of packets/sec.
What rule chooses the forwarding entry for a packet?
Longest Prefix Match — the matching prefix with the largest prefix length wins.
Matching condition for address D against prefix P/L?
(D AND M) == (P AND M) where M is L ones followed by (32-L) zeros (the subnet mask).
What does ANDing the address with the mask accomplish?
It zeros out the host bits, leaving only network bits to compare against the prefix.
What does 0.0.0.0/0 match and when is it used?
It matches every address (length 0); used only when no more specific prefix matches (default route).
Is /25 a bigger or smaller network than /24?
Smaller — more network bits means fewer host bits (128 vs 256 addresses).
What breaks ties between routes from different protocols?
Administrative distance (lower = more trusted), then metric within the protocol.
Is IP forwarding first-match or longest-match?
Longest prefix match, independent of table order.
Subnet mask for /26?
255.255.255.192 (26 ones = ...11000000 in last byte).
What does route resolution do when installing into FIB?
Recursively resolves the next-hop IP to a directly connected outgoing interface (and MAC via ARP).

Connections

  • IP Addressing and Subnetting — masks, prefix lengths, CIDR
  • ARP — Address Resolution Protocol — next-hop IP → MAC for the FIB
  • OSPF and Link-State Routing — populates the routing table
  • Distance Vector — RIP — alternative way the routing table is built
  • TCAM and Line-rate Forwarding — hardware that stores the FIB
  • Default Gateway and 0.0.0.0/0 — the catch-all entry
  • Control Plane vs Data Plane — the master distinction

Concept Map

build

control plane

derived into

data plane

consulted per packet

carries 32-bit dest

uses subnet mask

selects largest L

gives

slow rich thinking once

fast hardware search

Routing algorithms OSPF RIP BGP

Routing table

Control plane

Forwarding table FIB

Data plane

Incoming packet

Longest prefix match

Mask erases host bits

Best entry

Outgoing interface + next-hop

Hinglish (regional understanding)

Intuition Hinglish mein samjho

Dekho, router ke paas do tables hote hain aur dono ka kaam alag hai. Pehla hai routing table (RIB) — yeh router ka "soch-vichaar" wala notebook hai. Ismein routing protocols (OSPF, RIP, BGP) saari information bharte hain: kaun se prefix tak jaana hai, next-hop kya hai, metric/cost kitna hai, kis protocol ne route sikhaya. Yeh control plane mein rehta hai aur tabhi update hota hai jab network topology badalti hai. Yeh thoda heavy aur slow hai kyunki ismein bahut saari candidate routes ho sakti hain.

Dusra hai forwarding table ya FIB — yeh "action" wala chhota cheat-sheet hai jo routing table se nikaala jaata hai. Ismein sirf utna hi data hota hai jitna ek packet ko aage bhejne ke liye chahiye: prefix ke liye outgoing interface aur next-hop. Yeh data plane mein hota hai aur har packet ke liye use hota hai, isliye super-fast hona zaroori hai (often TCAM hardware mein). Funda simple hai: RIB plans, FIB ships — ek baar dimaag lagao, phir hardware speed se bhejo.

Ab packet kaise route hota hai? Har packet mein destination IP hoti hai. Router dekhta hai ki uske table ke kaun kaun se prefixes is address ke saath match karte hain — yani top L bits same hain (mask ke saath AND karke compare). Agar kai prefixes match karte hain, toh router Longest Prefix Match lagata hai: jiska prefix length sabse bada (sabse specific) ho, wahi jeetega. Jaise 10.20.30.40 ke liye /16 jeetega /8 se, aur /8 jeetega 0.0.0.0/0 default se. Yaad rakho — yeh "first match" nahi hai, yeh "most specific match" hai, aur longer mask matlab chhota network (zyada network bits, kam host bits).

Yeh important kyun hai? Real internet pe ek router ko har second crores packets forward karne padte hain. Agar har packet pe poora routing algorithm chalega toh router crash ho jaayega. Isliye thinking (control plane) aur doing (data plane) ko alag rakhte hain — correctness protocols se, aur speed hardware se. Exam aur interview dono mein yeh distinction bahut puchha jaata hai!

Go deeper — visual, from zero

Test yourself — Computer Networks

Connections