| Communication protocol | |
| Purpose | Network tunneling |
|---|---|
| Developer | Cisco Systems |
| Introduction | 1994 |
| RFCs | 1701, 1702, 2784 |
Generic routing encapsulation (GRE) is a tunneling protocol developed by Cisco Systems that can encapsulate a wide variety of network layer protocols inside virtual point-to-point links or point-to-multipoint links over an Internet Protocol network.
| OSI model layer | Protocol example |
|---|---|
| 7. Application | HTTP |
| 4. Transport | TCP |
| 3. Network (GRE-encapsulated) | IPv4 |
| Encapsulation | GRE |
| 3. Network | IPv6 |
| 2. Data link | Ethernet |
| 1. Physical | Ethernet physical layer |
Based on the principles of protocol layering in OSI, protocol encapsulation, not specifically GRE, breaks the layering order. It may be viewed as a separator between two different protocol stacks, one acting as a carrier for another.
GRE packets that are encapsulated within IP directly, use IP protocol type 47 in the IPv4 header's Protocol field or the IPv6 header's Next Header field.
For performance reasons, GRE can also be encapsulated in UDP packets. Better throughput may be achieved by using Equal-cost multi-path routing.
The extended version of the GRE packet header is represented below:
| Offsets | Octet | 0 | 1 | 2 | 3 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| 0 | 0 | C | K | S | Reserved 0 | Version | Protocol Type | ||||||||||||||||||||||||||
| 4 | 32 | Checksum (optional) | Reserved 1 (optional) | ||||||||||||||||||||||||||||||
| 8 | 64 | Key (optional) | |||||||||||||||||||||||||||||||
| 12 | 96 | Sequence Number (optional) | |||||||||||||||||||||||||||||||
A standard GRE packet header structure is represented in the diagram below.
| Offsets | Octet | 0 | 1 | 2 | 3 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| 0 | 0 | C | Reserved 0 | Version | Protocol Type | ||||||||||||||||||||||||||||
| 4 | 32 | Checksum (optional) | Reserved 1 (optional) | ||||||||||||||||||||||||||||||
The newer structure superseded the original structure:
| Offsets | Octet | 0 | 1 | 2 | 3 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| 0 | 0 | C | R | K | S | s | Recur | Flags | Version | Protocol Type | |||||||||||||||||||||||
| 4 | 32 | Checksum (optional) | Offset (optional) | ||||||||||||||||||||||||||||||
| 8 | 64 | Key (optional) | |||||||||||||||||||||||||||||||
| 12 | 96 | Sequence Number (optional) | |||||||||||||||||||||||||||||||
| 16 | 128 | Routing (optional, variable length) | |||||||||||||||||||||||||||||||
The original GRE RFC defined further fields in the packet header which became obsolete in the current standard:
The Point-to-Point Tunneling Protocol (PPTP) uses a variant GRE packet header structure, represented below. PPTP creates a GRE tunnel through which the PPTP GRE packets are sent.
| Offsets | Octet | 0 | 1 | 2 | 3 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Octet | Bit | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| 0 | 0 | C | R | K | S | s | Recur | A | Flags | Version | Protocol Type | ||||||||||||||||||||||
| 4 | 32 | Key Payload Length | Key Call ID | ||||||||||||||||||||||||||||||
| 8 | 64 | Sequence Number (optional) | |||||||||||||||||||||||||||||||
| 12 | 96 | Acknowledgement Number (optional) | |||||||||||||||||||||||||||||||