blob: bbda2df3f688f7ced1e6641b46c9e68ed8f1eec2 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001#ifndef included_vnet_gre_packet_h
2#define included_vnet_gre_packet_h
3
4/*
5 * GRE packet format
6 *
7 * Copyright (c) 2012 Cisco and/or its affiliates.
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at:
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
21#define foreach_gre_protocol \
22_ (0x0800, ip4) \
23_ (0x86DD, ip6) \
David Hothama8cd3092016-09-19 09:55:07 -070024_ (0x6558, teb) \
Ed Warnickecb9cada2015-12-08 15:45:58 -070025_ (0x0806, arp) \
26_ (0x8847, mpls_unicast) \
John Loa43ccae2018-02-13 17:15:23 -050027_ (0x88BE, erspan) \
Ed Warnickecb9cada2015-12-08 15:45:58 -070028_ (0x894F, nsh)
29
Swarup Nayak9ff647a2017-11-27 10:27:43 +053030typedef enum
31{
Ed Warnickecb9cada2015-12-08 15:45:58 -070032#define _(n,f) GRE_PROTOCOL_##f = n,
33 foreach_gre_protocol
34#undef _
35} gre_protocol_t;
36
Swarup Nayak9ff647a2017-11-27 10:27:43 +053037typedef struct
38{
Ed Warnickecb9cada2015-12-08 15:45:58 -070039 /* flags and version */
40 u16 flags_and_version;
41 /* unimplemented at the moment */
42#define GRE_FLAGS_CHECKSUM (1 << 15)
43
44 /* deprecated, according to rfc2784 */
45#define GRE_FLAGS_ROUTING (1 << 14)
46#define GRE_FLAGS_KEY (1 << 13)
47#define GRE_FLAGS_SEQUENCE (1 << 12)
48#define GRE_FLAGS_STRICT_SOURCE_ROUTE (1 << 11)
49
50 /* version 1 is PPTP which we don't support */
51#define GRE_SUPPORTED_VERSION 0
52#define GRE_VERSION_MASK 0x7
53
54 /* 0x800 for ip4, etc. */
55 u16 protocol;
56} gre_header_t;
57
John Loa43ccae2018-02-13 17:15:23 -050058/* From draft-foschiano-erspan-03.txt
59
60 Different frame variants known as "ERSPAN Types" can be
61 distinguished based on the GRE "Protocol Type" field value: Type I
62 and II's value is 0x88BE while Type III's is 0x22EB [ETYPES].
63
64 GRE header for ERSPAN Type II encapsulation (8 octets [34:41])
65 0 1 2 3
66 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
67 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
68 |0|0|0|1|0|00000|000000000|00000| Protocol Type for ERSPAN |
69 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
70 | Sequence Number (increments per packet per session) |
71 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
72
73 Note that in the above GRE header [RFC1701] out of the C, R, K, S,
74 s, Recur, Flags, Version fields only S (bit 03) may be set to 1. The
75 other fields are always set to zero.
76
77 ERSPAN Type II's frame format also adds a special 8-octet ERSPAN
78 "feature" header on top of the MAC/IPv4/GRE headers to enclose the
79 raw mirrored frames.
80
81 The ERSPAN Type II feature header is described below:
82
83 ERSPAN Type II header (8 octets [42:49])
84 0 1 2 3
85 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
86 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
87 | Ver | VLAN | COS | En|T| Session ID |
88 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
89 | Reserved | Index |
90 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
91
92 The various fields of the above header are described in this table:
93
94 Field Position Length Definition
95 [octet:bit] (bits)
96
97 Ver [42:0] 4 ERSPAN Encapsulation version.
98 This indicates the version of
99 the ERSPAN encapsulation
100 specification. Set to 0x1 for
101 Type II.
102
103 VLAN [42:4] 12 Original VLAN of the frame,
104 mirrored from the source.
105 If the En field is set to 11,
106 the value of VLAN is undefined.
107
108 COS [44:0] 3 Original class of service of the
109 frame, mirrored from the source.
110
111 En [44:3] 2 The trunk encapsulation type
112 associated with the ERSPAN source
113 port for ingress ERSPAN traffic.
114
115 The possible values are:
116 00-originally without VLAN tag
117 01-originally ISL encapsulated
118 10-originally 802.1Q encapsulated
119 11-VLAN tag preserved in frame.
120
121 T [44:5] 1 This bit indicates that the frame
122 copy encapsulated in the ERSPAN
123 packet has been truncated. This
124 occurs if the ERSPAN encapsulated
125 frame exceeds the configured MTU.
126
127 Session ID [44:6] 10 Identification associated with
128 (ERSPAN ID) each ERSPAN session. Must be
129 unique between the source and the
130 receiver(s). (See section below.)
131
132 Reserved [46:0] 12 All bits are set to zero
133
134 Index [47:4] 20 A 20 bit index/port number
135 associated with the ERSPAN
136 traffic's port and
137 direction (ingress/egress). N.B.:
138 This field is platform dependent.
139*/
140
John Loa43ccae2018-02-13 17:15:23 -0500141typedef CLIB_PACKED (struct {
142 u32 seq_num;
143 union
144 {
145 struct
146 {
147 u16 ver_vlan;
148 u16 cos_en_t_session;
149 u32 res_index;
150 } t2;
151 u64 t2_u64;
152 };
153}) erspan_t2_t;
154
155typedef CLIB_PACKED (struct {
156 gre_header_t gre;
157 erspan_t2_t erspan;
158}) erspan_t2_header_t;
159
John Loa43ccae2018-02-13 17:15:23 -0500160
John Lo2bf8b812018-02-27 16:35:03 -0500161/* u64 template for ERSPAN type 2 header with both EN bits set */
162#define ERSPAN_HDR2 0x1000180000000000ul
163
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164#endif /* included_vnet_gre_packet_h */
Swarup Nayak9ff647a2017-11-27 10:27:43 +0530165
166/*
167 * fd.io coding-style-patch-verification: ON
168 *
169 * Local Variables:
170 * eval: (c-set-style "gnu")
171 * End:
172 */