GRE协议报文格式
系统收到需要进行封装和路由的某网络层协议(如IPX)数据时,将首先对其加上GRE(Generic Routing Encapsulation)报文头,使之成为GRE报文,再将其封装在另一协议(如IP)中。这样,此报文的转发就可以完全由IP协议负责。RFC 2784和RFC 1701都定义了GRE首部格式,两者格式不同。
一、GRE首部格式(RFC 2784)
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|C| Reserved0 | Ver | Protocol Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum (optional) | Reserved1 (Optional) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
二、GRE首部字段解释(RFC 2784)
字段 | 长度 | 描述 |
---|---|---|
C | 1比特 | 校验和验证标识位。如果该位置1,表示GRE头插入了校验和(Checksum)字段;该位为0表示GRE头不包含校验和字段。 |
Reserved0 | 12比特 | 如果比特1–5不是全0,则该报文会被丢弃。比特6-12为预留字段,设置为0,接收者忽略此字段。 |
Ver | 3比特 | 版本字段,必须置为0。 |
Protocol Type | 16比特 | 乘客协议的协议类型,取值及含义与RFC1700中的“ETHER TYPES”相同。 |
Checksum | 16比特 | 对GRE头及其负载的校验和字段。 |
Reserved1 | 16比特 | 预留字段,设置为0。此字段只在校验和验证标识位(C位)置位时出现。 |
三、GRE首部格式(RFC 1701)
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
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|C|R|K|S|s|Recur| Flags | Ver | Protocol Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum (optional) | Offset (optional) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Key (optional) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Sequence Number (optional) |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Routing (optional)
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
四、GRE首部字段解释(RFC 1701)
字段 | 长度 | 描述 |
---|---|---|
C | 1比特 | 校验和验证标识位。如果该位置1,表示GRE头插入了校验和(Checksum)字段;该位为0表示GRE头不包含校验和字段。 |
R | 1比特 | 路由标识位。如果该位置1,表示GRE头插入了偏移字段和源路由字段。如果校验和验证位或者路由位其中一位置1,或两位都置1,则表示GRE头插入了校验和(Checksum)字段和偏移字段。 |
K | 1比特 | 关键字标识位。如果该位置1,表示GRE头插入了关键字(Key)字段;该位为0表示GRE头不包含关键字字段。 |
S | 1比特 | 序列号标识位。如果该位置1,表示GRE头插入了报文序列号字段。否则,表示GRE头没有序列号字段。 |
s | 1比特 | 严格源路由标识位。RFC1071推荐此标识位仅在路由信息域包含了严格源路由信息的情况下置1。 |
Recur | 3比特 | 用来表示GRE报文被封装的层数。完成一次GRE封装后将该字段加1。如果封装层数大于3,则丢弃该报文。该字段的作用是防止报文被无限次的封装。 |
Flags | 5比特 | 预留字段。当前必须设为0。 |
Ver | 3比特 | 版本字段,必须置为0。Version为1是使用在RFC2637的PPTP中。 |
Protocol Type | 16比特 | 乘客协议的协议类型,取值及含义与RFC1700中的“ETHER TYPES”相同。 |
Checksum | 16比特 | 对GRE头及其负载的校验和字段。 |
Offset | 16比特 | 偏移字段,表示活跃的路由信息域中的起始字节到活跃的源路由实体SRE(Source Route Entry)的字节偏移量。该字段只有在路由标识位或者校验和验证标识位置1时携带,并在路由标识位置1时才有效。 |
Key | 32比特 | 关键字字段,隧道接收端用于对收到的报文进行验证。 |
Sequence Number | 32比特 | 报文序列号字段,是由封装节点插入的一个32位的无符号整数。 |
Routing | 32比特 | 路由信息字段,是可选字段。只在路由标识位置1时出现。路由信息字段包含了一系列的源路由实体SRE(Source Route Entry)。每个SRE的格式如下:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Address Family | SRE Offset | SRE Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Routing Information ... +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ 路由信息字段以一个“Null”SRE为结尾,该SRE是一个长度为0,只包含一个类型为0x0000的Address Family子字段。 |
五、GRE报文(RFC 2784)示例
Frame 1: 138 bytes on wire (1104 bits), 138 bytes captured (1104 bits)
Arrival Time: Jun 21, 2008 20:06:06.434897000
Epoch Time: 1214049966.434897000 seconds
[Time delta from previous captured frame: 0.000000000 seconds]
[Time delta from previous displayed frame: 0.000000000 seconds]
[Time since reference or first frame: 0.000000000 seconds]
Frame Number: 1
Frame Length: 138 bytes (1104 bits)
Capture Length: 138 bytes (1104 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: eth:ip:gre:ip:icmp:data]
[Coloring Rule Name: ICMP]
[Coloring Rule String: icmp || icmpv6]
Ethernet II, Src: c2:00:57:75:00:00 (c2:00:57:75:00:00), Dst: c2:01:57:75:00:00 (c2:01:57:75:00:00)
Destination: c2:01:57:75:00:00 (c2:01:57:75:00:00)
Address: c2:01:57:75:00:00 (c2:01:57:75:00:00)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
Source: c2:00:57:75:00:00 (c2:00:57:75:00:00)
Address: c2:00:57:75:00:00 (c2:00:57:75:00:00)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..1. .... .... .... .... = LG bit: Locally administered address (this is NOT the factory default)
Type: IP (0x0800)
Internet Protocol Version 4, Src: 1.1.1.1 (1.1.1.1), Dst: 2.2.2.2 (2.2.2.2)
Version: 4
Header length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
0000 00.. = Differentiated Services Codepoint: Default (0x00)
.... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
Total Length: 124
Identification: 0x000a (10)
Flags: 0x00
0... .... = Reserved bit: Not set
.0.. .... = Don't fragment: Not set
..0. .... = More fragments: Not set
Fragment offset: 0
Time to live: 255
Protocol: GRE (47)
Header checksum: 0xa746 [correct]
[Good: True]
[Bad: False]
Source: 1.1.1.1 (1.1.1.1)
Destination: 2.2.2.2 (2.2.2.2)
Generic Routing Encapsulation (IP)
Flags and Version: 0x0000
0... .... .... .... = Checksum Bit: No
.0.. .... .... .... = Routing Bit: No
..0. .... .... .... = Key Bit: No
...0 .... .... .... = Sequence Number Bit: No
.... 0... .... .... = Strict Source Route Bit: No
.... .000 .... .... = Recursion control: 0
.... .... 0000 0... = Flags (Reserved): 0
.... .... .... .000 = Version: GRE (0)
Protocol Type: IP (0x0800)
Internet Protocol Version 4, Src: 10.0.0.1 (10.0.0.1), Dst: 10.0.0.2 (10.0.0.2)
Version: 4
Header length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
0000 00.. = Differentiated Services Codepoint: Default (0x00)
.... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
Total Length: 100
Identification: 0x000a (10)
Flags: 0x00
0... .... = Reserved bit: Not set
.0.. .... = Don't fragment: Not set
..0. .... = More fragments: Not set
Fragment offset: 0
Time to live: 255
Protocol: ICMP (1)
Header checksum: 0xb589 [correct]
[Good: True]
[Bad: False]
Source: 10.0.0.1 (10.0.0.1)
Destination: 10.0.0.2 (10.0.0.2)
Internet Control Message Protocol
Type: 8 (Echo (ping) request)
Code: 0
Checksum: 0xbfd4 [correct]
Identifier (BE): 2 (0x0002)
Identifier (LE): 512 (0x0200)
Sequence number (BE): 0 (0x0000)
Sequence number (LE): 0 (0x0000)
[Response In: 2]
Data (72 bytes)
六、GRE报文(RFC 1701)示例
Frame 4183: 74 bytes on wire (592 bits), 74 bytes captured (592 bits)
Arrival Time: Feb 25, 2014 02:33:42.077657000
Epoch Time: 1393266822.077657000 seconds
[Time delta from previous captured frame: 0.000000000 seconds]
[Time delta from previous displayed frame: 0.000000000 seconds]
[Time since reference or first frame: 1144.114491000 seconds]
Frame Number: 4183
Frame Length: 74 bytes (592 bits)
Capture Length: 74 bytes (592 bits)
[Frame is marked: False]
[Frame is ignored: False]
[Protocols in frame: eth:ip:gre:ppp:ipcp]
Ethernet II, Src: 00:e1:fc:45:2b:f3 (00:e1:fc:45:2b:f3), Dst: HuaweiTe_06:5f:38 (00:e0:fc:06:5f:38)
Destination: HuaweiTe_06:5f:38 (00:e0:fc:06:5f:38)
Address: HuaweiTe_06:5f:38 (00:e0:fc:06:5f:38)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Source: 00:e1:fc:45:2b:f3 (00:e1:fc:45:2b:f3)
Address: 00:e1:fc:45:2b:f3 (00:e1:fc:45:2b:f3)
.... ...0 .... .... .... .... = IG bit: Individual address (unicast)
.... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
Type: IP (0x0800)
Internet Protocol Version 4, Src: 172.26.244.130 (172.26.244.130), Dst: 172.26.241.164 (172.26.241.164)
Version: 4
Header length: 20 bytes
Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
0000 00.. = Differentiated Services Codepoint: Default (0x00)
.... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
Total Length: 60
Identification: 0x33e0 (13280)
Flags: 0x00
0... .... = Reserved bit: Not set
.0.. .... = Don't fragment: Not set
..0. .... = More fragments: Not set
Fragment offset: 0
Time to live: 61
Protocol: GRE (47)
Header checksum: 0x0b57 [correct]
[Good: True]
[Bad: False]
Source: 10.26.244.130 (10.26.244.130)
Destination: 10.26.241.164 (10.26.241.164)
Generic Routing Encapsulation (CDMA2000 A10 Unstructured byte stream)
Flags and Version: 0x3000
0... .... .... .... = Checksum Bit: No
.0.. .... .... .... = Routing Bit: No
..1. .... .... .... = Key Bit: Yes
...1 .... .... .... = Sequence Number Bit: Yes
.... 0... .... .... = Strict Source Route Bit: No
.... .000 .... .... = Recursion control: 0
.... .... 0... .... = Acknowledgment: No
.... .... .000 0... = Flags (Reserved): 0
.... .... .... .000 = Version: GRE (0)
Protocol Type: CDMA2000 A10 Unstructured byte stream (0x8881)
Key: 0x10330c63
Sequence Number: 7
PPP In HDLC-Like Framing
PPP Data
PPP Fragment
Point-to-Point Protocol
Protocol: IP Control Protocol (0x8021)
PPP IP Control Protocol
Code: Configuration Request (0x01)
Identifier: 0x07
Length: 22
Options: (18 bytes)
IP address: 10.45.76.66
Primary DNS server IP address: 10.30.19.50
Secondary DNS server IP address: 10.134.1.5
七、协议栈结构
净荷(Payload Packet):系统收到的需要封装和路由的数据报称为净荷。
乘客协议(Passenger Protocol):封装前的报文协议称为乘客协议。
封装协议(Encapsulation Protocol):上述的GRE协议称为封装协议,也称为运载协议(Carrier Protocol)。
传输协议(Transport Protocol或者Delivery Protocol):负责对封装后的报文进行转发的协议称为传输协议。
评论列表(1条)