# ND

IPv6 ND 提供機制來解決鄰近nodes間相互作用的下列問題：

```
Router Discovery - Hosts如何查尋到連接在link上的router？

Prefix Discovery - Hosts如何得知哪些prefix是屬於link上可直接傳送的位址？（Nodes利用prefix是否為on-link來決定直接傳送封包或透過router傳送封包到目的地）

Parameter Discovery - How to get link related parameter by each node？ ex： link MTU，Hop Limit值

Address Autoconfiguration - 提供機制來允許hosts對每個interface自動配置參數。ex：IPv6位址，link MTU等

Address resolution - 如何從鄰近nodes的IPv6位址解析到其link層地址

Next-hop determination - 如何將欲傳送的封包的目的地對應到next-hop位址？ 對於非鄰近（off-link）目的位址，Next-hop位址是router的位址。對於鄰近的（on-link）目的位址，next-hop位址就是目的位址本身

Neighbor Unreachability Detection - 如何偵測鄰近的nodes的可達性？對於不可達的nodes，可嘗試用位址解析機制來確認是否還可達。此外，如果link上有2個以上的routers，還可以透過更換default router來解決鄰近router不可達問題。

Duplicate Address Detection(DAD) - node如何確定它欲使用的位址是否已經被鄰近的其它node使用了？

Redirect（重新導向） - 當link上有2個以上routers時，Router如何告知host使用更佳的next-hop （即別的router）將封包送達特定的目的位址？
```

ND利用 ICMPv6 packet structure並且定義新的ICMPv6 type **133\~137** 分別來解決鄰近nodes間相互作用的問題。ND messages include

* ICMPv6 header
* 零到多個 ND options

  ![](/files/-MJaICVi6K5JHDtVlcQh)

ND 包括 5 種messages：

```
Router Solicitation（路由器請求，RS）- Message from host to router, 當host的interface被啟動時，host可以發送RS message要求router立即發佈RA message，不用等待router下次自發性發佈RA message的時間。

Router Advertisement（路由器公告，RA）- router將週期性發佈RA message, 當host發出RS message時， router也會立即發送RA message。RA message包含on-link或off-link的prefix，hop limit，和link MTU等。經host發出RS message而回應的RA亦稱為Solicited RA message（經由請求後才發送的）。Router週期性發佈的RA亦稱為Unsolicited RA message（非經由請求後才發送的）

Neighbor Solicitation（鄰居請求，NS）- 用來解析鄰近nodes的link層地址，也可檢測鄰近的nodes是否還reachable，還可用來做Duplicate Address Detection（DAD）檢測

Neighbor Advertisement（鄰居公告，NA）- NA主要包含發送者的link層地址，用來回應NS message。此外，當link層地址發生變化時，node會馬上發佈NA來通知所有的nodes。 回應NS的NA 亦稱為Solicited NA message，非因回應NS而發送的NA亦稱為Unsolicited NA message

Redirect（重新導向）- Router用來告知host使用路徑更佳的next-hop將封包送達特定的目的位址。
```

在具有multicast能力的link上 (RA 發送的時機點)

* 每個router週期性地send RA來宣告他的可用性
* 當host發出RS message時，router也會立即發送RA message

Hosts藉由收到的RA， 建立一個table稱為Default Router List。當host發現目前的default router unreachable 或不可用（router可能宣佈不再當router或者router的lifetime已經到期） 時， 可利用default router list找到其它可用的router後，更換default router

RA 包含零到多個prefix，每個prefix包括個別的on-link及autonomous flags，用來指定此prefix的用途。Hosts利用on-link flag值為1的prefix，建立一個列表稱為prefix list。發送封包時用prefix list決定直接送到目的地或者透過router轉送。Autonomous flag用來告知host是否使用此prefix自建Global或Unique Local Address。

Node透過發送NS 要求目標透過NA message來回應它的link層地址。NS的IP 目標位址為目標的Solicited-node multicast address，回應的NA message的IP 目標位址為NS message的來源位址。

Summary

DAD

* Implement by NA, NS

**Reference:**

```
RFC 4191  Router Preferences and More-Specific Routes

RFC 4861  Neighbor Discovery in IPv6
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://fashaun.gitbook.io/dev-protocol/ipv6/nd.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
