8. Routing Basics
How a router reads one address, picks the most specific route, and passes your packet one hop closer to the other side of the world
You're driving to a friend's house in a town you've never visited, with no map and no satnav. All you have is the address: 14 Mill Lane, Ashby. At the motorway junction, a sign says Ashby: exit 12. It knows nothing about Mill Lane, and doesn't need to. At the edge of Ashby, another sign says Town centre: straight on · Mill Lane: left · All other routes: right. You turn left, and a few minutes later you're there.
Nobody along the way knew your whole route. Each junction only knew which way to send you next, and when more than one sign matched your destination, you followed the most specific one: "Mill Lane" beats "Ashby", which beats "all other routes". And if you'd somehow been sent round in circles, you'd have given up after an hour rather than drive forever.
That's IP routing, almost exactly. A router is a junction. It reads one thing, the destination address, compares it with a list of signs called the routing table, follows the most specific match, and sends the packet one hop onward. A countdown in the packet, the TTL, makes sure that a packet sent round in circles eventually gives up.
The series has been building up to this. The Layers article said that a
router "throws the Ethernet header away" and builds a new one. The ARP article
showed the laptop deciding "that address isn't local, so hand it to the gateway". The
VLANs article routed a print job between two subnets in the house.
This article follows the packet past the home router and out across the Internet to the
web server at 203.0.113.80, through four routers, showing every decision on the way.
What a Router Does
A switch and a router both take a frame in on one port and send it out on another, so it's worth being precise about the difference.
Switch: within one network
Looks at the destination MAC, finds the port in its MAC table (or floods), and sends the frame out unchanged. It learns from the traffic it sees and needs no configuration. It never reads the IP header, and a frame has no hop count, which is why loops between switches are such a disaster (see Spanning Tree).
Router: between networks
Looks at the destination IP address, picks a route from its routing table, and sends the packet towards the next router. Along the way it decrements the TTL, fixes the IPv4 checksum, and wraps the packet in a brand-new Ethernet frame for the next link. It only forwards frames addressed to its own MAC.
Here is everything a router does with a packet, in order. It's worth reading slowly once, because the rest of the article is these steps in detail.
-
Accept the frame and unwrap it
The frame must be addressed to this interface's MAC (or be a broadcast or multicast the router cares about), and its FCS must check out. The router then discards the Ethernet header and trailer: their job is done.
-
Check the IP header
Version, header length and, for IPv4, the header checksum. A corrupt header is dropped silently. If the destination is one of the router's own addresses, the packet goes up its own stack instead (that's how you ping a router or log in to it).
-
Look up the destination
Find the longest matching prefix in the routing table. The winning route says which interface to send on and, unless the destination is directly connected, which neighbouring router (the next hop) to hand it to. No match at all means the packet is dropped with an ICMP "destination unreachable".
-
Decrement the TTL and fix the checksum
If the TTL (IPv6: hop limit) would reach zero, the packet is dropped and the sender gets an ICMP "time exceeded". Otherwise it goes down by one, and in IPv4 the header checksum is updated to match.
-
Find the next hop's MAC and send a new frame
ARP (IPv4) or Neighbor Discovery (IPv6) for the next hop's IP address, not the final destination's. Build a new Ethernet header, with the outgoing interface's MAC as source and the next hop's MAC as destination, compute a new FCS, and transmit. If the packet is too big for the outgoing link, fragment it (IPv4 only) or send back an ICMP "too big".
Notice what doesn't change: the source and destination IP addresses, and everything inside the IP payload. From the laptop to the server, the addresses in the IP header are the same at every hop, while the Ethernet header is replaced at every hop. In the Layers article's terms, the IP packet is the pouch that travels the whole way, and each Ethernet frame is a fresh crate for one leg of the journey.
Where the laptop fits in
The laptop is a tiny router too. Before it sends anything, it does its own version of step 3: the "local or remote?" test from the ARP article, made precise in IPv4 Addressing. If the destination is inside its own subnet, it ARPs for the destination and delivers directly. If not, it ARPs for its default gateway and hands the packet over. We'll see in a moment that this decision is just a lookup in a two-line routing table.
The one big exception: NAT
"IP addresses never change in transit" has a famous exception sitting in almost every
home. Our house has only one public IPv4 address, so the home router rewrites the
laptop's private source address 192.168.10.10 to its own public address on
the way out, and reverses the change for replies. That's
NAT,
and it's a separate job from routing that just happens to live in the same box. We'll
note where it happens and leave the details to the NAT article. The IPv6
path, later on, has no NAT at all.
The Routing Table
A routing table is a list of routes. Each one says: to reach addresses that start with this prefix, send the packet this way. Every router has one, and so does every host. Here are the fields you'll meet, with values from a route we'll use later:
| Field | Example | Meaning |
|---|---|---|
| Destination prefix | 203.0.113.0/24 |
Which destinations the route covers |
| Next hop (gateway) | 192.0.2.6 |
The neighbouring router to hand the packet to; empty if the destination is on the link |
| Outgoing interface | eth1 |
Which port to send it out of |
| Metric | 0 |
The route's cost according to whoever supplied it; lower is better |
| Source / admin distance | eBGP, 20 | Where the route came from, and how much the router trusts that source |
The next hop must be on a network the router is directly attached to. That's the whole
trick: a router doesn't need to know the path to 203.0.113.80, only which of its
neighbours is a step closer to it.
Kinds of route
- Connected routes. Created automatically when an interface gets an address. Give the
home router
192.168.10.1/24oneth0.10, and it immediately knows that192.168.10.0/24is reachable directly on that interface, with no next hop. - Static routes. Typed in by a person (or a script): "send
10.20.0.0/16via192.168.10.2". Simple, predictable, and blind: a static route keeps pointing at its next hop even if that router has died, unless the outgoing link itself goes down. - The default route.
0.0.0.0/0in IPv4 and::/0in IPv6. A prefix of length zero matches every address, so it catches whatever no other route does: "all other routes: right". The "default gateway" in a host's settings is just the next hop of its default route. Most routers at the edge of the Internet need nothing else; only the routers in the middle, the default-free zone, carry routes for the whole Internet instead. - Host routes. A
/32(IPv4) or/128(IPv6): a route to exactly one address. Used for a router's own loopback addresses, for a single machine that lives somewhere unusual, and, as we'll see, for deliberately dropping traffic to one address. - Dynamic routes. Learned automatically from neighbouring routers by a routing protocol such as OSPF or BGP. They're the subject of the next three articles; for now, they're just routes with a different source.
The laptop's table
On Linux, ip route shows the main routing table. The laptop's, after DHCP has configured
it on VLAN 10, has exactly two routes:
The laptop: ip route
$ ip route
default via 192.168.10.1 dev eth0 proto dhcp src 192.168.10.10 metric 100
192.168.10.0/24 dev eth0 proto kernel scope link src 192.168.10.10 metric 100
The second line is the connected route: the kernel added it
(proto kernel) when the interface got 192.168.10.10/24, and
scope link means "directly reachable, no gateway". The first is the
default route, supplied by DHCP: everything else goes
via 192.168.10.1.
Now the ARP article's "local or remote?" decision is just a routing lookup. The NAS at
192.168.10.30 matches both routes, and the /24 is more specific, so the laptop sends
directly. The server at 203.0.113.80 only matches default, so the laptop sends to
192.168.10.1. The command ip route get asks the kernel to do the lookup and show the
result:
$ ip route get 192.168.10.30
192.168.10.30 dev eth0 src 192.168.10.10 uid 1000
cache
$ ip route get 203.0.113.80
203.0.113.80 via 192.168.10.1 dev eth0 src 192.168.10.10 uid 1000
cache
That rule, "more specific wins", is the heart of routing. It deserves a section of its own.
Longest-Prefix Match
The rule every IP router follows, first teased in the IPv4 Addressing article, is:
Longest-prefix match
Among all the routes whose prefix matches the destination address, use the one with the
longest prefix. A /25 beats a /24, which beats a
/0. The more bits a route pins down, the more specific its knowledge, so the
more it is trusted for the addresses it covers.
A route matches if the first n bits of the destination equal the first n bits of the route's prefix, where n is the prefix length. Nothing else about the route matters for matching.
A table with overlaps
The laptop's table is too simple to be interesting. Here is the table of the ISP's core
router, R3, which we'll meet properly in the walkthrough. It has four interfaces:
eth0 towards the ISP's edge router R2 (and our house behind it), eth1 towards the data
centre hosting our web server, eth2 towards a bigger
transit provider,
and eth3 towards the hosting company's second data centre, "DC-2".
| Prefix | Next hop, interface | Source (AD) | Metric |
|---|---|---|---|
0.0.0.0/0 |
192.0.2.9, eth2 |
static (1) | 0 |
192.0.2.0/30 |
direct, eth0 | connected (0) | 0 |
192.0.2.4/30 |
direct, eth1 | connected (0) | 0 |
192.0.2.8/30 |
direct, eth2 | connected (0) | 0 |
192.0.2.12/30 |
direct, eth3 | connected (0) | 0 |
198.51.100.0/24 |
192.0.2.1, eth0 |
OSPF (110) | 20 |
198.51.100.99/32 |
drop (blackhole) | static (1) | 0 |
203.0.113.0/24 |
192.0.2.6, eth1 |
eBGP (20) | 0 |
203.0.113.0/24 |
192.0.2.13, eth3 |
static (250) | 0 |
203.0.113.128/25 |
192.0.2.13, eth3 |
eBGP (20) | 0 |
In words: the four /30s are the little point-to-point links to R3's neighbours. The ISP's
customers in our street, 198.51.100.0/24, are behind R2. One of them, 198.51.100.99,
is under a flood attack, so the ISP is dropping everything sent to it. The hosting company
announces its /24 from the main data centre, and the top half of it, a /25, from DC-2.
There's also a second, backup route for the /24 via DC-2, and a default route to the
transit provider for everything else.
The AD column (administrative distance) and the duplicate /24 will matter in a
minute. First, the lookups.
-
Destination 203.0.113.80: our web server
Three routes match:
0.0.0.0/0(0 bits), and both203.0.113.0/24routes (24 bits). The/25doesn't: its 25th bit is 1, and.80starts with a 0 bit. The longest match is/24, but there are two routes for it, so a tie-break is needed (below). The winner: via192.0.2.6on eth1, to the main data centre. -
Destination 203.0.113.200
Four routes match: the default, both
/24s and, this time, the/25, because.200starts with a 1 bit. The/25is longest: via192.0.2.13on eth3, to DC-2. -
Destination 198.51.100.99: the customer under attack
The default,
198.51.100.0/24and the/32host route all match. The/32wins, and it says drop. Every other address in the/24still goes to R2 as normal. -
Destination 198.51.100.23
The default and
198.51.100.0/24match; the/32for.99doesn't (it needs all 32 bits to agree). The/24wins: via192.0.2.1on eth0. This is how replies get back to our house, as we'll see. -
Destination 192.0.2.77
It shares 25 bits with each of the
/30s, but a/30needs 30. Only the default matches: via192.0.2.9on eth2, to the transit provider.
Here is the first lookup in binary. Matching bits are highlighted; the bit that rules a route out is in red:
destination 203.0.113.80 11001011 00000000 01110001 01010000
203.0.113.0/24 11001011 00000000 01110001 ········ 24 of 24: match
203.0.113.128/25 11001011 00000000 01110001 1······· bit 25 differs
198.51.100.0/24 11000110 00110011 01100100 ········ bit 5 differs
0.0.0.0/0 ········ ········ ········ ········ 0 of 0: match
Ties: same prefix, different routes
Longest-prefix match picks a prefix. When two or more routes exist for that exact
same prefix, as with the two /24s, the router breaks the tie in this order:
-
Lowest administrative distance
Each route source has a trust level, called administrative distance by Cisco (and by FRR, the open-source router suite); lower is more trusted. Cisco's defaults are connected 0, static 1, eBGP 20, OSPF 110, IS-IS 115, RIP 120, iBGP 200. Juniper calls it preference and uses different numbers (static 5, OSPF internal 10, OSPF external 150, BGP 170), but the idea is identical. Here eBGP's 20 beats the static route's 250.
-
Lowest metric
Only between routes from the same source. Metrics from different protocols are in different units (OSPF cost, RIP hop count, BGP's MED) and can't be compared, which is exactly why administrative distance exists.
-
Still tied? Use them all
Equal-cost routes can all be installed, and traffic is shared between them. That's ECMP, covered below.
The order matters: specificity first, trust second
Administrative distance never overrides prefix length. A static route (AD 1) for
0.0.0.0/0 loses to an OSPF route (AD 110) for 198.51.100.0/24
for any address in that /24, because they're routes to different prefixes.
AD only chooses between routes for the same prefix. The static
/24 with AD 250 is a floating static: it sits unused
until the BGP route for the same prefix disappears, then takes over.
In practice, routers settle the same-prefix contests ahead of time, whenever a route appears or disappears. Only the winner for each prefix goes into the table used to forward packets (the FIB, below), so the per-packet lookup is pure longest-prefix match. In pseudocode:
# Whenever a route is added or removed: pick one winner per prefix
for each prefix p known from any source:
candidates = all routes for exactly p
best = those with the lowest admin distance
best = those of them with the lowest metric # same source, so comparable
fib[p] = best # more than one left: ECMP
# For every packet: longest-prefix match over the winners
function lookup(fib, dst):
winner = none
for each (p, len) in fib:
if first_bits(dst, len) == first_bits(p, len):
if winner is none or len > winner.len:
winner = (p, len)
return fib[winner] # none: drop, ICMP unreachable
IPv6 works identically, just with 128-bit addresses. R3's IPv6 table has the same shape:
| Prefix | Next hop, interface | Source (AD) |
|---|---|---|
::/0 |
fe80::9, eth2 |
static (1) |
2001:db8:1200::/40 |
drop (blackhole) | static (1) |
2001:db8: |
fe80::, eth0 |
OSPF (110) |
2001:db8: |
direct, eth0 | connected (0) |
2001:db8: |
direct, eth1 | connected (0) |
2001:db8:1234::/56 |
fe80::, eth0 |
OSPF (110) |
2001:db8:113::/48 |
2001:db8:, eth1 |
eBGP (20) |
The ISP owns 2001:db8:1200::/40, which includes our house's 2001:db8:1234::/56
(the /40 fixes the first ten hex digits, 2001:0db8:12, and 34 follows). So the
laptop's address 2001:db8:1234:10:0:ff:feaa:bb01 matches three routes: ::/0, the
/40 and the /56. The /56 is longest, so it goes to R2. An address in the ISP's block
that nobody has been given, such as 2001:db8:12ab::1, matches only ::/0 and the
/40, so it's dropped. That "drop" route looks odd, but it prevents a loop, as we'll see
later. And the server, 2001:db8:113::80, matches ::/0 and the hosting
company's /48; the /48 wins.
Notice that two of the next hops are link-local addresses (fe80::…). That's normal
in IPv6: a next hop only has to be reachable on the attached link, and OSPF for IPv6 always
advertises neighbours by their link-local addresses. It's also why an IPv6 route always
names its interface: fe80::9 means nothing without one.
Destination
Type any IPv4 or IPv6 address; an IPv6 destination switches to R3’s IPv6 table.
Destination vs winning prefix, bit by bit
R3’s routing table
Each route shows how many bits it matched, or the first bit that differs. Press Bits to compare any route bit by bit, or Edit to change it.
Add a route
Making Lookups Fast
The pseudocode above checks every route for every packet. R3's table has ten routes; a router in the default-free zone holds more than a million IPv4 routes and around 220,000 IPv6 ones. A 100 Gb/s port receiving minimum-size packets gets about 148.8 million of them a second (64 bytes plus 20 bytes of preamble and gap is 672 bits, and 100 Gb/s divided by 672 bits is 148.8 million), which leaves under 7 nanoseconds per lookup. A linear scan is out of the question.
The binary trie
The classic structure is a binary trie: a tree in which each level tests one bit of the address, going left for 0 and right for 1. Each prefix lives at the node reached by following its bits. To look up an address, walk down the tree bit by bit, remembering the last prefix you passed; when you can't go any further, the last one you remembered is the longest match.
function trie_lookup(root, dst, bits): # bits = 32 for IPv4, 128 for IPv6
node = root
best = root.route # the default route, if any
for i in 0 .. bits-1:
node = node.child[bit(dst, i)] # bit i, counting from the left
if node is none:
break
if node.route is not none:
best = node.route
return best
That's correct but slow: up to 32 memory reads per IPv4 lookup, and 128 per IPv6 lookup. Every practical design is a way to take bigger steps:
- Path compression. Most nodes in a routing trie have one child. A Patricia trie (Donald Morrison, 1968) skips those chains and stores which bit to test next. The BSD "radix tree", in kernels since the early 1990s, is one of these.
- Multibit tries. Test several bits per level, say 8, so each node is an array of 256 children and an IPv4 lookup takes at most four steps. Prefixes that don't end on a stride boundary are expanded into several entries. DIR-24-8, from Gupta, Lin and McKeown in 1998, takes this to an extreme with one 224-entry table for the first 24 bits and a second table for longer prefixes: almost every lookup is one memory read, never more than two.
- Level compression. Linux's IPv4 FIB is an LC-trie (level-compressed trie, from Nilsson and Karlsson's 1999 paper), which uses wide nodes where the trie is dense and narrow ones where it is sparse.
TCAM: searching everything at once
Big hardware routers often skip the cleverness and use
TCAM.
Ordinary memory takes an address and returns the data stored there. Content-addressable
memory works backwards: give it a value and it returns where that value is stored,
comparing every entry at once in a single clock cycle. A ternary CAM stores three
states per bit: 0, 1, or "don't care". A prefix is just a pattern ending in don't-cares,
so 203.0.113.128/25 is stored as 11001011 00000000 01110001 1xxxxxxx.
When several entries match, the TCAM reports the one with the lowest index. So if the entries are kept sorted longest prefix first, the first match is the longest match. The catch is cost: every bit of every entry has its own comparison logic, so TCAM is expensive, power-hungry and small, which is why router vendors pay close attention to the size of the global routing table.
A Packet's Journey, Hop by Hop
Time to send the Layers article's HTTP request for real. Here is the whole path from the laptop to the web server: our house, two of our ISP's routers, and the hosting company's data-centre router.
The cast
All MAC addresses are locally administered, 02:00:00:…, like the rest of the series. The
house's devices keep the addresses from the VLANs article. The new
point-to-point links use /30s, which have exactly two usable addresses, one for each end.
Every IPv4 address outside the house comes from the
documentation ranges.
| Device | Interface | IPv4 | MAC |
|---|---|---|---|
| Laptop | eth0 | 192.168.10.10/24 |
02:00:00:aa:bb:01 |
| R1 (home) | eth0.10 (LAN) | 192.168.10.1/24 |
02:00:00:cc:dd:02 |
| R1 (home) | eth1 (WAN) | 198.51.100.23/24 |
02:00:00:cc:dd:03 |
| R2 (ISP edge) | eth0 | 198.51.100.1/24 |
02:00:00:e2:00:00 |
| R2 (ISP edge) | eth1 | 192.0.2.1/30 |
02:00:00:e2:00:01 |
| R3 (ISP core) | eth0 | 192.0.2.2/30 |
02:00:00:e3:00:00 |
| R3 (ISP core) | eth1 | 192.0.2.5/30 |
02:00:00:e3:00:01 |
| R4 (DC router) | eth0 | 192.0.2.6/30 |
02:00:00:e4:00:00 |
| R4 (DC router) | eth1 | 203.0.113.1/24 |
02:00:00:e4:00:01 |
| Web server | eth0 | 203.0.113.80/24 |
02:00:00:dd:00:80 |
R1's WAN address came from the ISP's DHCP server, along with its default gateway, R2. R3
also has eth2 (192.0.2.10/30, to the transit provider at 192.0.2.9) and eth3
(192.0.2.14/30, to DC-2 at 192.0.2.13), which this packet won't use.
The routing tables
R3's table is the one from the previous section. The other three routers have small ones:
| Router | Prefix | Next hop, interface | Source |
|---|---|---|---|
| R1 | 192.168.10.0/24 |
direct, eth0.10 | connected |
| R1 | 192.168.20.0/24, .30.0/24 |
direct, eth0.20, eth0.30 | connected |
| R1 | 198.51.100.0/24 |
direct, eth1 | connected |
| R1 | 0.0.0.0/0 |
198.51.100.1, eth1 |
DHCP |
| R2 | 198.51.100.0/24 |
direct, eth0 | connected |
| R2 | 192.0.2.0/30 |
direct, eth1 | connected |
| R2 | 0.0.0.0/0 |
192.0.2.2, eth1 |
static |
| R4 | 192.0.2.4/30 |
direct, eth0 | connected |
| R4 | 203.0.113.0/24 |
direct, eth1 | connected |
| R4 | 0.0.0.0/0 |
192.0.2.5, eth0 |
static |
This is typical of the Internet's shape. Routers at the edges, like R1, R2 and R4, know their own networks and send everything else "up" a default route. Only routers in the middle, like R3, need to know where specific far-away networks are.
The packet
The laptop sends the same 77-byte packet as in the Layers article: a
20-byte IPv4 header, a 20-byte TCP header and 37 bytes of GET / HTTP/1.1…, with TTL 64,
Don't Fragment set, and identification 1c46. The one difference is the source address:
since the VLANs article, the laptop is 192.168.10.10, not 192.168.1.10. That changes
the header checksum from 20 62 to 17 62:
Fold the carry: , and flip the bits: .
Hop by hop
-
The laptop: a lookup and an ARP
The laptop's lookup for
203.0.113.80matches only its default route: via192.168.10.1. It already has the router's MAC in its ARP cache, so it sends the frame from…aa:bb:01to…cc:dd:02, TTL 64, checksum17 62. (Switch A tags it VLAN 10 on the trunk; the router receives it oneth0.10.) -
R1, the home router: default route, and NAT
The destination isn't one of R1's addresses. The longest match is
0.0.0.0/0via198.51.100.1oneth1, because none of its connected routes cover203.0.113.80. TTL 64 → 63. As the packet leaves for the Internet, NAT rewrites the source address192.168.10.10to R1's public198.51.100.23(keeping the TCP port, which many NATs do when they can). Both changes are folded into the checksum:17 62→b8 c9. R1 ARPs for198.51.100.1, learns…e2:00:00, and sends a new frame from…cc:dd:03to…e2:00:00. -
R2, the ISP edge: default route again
R2 only knows its two connected networks and a default route. Longest match:
0.0.0.0/0via192.0.2.2oneth1. TTL 63 → 62, checksum →b9 c9. New frame:…e2:00:01→…e3:00:00. -
R3, the ISP core: a specific route
The lookup from the previous section:
203.0.113.0/24via192.0.2.6oneth1, the eBGP route. TTL 62 → 61, checksum →ba c9. New frame:…e3:00:01→…e4:00:00. -
R4, the data-centre router: the last hop
203.0.113.0/24is directly connected oneth1, so there's no next router: the next hop is the destination itself. TTL 61 → 60, checksum →bb c9. R4 ARPs for203.0.113.80, gets…dd:00:80, and sends the final frame from…e4:00:01. The server sees its own MAC, its own IP, and hands the segment to TCP.
The five frames side by side:
| Link | Ethernet src → dst | TTL | Checksum |
|---|---|---|---|
| Laptop → R1 | …aa:bb:01 → …cc:dd:02 |
64 | 17 62 |
| R1 → R2 | …cc:dd:03 → …e2:00:00 |
63 | b8 c9 |
| R2 → R3 | …e2:00:01 → …e3:00:00 |
62 | b9 c9 |
| R3 → R4 | …e3:00:01 → …e4:00:00 |
61 | ba c9 |
| R4 → server | …e4:00:01 → …dd:00:80 |
60 | bb c9 |
And the IPv4 header itself on each link, all 20 bytes. Only the TTL and checksum change from hop to hop, plus the source address once, at the NAT:
The IPv4 header on each link
Laptop → R1 45 00 00 4d 1c 46 40 00 40 06 17 62 c0 a8 0a 0a cb 00 71 50
R1 → R2 45 00 00 4d 1c 46 40 00 3f 06 b8 c9 c6 33 64 17 cb 00 71 50
R2 → R3 45 00 00 4d 1c 46 40 00 3e 06 b9 c9 c6 33 64 17 cb 00 71 50
R3 → R4 45 00 00 4d 1c 46 40 00 3d 06 ba c9 c6 33 64 17 cb 00 71 50
R4 → server 45 00 00 4d 1c 46 40 00 3c 06 bb c9 c6 33 64 17 cb 00 71 50
c6 33 64 17 is 198.51.100.23. The destination,
cb 00 71 50 = 203.0.113.80, never changes.
Updating the checksum without starting over
Look at the pattern: after the NAT, each hop's checksum is exactly 0x0100 more than the
last. That's no coincidence. The TTL is the high byte of the 16-bit word it shares with the
protocol number, so going from 63 to 62 turns the word 3f06 into 3e06: the sum of the
header drops by 0x0100, and its complement, the checksum, rises by 0x0100.
A router doesn't need to re-add all ten words to find that out. RFC 1624 (1994) gives the incremental update, where HC is the old checksum, m the old value of the word that changed, and m′ the new value:
At R2, where the TTL goes from 63 to 62:
The same formula handles NAT's address change: apply it once for each 16-bit word that
changed. RFC 1624 corrected an earlier version, RFC 1141, which could produce ffff
(one's-complement "negative zero") in a case where the right answer is 0000. IPv6 sidesteps
all of this by having no header checksum at all.
The same trip over IPv6
The laptop also has 2001:db8:1234:10:0:ff:feaa:bb01, and the server has
2001:db8:113::80, so the browser will probably use IPv6 (see the
IPv6 article). The routers are the same, with IPv6 addresses on
each link: R2's eth0 is 2001:db8:1200:1::1 on the ISP access network, the R2–R3 link is
2001:db8:1200:f1::/64 (R2 ::1, R3 ::2), the R3–R4 link is 2001:db8:1200:f2::/64
(R3 ::1, R4 ::2), and the server's LAN is 2001:db8:113::/64 with R4 at ::1. The
home network gets its /56 from the ISP by DHCPv6 prefix delegation, and R2 has a route
for it: 2001:db8:1234::/56 via R1's link-local address.
| Link | Ethernet src → dst | Hop limit | Next hop |
|---|---|---|---|
| Laptop → R1 | …aa:bb:01 → …cc:dd:02 |
64 | fe80::ff:fecc:dd02 |
| R1 → R2 | …cc:dd:03 → …e2:00:00 |
63 | fe80::ff:fee2:0 |
| R2 → R3 | …e2:00:01 → …e3:00:00 |
62 | fe80::ff:fee3:0 |
| R3 → R4 | …e3:00:01 → …e4:00:00 |
61 | 2001:db8: |
| R4 → server | …e4:00:01 → …dd:00:80 |
60 | on-link |
The routing is the same, with three differences that make it simpler:
- No NAT. Whatever source address the laptop writes arrives at the server unchanged. If
the laptop used its stable address,
2001:db8:1234:10:0:ff:feaa:bb01, the server could see exactly which machine in the house is talking to it, which is why real IPv6 hosts normally send from a temporary address instead (we use the stable one so you can check every value). - No checksum. Each router just decrements the hop limit (and leaves the
flow label
7a3c1alone). - Neighbor Discovery instead of ARP. Each router resolves its next hop's MAC with a
Neighbor Solicitation (see Neighbor Discovery). Most of
the next hops are link-local addresses, learned from Router Advertisements (the laptop and
R1) or from the routing protocol (R2 and R3's OSPF). R3's next hop for the hosting
company's
/48is global, because that route came from eBGP, which advertises global addresses.
ICMP: The Network Talks Back
IP is a "best effort" protocol: routers drop packets when they must. But they don't always drop them silently. The Internet Control Message Protocol (ICMP, RFC 792, 1981) is how a router or host tells a packet's sender what went wrong. ICMP messages ride inside IP packets (protocol number 1; ICMPv6 is next header 58), and every error message carries the start of the packet that caused it, so the sender can tell which of its packets it was about. For IPv4 that's at least the IP header plus 8 bytes, enough to include the TCP or UDP ports; RFC 1812 asks routers to include as much as fits in 576 bytes. ICMPv6 includes as much as fits in 1,280.
| Message | ICMP (IPv4) | ICMPv6 | Sent when |
|---|---|---|---|
| Echo request / reply | 8 / 0 | 128 / 129 | Someone runs ping |
| Destination unreachable | 3 | 1 | No route, no host, no listener, or forbidden |
| Packet too big | 3, code 4 | 2 | The packet doesn't fit the next link |
| Time exceeded | 11 | 3 | TTL or hop limit ran out |
| Redirect | 5 | 137 | A better first hop exists on the sender's link |
| Parameter problem | 12 | 4 | Something in the header is malformed |
Time Exceeded
When a router receives a packet whose TTL would drop to zero, RFC 1812 says it must discard it and send an ICMP Time Exceeded message, type 11, code 0 ("TTL exceeded in transit"), back to the source. (Code 1 is a different timeout: a host gave up waiting for all the fragments of a packet to arrive.) The ICMPv6 equivalent is type 3, code 0, "hop limit exceeded in transit". Exactly which address the reply comes from matters for traceroute: RFC 1812 says it must be an address of the interface the ICMP message is sent out of, which is normally the interface pointing back towards the sender.
TTL originally meant time: RFC 791 (1981) defined it in seconds, with each router subtracting at least one. In practice no router holds a packet for anything like a second, so it became a pure hop count, and IPv6 renamed it honestly. Linux and macOS start packets at 64, Windows at 128, and many routers use 255 for packets they originate.
Destination Unreachable
Type 3 in IPv4, with a code saying why. The important ones:
- Code 0, network unreachable: the router has no route that matches at all (no default either).
- Code 1, host unreachable: the last router has a connected route, but ARP for the destination got no answer.
- Code 3, port unreachable: sent by the destination host itself. The packet arrived, but nothing is listening on that UDP port.
- Code 4, fragmentation needed: the packet is too big for the next link and has Don't Fragment set. This is IPv4's "packet too big".
- Code 13, communication administratively prohibited: a filter dropped it, and chose to say so.
ICMPv6's type 1 has similar codes: 0 no route, 1 administratively prohibited, 3 address unreachable (the Neighbor Discovery version of "ARP failed"), and 4 port unreachable.
Packet Too Big and path MTU discovery
Every link has a maximum packet size, its MTU, 1500 bytes on ordinary Ethernet. Suppose the R3–R4 link were a tunnel with an MTU of 1400. A full-size 1500-byte packet with Don't Fragment set arrives at R3, which can't send it. R3 drops it and returns ICMP type 3, code 4, with the next-hop MTU, 1400, in the message (a field added by RFC 1191 in 1990). The sender's TCP lowers its packet size for that destination and resends. That's path MTU discovery. In IPv6, routers never fragment, so the ICMPv6 Packet Too Big message (RFC 4443; path MTU discovery itself is RFC 8201) is essential, as the IPv6 article explained.
If a firewall somewhere blocks these messages, the sender never finds out. Small packets (the TCP handshake) get through, big ones vanish, and the connection hangs as soon as real data flows: a PMTU black hole.
Redirect
Suppose a host sends a packet to its default router, and the router's lookup says the next hop is another router on the same link the packet came in on. The router forwards the packet anyway, but also sends the host a Redirect (ICMP type 5, ICMPv6 type 137): "next time, send packets for that destination straight to that router." The rule in RFC 1812 is that a router only sends one when the packet leaves through the interface it arrived on and the sender is on the same subnet as the better next hop, which means a shorter path really did exist. Redirects are easy to forge, so many hosts and routers turn them off.
Traceroute: Mapping the Path With Errors
Time Exceeded messages are meant as error reports, but in 1987 Van Jacobson, then at Lawrence Berkeley Laboratory, turned them into a tool, from a suggestion by Steve Deering. The idea is beautifully simple:
-
Send a packet with TTL 1
The first router decrements it to zero, drops it, and sends back Time Exceeded. The reply's source address is the first router.
-
Send one with TTL 2
The first router passes it on with TTL 1; the second router drops it and replies. Now you know the second router.
-
Keep going until the destination answers
Linux's
traceroutesends UDP probes to an "unlikely" port, starting at 33434, and three probes per TTL. When a probe finally reaches the destination, no program is listening on that port, so the destination replies with Destination Unreachable, port unreachable, and traceroute knows it has arrived. It gives up after 30 hops by default.
Here is what that looks like from the laptop. (The round-trip times are illustrative, but their shape is typical: tiny inside the house, a jump at the ISP's access network, then a few milliseconds per hop.)
traceroute -n 203.0.113.80
$ traceroute -n 203.0.113.80
traceroute to 203.0.113.80 (203.0.113.80), 30 hops max, 60 byte packets
1 192.168.10.1 0.412 ms 0.368 ms 0.351 ms
2 198.51.100.1 8.127 ms 8.094 ms 8.311 ms
3 192.0.2.2 11.482 ms 11.430 ms 11.617 ms
4 192.0.2.6 14.903 ms 14.861 ms 15.022 ms
5 203.0.113.80 15.214 ms 15.180 ms 15.247 ms
Each line is one TTL, the address that answered, and the round-trip time of each of the
three probes. -n skips looking up names for the addresses.
Each router reports the address of the interface facing back towards us, as RFC 1812
requires: R2 answers as 198.51.100.1, not 192.0.2.1, and R3 as 192.0.2.2. Hop 1 is
R1 itself. For hops 2 to 4, the Time Exceeded messages are addressed to R1's public
address, 198.51.100.23, and R1's NAT looks at the copy of the probe inside each one to
work out that it belongs to the laptop.
The IPv6 version gives the same shape, without the NAT:
$ traceroute -n 2001:db8:113::80
traceroute to 2001:db8:113::80 (2001:db8:113::80), 30 hops max, 80 byte packets
1 2001:db8:1234:10::1 0.455 ms 0.402 ms 0.391 ms
2 2001:db8:1200:1::1 8.310 ms 8.266 ms 8.402 ms
3 2001:db8:1200:f1::2 11.633 ms 11.590 ms 11.811 ms
4 2001:db8:1200:f2::2 15.041 ms 14.998 ms 15.120 ms
5 2001:db8:113::80 15.302 ms 15.266 ms 15.355 ms
Reading traceroute output
* * *means no reply arrived for that TTL. The router may not send Time Exceeded at all, may rate-limit ICMP (routers are allowed to), or a firewall may drop the replies. The path usually continues fine past it.!H,!N,!Xafter a time mean a Destination Unreachable came back instead: host unreachable, network unreachable, administratively prohibited.- Other probe types. Windows'
tracertsends ICMP echo requests instead of UDP, and printsTracing route to 203.0.113.80 over a maximum of 30 hopsfollowed by lines like2 8 ms 8 ms 9 ms 198.51.100.1. Linux'straceroute -Idoes the same, andtraceroute -Tuses TCP SYNs to port 80, which get through firewalls that drop everything else. - Traceroute only sees the way out. Each line is one router's view of the forward path. The replies may come back by a completely different route, and the times include that return trip.
- Multiple paths confuse it. If a router spreads traffic over several equal paths,
successive probes, which differ in UDP port, may take different ones, and the output
mixes routers from both. Paris traceroute (2006) fixes this by keeping the fields
routers hash on constant across probes.
mtrruns traceroute continuously and shows loss and latency per hop.
Scenario
Loops, Black Holes and Asymmetric Paths
A routing loop
Routing tables are built independently, router by router, and nothing forces them to agree. Suppose an engineer at the ISP is testing something and adds this static route to R3, in the Cisco-style syntax R3's router OS uses:
ip route 203.0.113.0 255.255.255.0 192.0.2.1
It sends the hosting company's /24 to R2. R3 still has its eBGP route for the same /24,
but a static route's administrative distance is 1, which beats eBGP's 20, so the new route
wins. R2, meanwhile, has no route for 203.0.113.0/24 except its default, which points
straight back at R3. Each router thinks the other one is closer to the server.
Follow our packet. R1 forwards it with TTL 63, R2 sends it to R3 with 62, R3 back to R2 with 61, and so on. R2 always receives odd TTLs and R3 even ones, so it's R2 that finally receives it with TTL 1, drops it, and sends Time Exceeded. Going by the traceroute times below, that is about a tenth of a second of wasted bandwidth on the R2–R3 link, and then the packet is gone: the loop is self-limiting. Compare the switching loop, where frames with no TTL circled until someone pulled a cable: that difference is the reason the TTL field exists.
Traceroute makes a loop obvious. The same two addresses repeat until traceroute gives up:
$ traceroute -n 203.0.113.80
traceroute to 203.0.113.80 (203.0.113.80), 30 hops max, 60 byte packets
1 192.168.10.1 0.398 ms 0.361 ms 0.349 ms
2 198.51.100.1 8.204 ms 8.161 ms 8.377 ms
3 192.0.2.2 11.513 ms 11.468 ms 11.702 ms
4 198.51.100.1 11.556 ms 11.497 ms 11.731 ms
5 192.0.2.2 14.812 ms 14.779 ms 14.950 ms
6 198.51.100.1 14.864 ms 14.801 ms 14.993 ms
...
29 192.0.2.2 54.317 ms 54.262 ms 54.480 ms
30 198.51.100.1 54.371 ms 54.309 ms 54.522 ms
(Odd hops from 3 onward are R3, even hops are R2. Every two hops adds another round trip across the R2–R3 link.) Real loops are more often transient than typed in: while a routing protocol is reconverging after a failure, some routers have heard the news and some haven't, and for a few hundred milliseconds two of them may point at each other. The routing protocols in the next articles spend a lot of effort keeping those moments short.
Black holes
A black hole is the opposite failure: traffic goes in and nothing comes out, not even an ICMP error. Some are deliberate:
- Blackhole (null) routes. R3's
198.51.100.99/32route discards everything for the customer under attack, so the flood stops at the ISP's core instead of filling the customer's line. Doing this on request, triggered by a BGP announcement, is called remotely triggered black hole filtering (RFC 3882; RFC 7999 standardised the BLACKHOLE community that requests it, and RFC 5635 extends the idea to filtering by source). On Linux it'sip route add blackhole 198.51.100.99/32; Cisco writesNull0as the interface. - Discard routes for aggregates. R3 tells the world that it is the way to
2001:db8:1200::/40, the ISP's whole IPv6 block. Without the blackhole route for the/40, a packet for an unassigned address like2001:db8:12ab::1would match only R3's default, go back out to the transit provider, which would send it back to R3 because of the/40, and loop until its hop limit ran out. The discard route turns a loop into a clean drop. Home routers do the same for their delegated prefix, as RFC 7084 requires: R1 has an unreachable route for2001:db8:1234::/56, so packets for the 253 subnets it doesn't use are dropped with an ICMPv6 error instead of bounced back to R2.
Others are accidents:
- A dead next hop. If R2's static default pointed at a router that had crashed but whose link stayed up, R2 would keep sending packets to it, ARP would fail, and they would vanish. Static routes can't tell; dynamic routing protocols notice when a neighbour stops talking.
- A missing return route. If R3 had no route back to
198.51.100.0/24, our packets would reach the server fine, but every reply would follow R3's default route to the transit provider and never come home. From the laptop, it looks like the server is down. - Filtered ICMP, causing the PMTU black hole from the ICMP section.
Asymmetric routing
Nothing requires the reply to take the same path as the request. Each router decides only
the next hop for the packet in front of it, and the server's replies are routed by a
different set of tables: R4's default, R3's route for 198.51.100.0/24, R2's connected
route. Here they happen to retrace our path. But if the hosting company had a second
upstream, its replies might go out through DC-2 and a different ISP entirely, while our
requests come in through R3. That's asymmetric routing, and on the Internet it's
normal, especially between different providers.
It's mostly harmless, but it has consequences. Traceroute only ever shows you half the
story. A stateful firewall that sees only one direction of a connection will block it.
And a router doing strict reverse-path filtering (RFC 3704), which drops packets that
arrive on an interface it wouldn't use to reach their source, a cheap way to block spoofed
addresses, will drop legitimate asymmetric traffic too. That's why ISPs use the "strict"
mode only towards single-homed customers, and Linux's rp_filter has a "loose" setting.
Static and Dynamic Routing: Control Plane and Data Plane
Every route in this article so far was either connected or typed in, except R3's OSPF and BGP routes. That's fine for R1, R2 and R4, whose tables barely change. It doesn't scale to R3, which would need a person to update it every time a customer was added, a link failed, or another network on the Internet changed its addresses. Static routing means the tables are configured by hand; dynamic routing means routers run a routing protocol to tell each other which networks they can reach, and rebuild their tables when anything changes.
Either way, a router is really two systems:
- The control plane decides. It runs the routing protocols, keeps every route it has heard in the RIB (routing information base), applies administrative distance and metrics, and installs the winners in the FIB (forwarding information base). It's ordinary software on a general-purpose CPU, and it works on a timescale of milliseconds to minutes.
- The data plane does. For every packet it does the longest-prefix match in the FIB, the TTL and checksum update, and the header rewrite. On a big router it's a dedicated chip with TCAM or SRAM tries; on a Linux box it's the kernel's forwarding path. It works on a timescale of nanoseconds.
On Linux the split is visible. The kernel's routing table is the FIB. Routing daemons
such as FRR or BIRD hold their own RIB, pick winners, and install them into the kernel
over the netlink interface, tagged with their origin, which is what the proto field in
ip route output shows (proto kernel, proto dhcp, proto ospf, proto bgp). Splitting
the two planes also means the data plane keeps forwarding while the control plane restarts,
and it's what software-defined networking takes further, by moving the control plane out of
the box altogether.
ECMP: using more than one path
If the tie-breaks leave several routes with the same prefix, source and metric, a router can install them all: equal-cost multipath. Rather than alternate packet by packet, which would deliver a TCP connection's packets out of order, it hashes each packet's addresses and ports (and, for IPv6, possibly the flow label) and uses the hash to pick a path. Every packet of one connection takes the same path, and different connections spread across all of them. ECMP is what lets the leaf-spine data-centre fabrics from the Spanning Tree article use every link at once. On Linux:
ip route add 203.0.113.0/24 nexthop via 192.0.2.6 dev eth1 nexthop via 192.0.2.13 dev eth3
Policy routing: more than one table
Ordinary routing looks only at the destination. Policy routing lets other things choose the table: the source address, the incoming interface, a firewall mark. Linux has several routing tables and a list of rules saying which to consult, in order. Out of the box, the rules are:
$ ip rule
0: from all lookup local
32766: from all lookup main
32767: from all lookup default
The local table (number 255) holds the machine's own addresses and broadcast addresses,
main (254) is what ip route shows, and default (253) is normally empty. To send the
guest VLAN's traffic out through a separate VPN, say, R1 could add a rule
ip rule add from 192.168.30.0/24 lookup 30 and put a different default route in table 30.
Routers from other vendors offer the same thing under names like "policy-based routing"
or "filter-based forwarding".
Routing Tables on Your Own Machine
Linux
We've seen the laptop's table. Here is R1's, a Linux home router:
$ ip route
default via 198.51.100.1 dev eth1 proto dhcp src 198.51.100.23 metric 1024
192.168.10.0/24 dev eth0.10 proto kernel scope link src 192.168.10.1
192.168.20.0/24 dev eth0.20 proto kernel scope link src 192.168.20.1
192.168.30.0/24 dev eth0.30 proto kernel scope link src 192.168.30.1
198.51.100.0/24 dev eth1 proto kernel scope link src 198.51.100.23
$ ip route get 203.0.113.80
203.0.113.80 via 198.51.100.1 dev eth1 src 198.51.100.23 uid 0
cache
The src field is the source address the router uses for packets it originates on that
route. Host routes for the machine's own addresses live in the local table:
$ ip route show table local
local 127.0.0.0/8 dev lo proto kernel scope host src 127.0.0.1
local 127.0.0.1 dev lo proto kernel scope host src 127.0.0.1
broadcast 127.255.255.255 dev lo proto kernel scope link src 127.0.0.1
local 192.168.10.1 dev eth0.10 proto kernel scope host src 192.168.10.1
broadcast 192.168.10.255 dev eth0.10 proto kernel scope link src 192.168.10.1
...
(192.168.10.1 without a length is a /32: a host route.) For IPv6, ip -6 route on the
laptop shows the loopback address, the prefix from the Router Advertisement, the
link-local prefix, and a default route whose next hop is the router's link-local address:
$ ip -6 route
::1 dev lo proto kernel metric 256 pref medium
2001:db8:1234:10::/64 dev eth0 proto ra metric 100 pref medium
fe80::/64 dev eth0 proto kernel metric 1024 pref medium
default via fe80::ff:fecc:dd02 dev eth0 proto ra metric 100 pref medium
Linux also has the special route types we've met: blackhole drops silently,
unreachable drops and sends an ICMP host unreachable, and prohibit sends
"administratively prohibited". R1's protective route for its /56 is
unreachable 2001:db8:1234::/56. Adding and removing routes is ip route add and
ip route del, for example R2's default:
ip route add default via 192.0.2.2 dev eth1.
Windows and macOS
Windows shows its table with route print (or route print -4 for just IPv4). The laptop's
IPv4 table, if it ran Windows, would look like this (an excerpt; the multicast and limited-broadcast rows are omitted):
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 192.168.10.1 192.168.10.10 25
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
192.168.10.0 255.255.255.0 On-link 192.168.10.10 281
192.168.10.10 255.255.255.255 On-link 192.168.10.10 281
192.168.10.255 255.255.255.255 On-link 192.168.10.10 281
The same information in a different costume: masks instead of prefix lengths, "On-link"
instead of scope link, and the host routes mixed in with the rest. The metric is the
route's metric plus the interface's. On macOS, netstat -rn prints the table and
route get 203.0.113.80 does the lookup.
How Routers Learn Routes
R3 learned 198.51.100.0/24 from OSPF and 203.0.113.0/24 from BGP. How? There are three
big families of routing protocol, and each of the next three articles takes one apart:
- Distance-vector (RIP, and the ideas inside BGP and EIGRP). Each router tells its neighbours "here are the networks I can reach, and how far away they are". Simple, and needs little memory, but bad news travels slowly, and the classic failure is two routers counting to infinity while a packet loops between them, like our R2 and R3.
- Link-state (OSPF, IS-IS). Every router floods a description of its own links to every other router, so they all build the same map of the network, and each runs Dijkstra's shortest-path algorithm on it. Fast to converge and loop-free once everyone agrees, at the cost of more memory and computation.
- BGP, the Border Gateway Protocol, the one routing protocol of the
Internet between organisations. It's a path-vector protocol: routes carry the list of
networks they've passed through, and each network applies its own policy, business
relationships as much as distance, to decide which to use and which to pass on. It's how
R3 heard about the hosting company's
/24and/25, and how every network learns about every other.
Whatever the protocol, the output is the same thing: entries in the RIB, the best of which end up in the FIB, looked up by longest-prefix match exactly as in this article.
Where to Go Next
- Distance-Vector Routing: the simplest way for routers to fill in their tables automatically, and the loops it can create.
- Link-State Routing: flooding a map of the network and running Dijkstra on it.
- BGP: how the Internet's networks tell each other where every prefix lives.
- NAT: what R1 was doing to the source address, and how the replies find their way back.
- IPv4 Addressing and IPv6: prefixes, aggregation, and the address plans the routes are built from.
- Layers & Encapsulation: the packet we just routed, byte by byte.
Key Takeaways
- A router forwards between networks by destination IP. At each hop it decrements the TTL (IPv6: hop limit), updates the IPv4 header checksum, and builds a new Ethernet header addressed to the next hop's MAC, found by ARP or Neighbor Discovery. IP addresses stay the same end to end, except where NAT rewrites them.
- A routing table maps prefixes to a next hop and an outgoing interface. Routes are connected, static, or learned dynamically;
0.0.0.0/0and::/0are default routes,/32and/128are host routes. A host's "local or remote?" decision is just a lookup in its own two-route table. - Longest-prefix match picks the most specific matching prefix. Only between routes for the same prefix does administrative distance decide, then metric; any remaining tie can be shared with ECMP.
- Lookups must take nanoseconds, so routers use tries (Patricia, multibit, LC-trie, DIR-24-8) or TCAM, which compares every entry at once and returns the first, longest match.
- In the walkthrough the TTL went 64 → 60 over four routers and the checksum went
17 62→b8 c9(TTL plus NAT) →b9 c9→ba c9→bb c9. RFC 1624's incremental update, HC′ = ~(~HC + ~m + m′), avoids re-adding the whole header. - ICMP reports problems to the sender: Time Exceeded (11; ICMPv6 3), Destination Unreachable (3; ICMPv6 1), fragmentation needed / Packet Too Big for path MTU discovery, and Redirect (5; ICMPv6 137).
- Traceroute sends probes with TTL 1, 2, 3… and lists the routers that send back Time Exceeded, until the destination answers with port unreachable. It shows only the forward path.
- TTL makes routing loops self-limiting. Black holes drop traffic silently, deliberately (null routes, discard routes for aggregates) or by accident. Paths can be asymmetric.
- The control plane (routing protocols, RIB) chooses routes; the data plane (FIB) forwards packets. Static routes are typed in; distance-vector, link-state and BGP protocols learn them automatically.
R3's table had routes from OSPF and BGP, and we simply took them as given. In the next article, routers start with nothing but their connected networks and fill in their tables by gossiping with their neighbours: Distance-Vector Routing, and the curious problem of counting to infinity.