Understanding IPv6 第4章——IPv6头部

结构如下:
这里写图片描述
IPv6头部长度固定为40字节,扩展头部长度没有限制。
在具体介绍IPv6头部之前,先复习一下IPv4头部。

IPv4头部结构
这里写图片描述

这里写图片描述

IPv6头部结构
这里写图片描述

version: 长度为4位,用来标识IP协议的版本。但是这个字段在IP层并不会被用到,因为在链路层会有字段记录IP层使用的协议,并在传递到IP层时选择合适的协议。
traffic class: 长度为8位。表示IPv6流量的优先级或类别。
flow label: 长度为20位,结合源地址和目的地址,可以表示一系列数据包中的一个。路由器可以据此进行不同的处理,比如实时发送。
playload length:长度为16位。包含扩展头部和上层协议的数据。如果长度超出16位表示的范围,这个字段被设置为0,并用扩展头部中的Jumbo Payload option表示。
Next Header:长度为8位。表示下一个扩展头部的类型(如果有),或者上层协议的类型。如果表示上层协议,和IPv4中定义的值一样。
hop limit:表示IPv6能够经过的最大链路数。和IPv4中的LLT类似,区别是不再与时间有关。
source address:源地址
destination address:目的地址,如果有路由选项,则可能是中间目的地的地址。

这里写图片描述
In looking at the value of the Next Header feld to indicate no next header, it would seem to make more sense to set its value to 0, rather than 59. However, the designers of IPv6 wanted to optimize the processing of IPv6 packets at intermediate routers. The only extension header that must be processed at every intermediate router is the Hop-by-Hop Options header. To optimize the test of whether the Hop-by-Hop Options header is present, its Next Header value is set to 0. In router hardware, it is easier to test for a value of 0 than to test for a value of 59.


IPv6头部能够减少路由器的关键指令集,即转发数据包的步骤。
IPv4转发数据包的过程一般如下:
1. 检查校验和
2. 检查版本号,不对则丢弃
3. 检查并设置LLT值,小于1则发送ICMP超时报文。
4. 检查头部选项是否存在并处理
5. 通过路由表来判断转发的接口。如果没有找到对应的条目则发送ICMP主机不可达报文。
6. 检查MTU,进行拆分或者发送 ICMPv4 Destination Unreachable-Fragmentation Needed and DF Set message
7. 重新计算校验和
8. 通过合适接口转发。

IPv6转发数据包的过程一般如下:
1. 检查版本
2. 检查并设置hop limit字段,小于1则发送 ICMPv6 Time Exceeded-Hop Limit Exceeded in Transit消息。
3. Check the Next Header feld for a value of 0. If it is 0, process the Hop-by-Hop Options header.
4. Use the value of the Destination Address feld and the contents of the local routing table to determine a forwarding interface and a next-hop IPv6 address. If a route is not found, send an ICMPv6 Destination Unreachable-No Route To Destination message to the source of the packet and then discard the packet.
5. If the link MTU of the forwarding interface is less than 40 plus the value of the Payload Length feld, send an ICMPv6 Packet Too Big message to the source of the packet and discard the packet.
6. Forward the packet by using the appropriate forwarding interface.

相比于IPv4,IPv6精简的地方在于:
1. 不用计算校验和
2. 不用进行分片
3. 不用处理跟路由器无关的头部


扩展头部

因为IPv4头部包含所有选项,所以每个中间路由器必须检查所有选项是否存在并进行处理。(是这样的吗?)
IPv6唯一要处理的扩展头部是Hop-by-Hop Option。IPv6扩展头部的长度必须为8字节的整数倍速,非定长扩展头部中有长度字段。头部中next header字段和扩展头部(如果有)中的next header字段构成了一个指针链。如果有不能识别的扩展头部类型,则会发送 ICMP Parameter Problem-Unrecognized Next Header Type Encountered报文。

hop-by-hop Options header

这里写图片描述
这个选项用来传递转发参数。
header extension length以8字节为单位,并且从0开始。所以length=(1+length)* 8。这是IPv6设计者所做的优化,因为如果长度从1开始的话就需要先判断值是不是0。
option的结构如图所示:
这里写图片描述
option有以下几种:
1. Pad1 Option
option type的值被设置为0。一个字节的填充选项。没有option length 和 option data。
2.Padn Option
这里写图片描述
option type是1,option length表示字节长度。不太明白这个length是否包含type和length字段本身。
3. Jumbo Payload Option(超大报文选项)
这里写图片描述
 4个字节最大能够表示 4,294,967,295字节。此选项有对齐要求, 需从4n + 2位置开始。
4. router alert Option
这里写图片描述
和多播地址和资源保留协议相关的选项。不懂。

Destination Options header

略略略有需要的时候再看吧…..

IPv6 MTU

IPv6要求链路层提供最小为1280字节的MTU,如果不能提供,那么就必须实现对网络层不可见的分片和重装。
IPv6也可IPv4一样有路径MTU发现协议,利用ICMPv6实现。

Upper-Layer Checksums

IPv4协议中的TCP,UDP,ICMP计算校验和时都会先构造一个伪IP头部。但是发送的过程中并不真正的发送伪头部。接收方在收到这个报文后会构造出同样的伪头部,然后进行同样的计算。这样做的目的是为了使校验和能够覆盖到IP层的某些字段。比如说源地址和目标地址。
在IPv6中,由于头部字段发生了不少的变化,所以伪头部被重新构造,结构如下:
这里写图片描述



参考

understanding IPv6

深入解析IPv6 第3版

猜你喜欢

转载自blog.csdn.net/qq_31567335/article/details/80161270
今日推荐