4.4 Routing Header (路由报头)
Routing header 由 IPv6 源使用, 以列出在到达分组目的地的途中要 "visited (访问)" 的一个或多个中间节点.此功能与 IPv4 的 Loose Source and Record Route option (松散源和记录路由选项) 非常相似.Routing header 由紧邻前一报头中 Next Header 值 43 标识, 并具有以下格式:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | Routing Type | Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
. .
. type-specific data .
. .
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Next Header (下一报头) - 8 位选择器.标识紧跟 Routing header 后面的报头类型.使用与 IPv4 Protocol 字段相同的值 [RFC-1700 et seq.].
Hdr Ext Len (报头扩展长度) - 8 位无符号整数.Routing header 的长度 (以 8 个八位字节为单位), 不包括前 8 个八位字节.
Routing Type (路由类型) - 8 位特定 Routing header 变体的标识符.
Segments Left (剩余段数) - 8 位无符号整数.剩余的路由段数, 即在到达最终目的地之前仍需访问的明确列出的中间节点数.
type-specific data (类型特定数据) - 可变长度字段, 其格式由 Routing Type 决定, 其长度使得完整的 Routing header 的长度是 8 个八位字节的整数倍.
如果在处理接收到的分组时, 节点遇到具有无法识别的 Routing Type 值的 Routing header, 则节点所需的行为取决于 Segments Left 字段的值, 如下所示:
如果 Segments Left 为零, 节点必须忽略 Routing header 并继续处理分组中的下一个报头, 其类型由 Routing header 中的 Next Header 字段标识.
如果 Segments Left 非零, 节点必须丢弃该分组并向分组的 Source Address 发送 ICMP Parameter Problem, Code 0 消息, 指向无法识别的 Routing Type.
如果在处理接收到的分组的 Routing header 后, 中间节点确定该分组将被转发到其链路 MTU 小于分组大小的链路上, 则该节点必须丢弃该分组并向分组的 Source Address 发送 ICMP Packet Too Big 消息.
Type 0 Routing header (Type 0 路由报头)
Type 0 Routing header 具有以下格式:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Next Header | Hdr Ext Len | Routing Type=0| Segments Left |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Reserved |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Address[1] +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Address[2] +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
. . .
. . .
. . .
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| |
+ +
| |
+ Address[n] +
| |
+ +
| |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Next Header (下一报头) - 8 位选择器.标识紧跟 Routing header 后面的报头类型.使用与 IPv4 Protocol 字段相同的值 [RFC-1700 et seq.].
Hdr Ext Len (报头扩展长度) - 8 位无符号整数.Routing header 的长度 (以 8 个八位字节为单位), 不包括前 8 个八位字节.对于 Type 0 Routing header, Hdr Ext Len 等于报头中地址数量的两倍.
Routing Type (路由类型) - 0.
Segments Left (剩余段数) - 8 位无符号整数.剩余的路由段数, 即在到达最终目的地之前仍需访问的明确列出的中间节点数.
Reserved (保留) - 32 位保留字段.发送时初始化为零; 接收时忽略.
Address[1..n] (地址[1..n]) - 128 位地址的向量, 编号为 1 到 n.
组播地址不得出现在 Type 0 的 Routing header 中, 也不得出现在携带 Type 0 Routing header 的分组的 IPv6 Destination Address 字段中.
Routing header 在到达 IPv6 报头的 Destination Address 字段中标识的节点之前不会被检查或处理.在该节点中, 对紧邻前一报头的 Next Header 字段进行分派会调用 Routing header 模块, 在 Routing Type 0 的情况下, 该模块执行以下算法:
if Segments Left = 0 {
proceed to process the next header in the packet, whose type is
identified by the Next Header field in the Routing header
}
else if Hdr Ext Len is odd {
send an ICMP Parameter Problem, Code 0, message to the Source
Address, pointing to the Hdr Ext Len field, and discard the
packet
}
else {
compute n, the number of addresses in the Routing header, by
dividing Hdr Ext Len by 2
if Segments Left is greater than n {
send an ICMP Parameter Problem, Code 0, message to the Source
Address, pointing to the Segments Left field, and discard the
packet
}
else {
decrement Segments Left by 1;
compute i, the index of the next address to be visited in
the address vector, by subtracting Segments Left from n
if Address [i] or the IPv6 Destination Address is multicast {
discard the packet
}
else {
swap the IPv6 Destination Address and Address[i]
if the IPv6 Hop Limit is less than or equal to 1 {
send an ICMP Time Exceeded -- Hop Limit Exceeded in
Transit message to the Source Address and discard the
packet
}
else {
decrement the Hop Limit by 1
resubmit the packet to the IPv6 module for transmission
to the new destination
}
}
}
}
路由示例
作为上述算法效果的一个示例, 考虑源节点 S 向目的节点 D 发送分组的情况, 使用 Routing header 使分组通过中间节点 I1、I2 和 I3 路由.在传递路径的每个段上, 相关 IPv6 报头和 Routing header 字段的值将如下所示:
当分组从 S 传输到 I1 时:
Source Address = S Hdr Ext Len = 6
Destination Address = I1 Segments Left = 3
Address[1] = I2
Address[2] = I3
Address[3] = D
当分组从 I1 传输到 I2 时:
Source Address = S Hdr Ext Len = 6
Destination Address = I2 Segments Left = 2
Address[1] = I1
Address[2] = I3
Address[3] = D
当分组从 I2 传输到 I3 时:
Source Address = S Hdr Ext Len = 6
Destination Address = I3 Segments Left = 1
Address[1] = I1
Address[2] = I2
Address[3] = D
当分组从 I3 传输到 D 时:
Source Address = S Hdr Ext Len = 6
Destination Address = D Segments Left = 0
Address[1] = I1
Address[2] = I2
Address[3] = I3