On 24 February 2008, for about two hours, a lot of the Internet couldn’t reach YouTube. Its traffic was going to Pakistan instead. Nobody hacked YouTube. Pakistan Telecom made an announcement, and the rest of the Internet believed it 1.
That announcement was made in BGP, the protocol networks use to tell each other what they can reach. In this article, let’s see how BGP works, and why it believed Pakistan.
Problem
The Internet isn’t one network. It’s a lot of independent ones: ISPs, cloud providers, universities, companies. Each runs its own routers its own way. RFC 4271 calls each of them an Autonomous System (AS): “a set of routers under a single technical administration” 2. Each AS has a number. YouTube was AS36561, Pakistan Telecom AS17557 1.
Addresses are handed out in blocks called prefixes. 208.65.152.0/22 means “every address whose first 22 bits match 208.65.152.0”. That’s 1024 addresses.
There is no central map of which AS has which prefix, and no single company that could keep one. So every AS has to learn it from its neighbours. That’s BGP’s job.
Passing paths around
BGP is a path vector protocol. It works like gossip:
- An AS that owns a prefix tells its neighbours: “I can reach 203.0.113.0/24”. The route carries an AS_PATH, the list of ASes the announcement went through. The owner starts it with its own number 2.
- A neighbour that accepts the route passes it on to its own neighbours, with its own number added at the front 2.
- If an AS sees its own number already in the path, the announcement went in a circle, and it drops it 2. That’s all it takes to avoid routing loops.
Each AS may hear about the same prefix from several neighbours. Which one does it use? First its own policy, e.g., “prefer routes from customers who pay me”. RFC 4271 calls this the degree of preference, usually set with LOCAL_PREF 2. Among equally preferred routes, the first tie-breaker is “the smallest number of AS numbers” in the path 2.
Here are 8 networks. Press the first button and watch AS1’s announcement spread, one round at a time. The grey text under each AS is the path it picked:
Each round, every AS only talks to its direct neighbours. After a few rounds, everyone has a path to AS1, and no one ever saw the whole map.
Longest match
Now the second rule, and the one that matters for YouTube. When a router forwards a packet, several prefixes in its table may cover the destination, e.g., a /22 and a /24 inside it. “Forwarding in the Internet is done on a longest-match basis” 3: the most specific prefix wins.
Here is what happened that Sunday, using RIPE NCC’s timeline. youtube.com resolved to 208.65.153.238 1. Step through it and watch which route wins:
To give you a summary:
- YouTube announced a /22. Pakistan Telecom announced a /24 inside it. Pakistan was trying to block YouTube 1.
- Its upstream, PCCW Global, passed the /24 to the rest of the Internet. The /24 was more specific, so it won everywhere it reached.
- YouTube fought back with the same /24, then with two /25s, which beat the /24 by the same rule.
- It ended when PCCW withdrew Pakistan Telecom’s routes 1.
Go back to the simulator above and press AS8 announces the same /24, then AS8 announces two /25s. The first only pulls in the networks that are closer to AS8. The second takes everyone, however long the path.
Notice what BGP never asked: does AS8 own this address? Plain BGP has no way to check. It trusts what its neighbours tell it.
Withdrawing
Routes don’t just appear, they also go away. An AS can withdraw a route, and its neighbours drop it and look for another path 2.
On 4 October 2021, Facebook disappeared from the Internet. Its DNS servers were set up to stop announcing their BGP routes if they couldn’t reach Facebook’s data centers. During routine maintenance, a command “unintentionally took down all the connections in our backbone network”, so every DNS site withdrew its routes. “The end result was that our DNS servers became unreachable even though they were still operational” 4.
Press Reset, then AS1 announces /24, then AS1 withdraws in the simulator. Routes don’t vanish in one step. For a few rounds, ASes switch to longer and longer paths through each other, until loop detection throws every one of them out.
Final Thoughts
BGP holds the Internet together, but it’s built on trust. A few limits worth knowing:
- Any AS can announce any prefix, and a more specific one wins. RPKI origin validation lets a prefix holder say which AS may originate it, but even its RFC calls it a mechanism to “partially satisfy” the requirement 5. It checks the origin, not the whole path.
- The shortest path is counted in ASes, not milliseconds 2. A path through 2 slow networks beats one through 3 fast ones.
- Changes take rounds to settle, and a withdrawal can make networks hunt through bad paths before giving up.
YouTube’s fix in 2008 was to play by the same rule that hurt it: announce something even more specific 1.
Footnotes
-
RIPE NCC, YouTube Hijacking: A RIPE NCC RIS case study, 2008. ↩ ↩2 ↩3 ↩4 ↩5 ↩6
-
Y. Rekhter, T. Li and S. Hares, RFC 4271: A Border Gateway Protocol 4 (BGP-4). The AS definition in section 1.1; AS_PATH and prepending in 5.1.2; degree of preference and LOCAL_PREF in 9.1.1 and 5.1.5; AS loop detection and tie-breaking in 9.1.2 and 9.1.2.2; withdrawn routes in 4.3. ↩ ↩2 ↩3 ↩4 ↩5 ↩6 ↩7 ↩8
-
V. Fuller and T. Li, RFC 4632: Classless Inter-domain Routing (CIDR), section 5.1. ↩
-
Santosh Janardhan, Engineering at Meta, More details about the October 4 outage, October 2021. ↩
-
P. Mohapatra et al., RFC 6811: BGP Prefix Origin Validation, abstract. ↩