Sub topic 13
Neighbor Discovery and Router Advertisements
What this chapter assumes
This chapter assumes you can read compressed IPv6 addresses and know the address types from earlier chapters. You should know link-local (fe80::/10) and multicast (ff00::/8) addresses. You should also know how a host builds an interface identifier. You should understand ARP in IPv4 and what a default gateway does.
What Neighbor Discovery does
Neighbor Discovery Protocol (NDP) is the set of ICMPv6 messages that IPv6 nodes use to find each other on a link. It replaces ARP and also covers router discovery, prefix discovery, duplicate address detection, and redirects. NDP runs inside ICMPv6 and needs no separate protocol or broadcast. Because it uses link-local and multicast addresses, a host can use it before it has any global address.
| ICMPv6 type | Message | Sent to | Purpose |
|---|---|---|---|
| 133 | Router Solicitation (RS) | `ff02::2` (all routers) | A host asks routers to announce themselves now |
| 134 | Router Advertisement (RA) | `ff02::1` (all nodes) or the soliciting host | A router announces prefixes, flags, and its own availability |
| 135 | Neighbor Solicitation (NS) | Solicited-node multicast or a unicast address | Resolve a link-layer address, check reachability, or test an address for duplicates |
| 136 | Neighbor Advertisement (NA) | The solicitor or `ff02::1` | Answer an NS or announce a change |
| 137 | Redirect | A host | A router points a host to a better next hop |
Every NDP message is sent with a hop limit of 255. A receiver discards any message with a lower value. A packet that crossed a router would have a lower hop limit, so this check keeps off-link attackers from injecting NDP messages.
Address resolution without ARP
ARP broadcasts to every host on the link. NDP narrows the audience with a solicited-node multicast address. It is formed from the prefix ff02::1:ff00:0/104 plus the low 24 bits of the unicast address being resolved. Hosts whose addresses end in the same 24 bits share a group, so a query usually reaches one host or a few.
import ipaddress
def solicited_node(addr):
low24 = int(ipaddress.IPv6Address(addr)) & 0xFFFFFF
base = int(ipaddress.IPv6Address("ff02::1:ff00:0"))
return ipaddress.IPv6Address(base | low24)
print(solicited_node("2001:db8::ff00:42:8329")) # ff02::1:ff42:8329
print(solicited_node("fe80::21a:2bff:fe3c:4d5e")) # ff02::1:ff3c:4d5eThe Ethernet destination for such a multicast is 33:33: followed by the last 32 bits of the IPv6 address. A network card can filter these frames in hardware, so unrelated hosts are not interrupted.
The exchange works like this:
- Host A wants to send to
2001:db8::10on its link. It has no cache entry. - A sends an NS to the solicited-node address of
2001:db8::10. The NS carries A's own link-layer address in a Source Link-Layer Address option. - The owner of
2001:db8::10replies with a unicast NA. The NA has the Solicited flag set and carries the owner's link-layer address. - A stores the mapping in its neighbor cache and sends the queued packet.
Neighbor cache states
The neighbor cache is the IPv6 counterpart of the ARP table. Each entry has a state that tracks how fresh the mapping is.
| State | Meaning |
|---|---|
| INCOMPLETE | An NS was sent and no reply has arrived yet |
| REACHABLE | A confirmation arrived within the reachable time (30 seconds by default, randomized) |
| STALE | The time has expired. The entry is kept but not verified |
| DELAY | A packet was sent to a stale entry. The host waits briefly for upper-layer confirmation, such as a TCP acknowledgment |
| PROBE | The host sends unicast NS messages to confirm the neighbor is still there |
This design is called Neighbor Unreachability Detection. A host learns that a neighbor or router has failed from the cache entry itself. It does not wait for an application timeout. It can then pick another default router.
Duplicate Address Detection
Before a host uses any unicast address, it must check that nobody else on the link has it. This check is Duplicate Address Detection (DAD). The address is "tentative" during the check. The host sends an NS whose source is the unspecified address :: and whose target is the tentative address. The destination is the solicited-node multicast of that address. If a node replies with an NA, or sends its own DAD NS for the same address, the address is a duplicate and the host does not use it. If nothing arrives within the retransmit interval (one second by default), the address becomes usable. DAD applies to link-local, SLAAC, and DHCPv6 addresses alike.
The Router Advertisement
An RA is how a router tells hosts how to configure themselves. Routers send RAs periodically (every few minutes by default on many systems) and in reply to an RS. The key fields are:
| Field or option | Meaning |
|---|---|
| Cur Hop Limit | Default hop limit hosts should put in outgoing packets |
| M flag | Managed. Hosts should use DHCPv6 for addresses |
| O flag | Other. Hosts should use DHCPv6 for other information, such as DNS servers |
| Router Lifetime | Seconds the router can serve as a default router. A value of 0 means it is not a default router |
| Prefix Information option | A prefix, its length, and the L and A flags, with valid and preferred lifetimes |
| L flag (on-link) | Addresses in this prefix are reachable directly on this link |
| A flag (autonomous) | Hosts may build an address from this prefix using SLAAC |
| MTU option | The link MTU to use |
| RDNSS option | DNS server addresses (RFC 8106) |
| Source Link-Layer Address | The router's own MAC address, so hosts need no NS to reach it |
The RA is the starting point for SLAAC, which the next chapter covers. A prefix with A set tells the host to combine the prefix with its own interface identifier. A prefix with M set sends the host to a DHCPv6 server.
The source address of an RA is always the router's link-local address. A host therefore learns its default gateway as a link-local address such as fe80::1. It does not learn a global address.
Redirects
When a router receives a packet and sees that the sender could reach the destination through a better router on the same link, it forwards the packet. It also sends a Redirect to the sender. The Redirect names the better next hop. The host adds this to its destination cache. Redirects must come from the current first-hop router's link-local address. Many networks filter them for security.
Inspecting NDP on Linux
These commands show the neighbor cache, the routes learned from RAs, and the sysctl that controls whether a host accepts RAs.
ip -6 neigh show
ip -6 route show default
sysctl net.ipv6.conf.all.accept_ra
ping -6 -c 3 ff02::1%eth0In the ip -6 neigh output, each line ends with a state such as REACHABLE or STALE. A default route learned from an RA includes proto ra and an expires value that counts down from the router lifetime. The last command pings all nodes on the link. Replace eth0 with your interface name. The %eth0 zone ID is required for link-local and link-scope multicast targets because the same address is valid on every interface.
Common errors
- Blocking ICMPv6 entirely. An IPv4 habit is to drop ICMP. Doing this for IPv6 breaks address resolution, DAD, and autoconfiguration. Allow types 133 to 137 on the local link, and allow Packet Too Big messages for path MTU discovery.
- Forgetting the zone ID.
ping fe80::1fails or picks the wrong interface on a host with several links. Usefe80::1%eth0. - Rogue Router Advertisements. Any device on the link can send an RA, such as a laptop with connection sharing. Hosts then adopt it as their default gateway. RA Guard on switches blocks RAs from ports that are not router ports.
- Router lifetime of 0. The router advertises prefixes but is not a default router, so hosts get no default route. This is deliberate in some designs, but it often appears by mistake.
- A prefix longer or shorter than /64. SLAAC requires a 64-bit interface identifier, so an RA with the A flag on a prefix that is not /64 does not produce working addresses.
- Leaving NDP traffic unlimited. A scan of a /64 can fill a router's neighbor cache with INCOMPLETE entries. Routers need cache size limits and rate limits.
Exercise
A host has the global address 2001:db8:5::a1b2:c3d4. It must resolve the link-layer address of that same address on a neighbor. To which multicast group does it send the Neighbor Solicitation? Then name two things that would be wrong if the router advertisement for this link carried a Router Lifetime of 0.
Show answer
The solicited-node group takes the low 24 bits of the address (0xb2c3d4) and appends them to ff02::1:ff00:0/104. The group is ff02::1:ffb2:c3d4. With a Router Lifetime of 0, hosts would not install a default route from that router, so they could not reach off-link destinations through it. They could still use its prefixes for on-link and SLAAC address purposes if the prefix options allow it. The router also stops being a candidate for Neighbor Unreachability Detection failover as a default router.