ILD

Neighbor Discovery for IP version 6 (IPv6)
作者:Yuan Jianpeng 邮箱:yuanjp89@163.com
发布时间:2019-7-29 站点:Inside Linux Development

IPv6是用邻居发现协议来确定邻居的链路层地址,来查找愿意转发包的路由器,维护活跃邻居的可达信息。


Addresses

Neighbor Discovery使用下列地址:


all-nodes multicast address

link-local scope内的到达所有节点的地址,FF02::01


all-routers multicast address

link local scope内到达所有router的地址,FF02::02


solicited-node multicast address


link-local address


unspecified address


Protocol Overview

解决下列问题

Router Discovery

Prefix Discovery

Parameter Discovery

Address Autoconfiguration

Address resolution

Next-hop determination

Neighnor Unreachability Detection

Duplicate Address Detection

Redirect


邻居发现定义了5种不同的ICMP包类型:

Router Solicitation messages

当一个接口激活时,host发送这个消息,要求router立即发送一个advertising消息。


Router Advertisement messages

router周期性的发送该消息,或者在收到solicitation消息时发送该消息。用来包含很多的信息。


Neighbor Solicitation messages

node发送这个消息来请求邻居的链路层地址,或者用来验证邻居是否仍然活跃。也可以用来检测地址是否冲突。


Neighbor Advertisement messages

响应邻居solicatition消息,可以主动发送该消息,来宣告链路层地址的变化。


Redirect message

router来告知host一个目的地的一个更好的下一跳信息。


Router Solicitation message format

主机发送该消息,提醒router尽快响应一个router advertisement。

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |     Type      |     Code      |          Checksum             |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                            Reserved                           |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |   Options ...
     +-+-+-+-+-+-+-+-+-+-+-+-


IPv6 Header Fields

Source Address:分配给发送接口的地址,或者是unspecified address,如果还没有分配地址的话。

Destination Address:all routers multicast address FF02::02


ICMP Fields

Type 133


options

Source link layer address,如果IPv6头中的源地址是unspecified address,则不能包含此选项。


Router Advertisement Message Format

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |     Type      |     Code      |          Checksum             |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     | Cur Hop Limit |M|O|  Reserved |       Router Lifetime         |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                         Reachable Time                        |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                          Retrans Timer                        |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |   Options ...
     +-+-+-+-+-+-+-+-+-+-+-+-


IPv6 Header Fields

source address:发送此接口的link-local地址

destination address:all-nodes多播地址,如果是响应solicitation,则是那个node的地址。


ICMP Fields

Type:134

M:Managed address configuration标志,1表示地址信息可以通过DHCPv6获取。

O:Other configuration位,表示可以通过DHCPv6获取其它信息。当M为1时,被忽略。

Router Lifetime:0表示缺省路由的秒数,最大限制为9000s,0表示不是缺省路由。

Reachable Time:32位无符号整数,单位毫秒,由NeighborUnreachability Detection algorithm使用。

Retrans Timer:32位无符号整数,单位毫秒,由Address resolution和NeighborUnreachability Detection algorithm使用。


可能的选项

Source link-layer address:发送接口的的链路层地址。

MTU:

Prefix Information:一个router应当包含所有的on-link prefixs,除了link-local prefix


Neighbor Solicitation Message Format

Nodes (host and router)发送这个消息,来获取一个target node的链路层地址。同时提供自己的链路层地址。

当Node尝试解析地址时,它使用多播。当验证neighbor是否可达时,可使用单播。

      0                   1                   2                   3
      0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |     Type      |     Code      |          Checksum             |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                           Reserved                            |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |                                                               |
     +                                                               +
     |                                                               |
     +                       Target Address                          +
     |                                                               |
     +                                                               +
     |                                                               |
     +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
     |   Options ...
     +-+-+-+-+-+-+-+-+-+-+-+-

IPv6 Fields

Source Address:或者是发送接口的地址,如果是重复地址探测,则填unspecified address。

Destination Address:或者是target address的solicited-node multicast address,或者是target address。


ICMP Fields

Type 135

Target Address,要solicitation的IPv6地址,不能是多播地址。


可能的选项

Source link-layer address

发送者的链路层地址,如果source IP address是unspecified address时,不能包括此选项。如果是multicast solicitations则必须包含,单播则应当包含。


Neighbor Advertisement Message Format

响应neighbor solicitation或者主动推送,告诉邻居新信息。

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |     Type      |     Code      |          Checksum             |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |R|S|O|                     Reserved                            |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      +                                                               +
      |                                                               |
      +                       Target Address                          +
      |                                                               |
      +                                                               +
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |   Options ...
      +-+-+-+-+-+-+-+-+-+-+-+-


IP Fields

Source Address,发送此包的接口的地址。

Destination Address,请求者的单播地址,或者是all-nodes multicast address


ICMP Fields

Type:136

R:Router flag

S:Solicited flag,响应一个solicitation请求而发送的此包。

O:Override flag。

Target Address:


可选的选项

Target link-layer address


Option Formats

        0                   1                   2                   3
        0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       |     Type      |    Length     |              ...              |
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       ~                              ...                              ~
       +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+


Type

                           Option Name                             Type

                        Source Link-Layer Address                    1
                        Target Link-Layer Address                    2
                        Prefix Information                           3
                        Redirected Header                            4
                        MTU                                          5


这里特别关注一下Prefix Information

       0                   1                   2                   3
       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |     Type      |    Length     | Prefix Length |L|A| Reserved1 |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                         Valid Lifetime                        |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                       Preferred Lifetime                      |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                           Reserved2                           |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
      |                                                               |
      +                                                               +
      |                                                               |
      +                            Prefix                             +
      |                                                               |
      +                                                               +
      |                                                               |
      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

L:on-link flag

A:autonomous address-configuration flag,意味着这个prefix可以用做无状态地址配置。

Prefix length:前缀的长度,0到128。

Prefix:IP地址或者IP地址前缀。


Conceptual Model of a Host

设计了几种邻居的状态

      INCOMPLETE  Address resolution is in progress and the link-layer
                  address of the neighbor has not yet been determined.

      REACHABLE   Roughly speaking, the neighbor is known to have been
                  reachable recently (within tens of seconds ago).

      STALE       The neighbor is no longer known to be reachable but
                  until traffic is sent to the neighbor, no attempt
                  should be made to verify its reachability.

      DELAY       The neighbor is no longer known to be reachable, and
                  traffic has recently been sent to the neighbor.
                  Rather than probe the neighbor immediately, however,
                  delay sending probes for a short while in order to
                  give upper-layer protocols a chance to provide
                  reachability confirmation.

      PROBE       The neighbor is no longer known to be reachable, and
                  unicast Neighbor Solicitation probes are being sent to
                  verify reachability.


参考

https://tools.ietf.org/html/rfc4861


Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.