Neighbor Discovery
Neighbor Discovery Protocol (NDP) is an important basic protocol used with IPv6. It is an enhancement of the Address Resolution Protocol (ARP) and Internet Control Management Protocol (ICMP) router discovery used with IPv4. In addition to the function of ICMPv6 address resolution, NDP also provides the following functions: neighbor tracking, duplicate address detection, router discovery, and redirection.
Address Resolution
To communicate with a destination host, a source host needs to first obtain the destination host's link-layer address. In IPv4, this is achieved through ARP, whereas in IPv6, this is achieved through NDP.
- Layer 3 address resolution enables Layer 2 devices to use the same address resolution protocol.
- Layer 3 security mechanisms are used to prevent address resolution attacks.
- Request packets can be sent in multicast mode, reducing load on Layer 2 networks.
- In NS messages, the Type and Code field values are 135 and 0, respectively. These messages are similar to IPv4 ARP Request messages.
- In NA messages, the Type and Code field values are 136 and 0, respectively. These messages are similar to IPv4 ARP Reply messages.
Figure 8-10 shows the process of address resolution.
Before sending messages to Host B, Host A must obtain Host B's link-layer address. To accomplish this, Host A sends an NS message with its IPv6 address as the source address and the solicited-node multicast address of Host B as the destination address. In the NS message, the Options field carries Host A's link-layer address.
After receiving the NS message, Host B replies with an NA message. In the NA message, the source address is Host B's IPv6 address, the destination IPv6 address is Host A's IPv6 address, and the destination link-layer address is Host A's link-layer address read from the NS message. The Options field in the NA message carries Host B's link-layer address. This address resolution process enables Host A to obtain Host B's link-layer address.
Neighbor State Tracking
Hardware faults and hot swapping of interface cards interrupt communication with neighboring devices. This means that a neighbor can transit from one state to another. Communication cannot be restored if the destination of a neighboring device becomes invalid, but it can be restored if the path fails. To monitor the state of each neighboring device, nodes therefore need to maintain a neighbor table.
RFC2461 defines five neighbor states: Incomplete, Reachable, Stale, Delay, and Probe.
Figure 8-11 shows the transition of neighbor states. The Empty state indicates that the neighbor table is empty.
The following example describes changes in the neighbor state of node A during its first communication with node B.
- Node A sends an NS message and generates a cache entry. The neighbor state of node A is Incomplete.
- If node B replies with an NA message, the neighbor state of node A changes from Incomplete to Reachable. Otherwise, the neighbor state changes from Incomplete to Empty after a certain period of time, and node A deletes this entry.
- After the neighbor reachable time times out, the neighbor state changes from Reachable to Stale, indicating that the neighbor reachable state is unknown.
- If node A in the Reachable state receives a non-NA Request message from node B, and the link-layer address of node B carried in the message is different from that learned by node A, the neighbor state of node A changes to Stale.
- If node A sends data to node B, the neighbor state of node A changes from Stale to Delay.
- After a period of time, the neighbor state of node A changes from Delay to Probe and an NS message is sent. During this time, if node A receives an NA Reply message, the neighbor state of node A changes from Delay to Reachable.
- Node A in the Probe state sends several unicast NS messages at the configured interval. If node A receives a Reply message, the neighbor state of node A changes from Probe to Reachable. Otherwise, the state changes to Empty and node A deletes the entry.
Duplicate Address Detection
Before an IPv6 unicast address is assigned to an interface, duplicate address detection (DAD) is performed to check whether another node uses the address. DAD is required if IP addresses are configured automatically. An IPv6 unicast address assigned to an interface but not verified by DAD is called a tentative address. An interface cannot use the tentative address for unicast communication but will join two multicast groups: ALL-nodes multicast group and Solicited-node multicast group.
IPv6 DAD is similar to IPv4 gratuitous ARP. A node sends an NS message that requests the tentative address as the destination address to the solicited-node multicast group. If the node receives an NA Reply message, another node is using the tentative address for communication. This node will not use this tentative address for communication.
Figure 8-12 shows an example of DAD.
The IPv6 address FC00::1 is assigned to Host A as a tentative IPv6 address. To check the validity of this address, Host A sends an NS message containing the requested address FC00::1 to the Solicited-node multicast group to which FC00::1 belongs. Since FC00::1 is not specified, the source address of the NS message is an unspecified address. After receiving the NS message, Host B processes the message in one of the following ways:
If FC00::1 is a tentative address of Host B, Host B will not use this address as an interface address and will not send an NA message.
If FC00::1 is in use on Host B, Host B sends an NA message to FF02::1 carrying IP address FC00::1. In this way, Host A can find and mark the duplicate tentative address after receiving the message, and the address does not take effect on Host A.
Router Discovery
Router discovery is used to locate neighboring devices and learn their address prefixes and configuration parameters for address autoconfiguration.
IPv6 supports stateless address autoconfiguration. Hosts obtain IPv6 prefixes and automatically generate interface IDs. Router Discovery is the basis of IPv6 address autoconfiguration and is implemented through the following two types of packets:
- Router Advertisement (RA) message: Each router periodically sends multicast RA messages carrying network prefixes and identifiers on the network to declare its existence to Layer 2 hosts and devices. An RA message has a Type field value of 134.
- Router Solicitation (RS) message: After being connected to the network, a host immediately sends an RS message to obtain network prefixes. Devices on the network reply with RA messages. An RS message has a Type field value of 133.
Figure 8-13 shows the router discovery function.
Address Autoconfiguration
IPv4 uses DHCP to automatically configure IP addresses and default gateways. This simplifies network management. The length of an IPv6 address is increased to 128 bits. Multiple terminal nodes require the function of automatic configuration. IPv6 allows both stateful and stateless address autoconfiguration. Stateless autoconfiguration enables hosts to automatically generate link-local addresses. Hosts automatically configure global unicast addresses and obtain other information based on prefixes in the RA message.
The process of IPv6 stateless autoconfiguration is as follows:
- A host automatically configures the link-local address based on the interface ID.
- The host sends an NS message for duplicate address detection.
- If address conflict occurs, the host stops address autoconfiguration. Then addresses need to be configured manually.
- If addresses do not conflict, the link-local address takes effect. The host then connects to the network and communicates with the local node.
- The host either sends an RS message or receives RA messages devices periodically send.
- The host obtains the IPv6 address based on the prefixes carried in the RA message and the interface ID.
Default Router Priority and Route Information Discovery
If there are multiple devices on the network where hosts reside, hosts need to select forwarding devices based on the destination address of the packet. In such a case, devices advertise default router priorities and route information, which allows hosts to select the optimal forwarding device based on the packet destination address.
The fields of default router priority and route information are defined in an RA message. These two fields enable hosts to select the optimal forwarding device.
After receiving an RA message containing route information, hosts update their routing tables. When sending packets to other devices, hosts check the routing table and select the optimal route.
When receiving an RA message carrying default router priorities, hosts update their default router lists. When sending packets to other devices, hosts select the device with the highest priority to forward packets from the router list. If the selected router does not work, hosts select the subsequent device in descending order of priority.
Redirection
To choose an optimal gateway device, the gateway device sends a Redirection message to notify the sender that another gateway device can send packets. Redirection messages are contained within ICMPv6 messages and have a Type field value of 137. They carry a better next hop address and destination address for packets that need to be redirected.
Figure 8-14 shows an example of packet redirection.
Host A needs to communicate with Host B. By default, Router A sends packets from Host A to Host B. After receiving packets from Host A, Router A discovers that sending packets directly to Router B is more efficient. Router A sends a Redirection message carrying the destination address of Host B to Host A to notify Host A that Router B is a better next hop address. After receiving the Redirection message, Host A adds a host route to the default routing table. Packets sent to Host B will be sent directly to Router B.
A device sends a Redirection message in the following situations:
- The destination address of the packet is not a multicast address.
- Packets are not forwarded to the device through routing.
- After route calculation, the outbound interface of the next hop is the interface that receives the packets.
- The device discovers that a better next hop IP address of the packet is on the same network segment as the source IP address of the packet.
- After checking the source address of the packet, the device discovers a neighboring device in the neighbor entries using this address as the global unicast address or the link-local unicast address.