Understanding IPv6 第6章——邻居发现

参考

understanding IPv6

深入解析IPv6 第3版

这章是真复杂呀,overview里介绍的内容真多。而且有整整50页。只能说加油!

Neighbor Discover用来决定邻居间的关系。用来取代IPv4中的ARP,ICMP路由发现,ICMP重定向。

Neighbor Discover也是属于ICMPv6的内容。复习一下ICMPv6的格式如下:
Understanding IPv6 第6章——邻居发现_第1张图片
ND协议有五种消息类型:
Router Solicitation (ICMPv6 type 133)
Router Advertisement (ICMPv6 type 134)
Neighbor Solicitation (ICMPv6 type 135)
Neighbor Advertisement (ICMPv6 type 136)
Redirect (ICMPv6 type 137)

message body用来放置各种选项。

ND options

选项采用经典的TLV格式:
Understanding IPv6 第6章——邻居发现_第2张图片

1. 源和目标链路层地址

type分别是1(源)和2(target)。以8字节为界,length表示整个可选项的以8字节为单位的长度,从1开始。但是并没说如果不是刚好8字节怎么补齐。 included in the Neighbor Solicitation, Router Solicitation,and Router Advertisement messages

2. 前缀信息选项

在Router Advertisement messages中用来通告地址前缀信息
其中三个标志位没看懂。

3. 头部重定向选项

将导致重定向的报文的部分或全部封装到选项中。

4. MTU可选项

The MTU option is sent in Router Advertisement messages to indicate the IPv6 MTU of the link。在桥接和二层交换环境中,PMTU无法探测出路径MTU。路由器会通告整个链路的MTU,主机收到这个值之后会覆盖掉接口上报的MTU值。但是不明白路由器是如何得到整个链路的MTU的。

5. 路由信息选项

没有此选项时,一个主机只能设置一个默认路由器。默认路由器通过重定向报文告诉主机更优的选择。路由信息选项通过通告网络前缀,让主机添加更加精确的路由条目,从而优化报文的传输。路由信息选项的报文中只发送前缀,路由器的地址应该是从IP层获取。

Neighbor Discovery Messages

1. Router Solicitation message

sent by IPv6 hosts to discover the presence of IPv6 routers on the link. A host sends a multicast Router Solicitation message to prompt IPv6 routers to respond immediately rather than waiting for an unsolicited Router Advertisement message.
For example, assuming that the local link is Ethernet, in the Ethernet header of the Router Solicitation message you will fnd these settings:
The Source Address feld is set to the MAC address of the sending network adapter.
The Destination Address feld is set to 33-33-00-00-00-02.
In the IPv6 header of the Router Solicitation message, you will fnd the following settings:
The Source Address feld is set to either a link-local IPv6 address assigned to the sending interface or the IPv6 unspecifed address (::).
The Destination Address feld is set to the link-local scope all-routers multicast address (FF02::2).
The Hop Limit feld is set to 255.

2. Router advertisement

用来响应router solicitation或者假周期性的(防止严格同周期带来的碰撞问题)通告路由器的存在。如果响应请求,报文会只发送到对应的单播地址。如果是主动通报,mac目的地址为:33-33-00-00-00-01,IP层目的地址为:FF02::1。

3. Neighbor Solicitation message

IPv6 nodes send the Neighbor Solicitation message to discover the link-layer address of an onlink IPv6 node or to confrm previously determined link-layer address. It typically includes the link-layer address of the sender. Typical Neighbor Solicitation messages are multicast for address resolution and unicast when the reachability of a neighboring node is being verifed.
文中提到在重复地址检测阶段,IPv6头部的源地址字段会被设置为 ::。而且在ICMPv6的源地址选项中也可以被设置为这个值。那么邻居节点怎么回复请求呢?我认为应该是直接通过链路层发送吧,毕竟二层互通。

4. Neighbor advertisement

An IPv6 node sends the Neighbor Advertisement message in response to a Neighbor Solicitation message. An IPv6 node also sends unsolicited Neighbor Advertisements to inform neighboring nodes of changes in link-layer addresses or the node’s role. The Neighbor Advertisement contains information required by nodes to determine the type of Neighbor Advertisement message, the sender’s role on the network, and typically the link-layer address of the sender.

5. redirect

The Redirect message is sent by an IPv6 router to inform an originating host of a better frst-hop address for a specifc destination. Redirect messages are sent only by routers for unicast traffc, are unicast only to originating hosts, and are processed only by hosts.


neighbor discovery process

To facilitate interactions between neighboring nodes, RFC 4861 defnes the following conceptual host data structures as an example of how to store information for ND processes:
Neighbor cache The neighbor cache stores the on-link IP address of each neighbor, its corresponding link-layer address, and an indication of the neighbor’s reachability state. The neighbor cache is equivalent to the ARP cache in IPv4.
Destination cache: The destination cache stores information on next-hop IP addresses for destinations to which traffc has recently been sent. Each entry in the destination cache contains the destination IP address (either local or remote), the previously resolved next-hop IP address, and the path MTU for the destination.
Prefx list: The prefx list contains on-link prefxes. Each entry in the prefx list defnes a range of IP addresses for destinations that are directly reachable (neighbors). This list is populated from prefxes advertised by routers using the Router Advertisement message.
Default router list: IP addresses corresponding to on-link routers that have sent Router Advertisement messages and that are eligible to be default routers are included in the default router list.

1. address resolution

在IPv4中,由IP地址解析得到mac地址的过程是这样的:
https://blog.csdn.net/qq_31567335/article/details/78307653
这种方式有一个缺点:
arp请求以广播的形式发送出去,所有的节点在链路层都必须接收此报文,然后判断请求的不是自己的ip,便丢弃报文。这种方式对性能会产生影响
在IPv6中,专门规定了一种叫做请求节点地址的组播地址,来解决这个问题:
请求节点地址:每个IPv6地址都会对应一个请求节点地址,接口会在链路层监听此地址对应的mac地址,所以地址解析请求只需要发往IP地址对应的请求节点地址即可,而不会打扰到所有的节点。请求节点地址格式如下:
Understanding IPv6 第6章——邻居发现_第3张图片
请求结点地址(组播地址)与mac地址对应的关系如下:
Understanding IPv6 第6章——邻居发现_第4张图片
请求消息以 Neighbor Solicitation的格式发送出去,目的IP地址是对应的组播地址,目的地址链路地址即是由组播地址推算出来的mac地址。消息中会携带 Source Link-Layer Address option。
对应主机收到请求后更新自己的邻居缓存并做出响应。响应的目的ip地址是单播地址,链路地址是请求消息中发送的地址。

2. Neighbor Unreachability Detection

同一个链路上的邻居节点用前面介绍到的 Neighbor Solicitation message和 Neighbor advertisement来确认可达性。当A想确认B的连通性时主动向B发送 Neighbor Solicitation message,收到B的回复确认B连通。但是B不能因此认为A连通,要主动发起请求收到响应才算。这跟TCP的握手很像。

3. Neighbor Cache entry States

邻居节点的状态变化可以通过下图来表示:
Understanding IPv6 第6章——邻居发现_第5张图片
通过邻居节点发现协议,可以改进TCP/IP中的Dead Gateway Detection协议:
通过探测由默认路由器与目的地建立的tcp连接失败数量占比是否达到25%来判断默认路由器是否可用,并进行切换。这个方法有以下两个缺点:
1. 只对tcp有效
2. 可能误判(路径中其他路由器问题)
邻居发现协议能够改善这个协议。
1. tcp中有标记,tcp的正常可以暗示邻居节点正常。其他协议可以通过Neighbor Solicitation and Neighbor Advertisement messages 来判断。
2. 能够准确判断出是路由器的问题,不会误判。

Duplicate address Detection

和IPv4中的gratuitous ARP作用一样,是为了探测某个IP是否已经被使用。arp及gratuitous ARP的工作方式参见此文章:
https://blog.csdn.net/qq_31567335/article/details/78307653

IPv6是利用邻居请求消息来进行探测的,工作过程如下:
1. 将目的地址映射成请求节点地址(组播地址)。映射方法:
https://blog.csdn.net/qq_31567335/article/details/80138851
将此地址作为IPv6头部的目的地址。源地址填unspecifed address (::)
2. 在ICMPv6的目的地址选项中填上待探测的目标地址。
3. 拥有此IP地址的节点在收到请求并处理后,回复Neighbor Advertisement reply message。IPv6头部的源地址填2中的待探测的目标地址。目的地址填 link-local scope all-nodes multicast address (FF02::1)。因为请求的时候并未声明源地址,所以响应报文无法以单播的形式发送。
4. 请求节点如果收到了响应,则说明此ip已经被使用。

Router Discovery

节点用来发现本地链路上的路由器的过程。
1. 向 link-local scope all-routers multicast address (FF02::2)发送Router Solicitation message。源地址如果没有就填 ::,如果已经分配单播地址就填单播地址。
2. 路由器收到请求之后进行回复,目的地址为 link-local scope all-nodes multicast address (FF02::1)或者对应的单播地址。请求点节可以由此设置默认路由。响应报文中还会包含以下信息:
hop limit 的默认值
地址配置相关信息
The timers used in neighbor unreachability detection and the retransmission of Neighbor Solicitations
网络前缀列表
链路MTU
路由信息

redirect function

有两种场景会触发重定向:
1. A router informs an originating host of the IP address of a router available on the local link that is “closer” to the destination. “Closer” is a routing metric function used to reach the destination network segment. This condition can occur when there are multiple routers on a network segment, and the originating host chooses a default router and it is not the better (“closer”) one to use to reach the destination.
2. A router informs an originating host that the destination is a neighbor. (That is, it is on the same link as the originating host.) This condition can occur when the prefx list of a host does not include the prefx of the destination. Because the destination does not match a prefx in the list, the originating host forwards the packet to its default route

没明白路由器是怎么识别第一种场景的。
第二种场景具体如下:发现下一跳和源主机是邻居。这个时候显然源主机应该直接将报文转发给邻居(不管是路由器还是主机)

Host Sending Algorithm

Understanding IPv6 第6章——邻居发现_第6张图片

你可能感兴趣的:(IPv6)